/src/cpython/Objects/clinic/moduleobject.c.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
10 | | |
11 | | PyDoc_STRVAR(module___init____doc__, |
12 | | "module(name, doc=None)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Create a module object.\n" |
16 | | "\n" |
17 | | "The name must be a string; the optional doc argument can have any type."); |
18 | | |
19 | | static int |
20 | | module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc); |
21 | | |
22 | | static int |
23 | | module___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
24 | 912 | { |
25 | 912 | int return_value = -1; |
26 | 912 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
27 | | |
28 | 912 | #define NUM_KEYWORDS 2 |
29 | 912 | static struct { |
30 | 912 | PyGC_Head _this_is_not_used; |
31 | 912 | PyObject_VAR_HEAD |
32 | 912 | Py_hash_t ob_hash; |
33 | 912 | PyObject *ob_item[NUM_KEYWORDS]; |
34 | 912 | } _kwtuple = { |
35 | 912 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
36 | 912 | .ob_hash = -1, |
37 | 912 | .ob_item = { &_Py_ID(name), &_Py_ID(doc), }, |
38 | 912 | }; |
39 | 912 | #undef NUM_KEYWORDS |
40 | 912 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
41 | | |
42 | | #else // !Py_BUILD_CORE |
43 | | # define KWTUPLE NULL |
44 | | #endif // !Py_BUILD_CORE |
45 | | |
46 | 912 | static const char * const _keywords[] = {"name", "doc", NULL}; |
47 | 912 | static _PyArg_Parser _parser = { |
48 | 912 | .keywords = _keywords, |
49 | 912 | .fname = "module", |
50 | 912 | .kwtuple = KWTUPLE, |
51 | 912 | }; |
52 | 912 | #undef KWTUPLE |
53 | 912 | PyObject *argsbuf[2]; |
54 | 912 | PyObject * const *fastargs; |
55 | 912 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
56 | 912 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
57 | 912 | PyObject *name; |
58 | 912 | PyObject *doc = Py_None; |
59 | | |
60 | 912 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
61 | 912 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
62 | 912 | if (!fastargs) { |
63 | 0 | goto exit; |
64 | 0 | } |
65 | 912 | if (!PyUnicode_Check(fastargs[0])) { |
66 | 0 | _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]); |
67 | 0 | goto exit; |
68 | 0 | } |
69 | 912 | name = fastargs[0]; |
70 | 912 | if (!noptargs) { |
71 | 912 | goto skip_optional_pos; |
72 | 912 | } |
73 | 0 | doc = fastargs[1]; |
74 | 912 | skip_optional_pos: |
75 | 912 | return_value = module___init___impl((PyModuleObject *)self, name, doc); |
76 | | |
77 | 912 | exit: |
78 | 912 | return return_value; |
79 | 912 | } |
80 | | /*[clinic end generated code: output=523344ad09ab2ea1 input=a9049054013a1b77]*/ |