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(_testinternalcapi_compiler_cleandoc__doc__,
12 "compiler_cleandoc($module, /, doc)\n"
13 "--\n"
14 "\n"
15 "C implementation of inspect.cleandoc().");
16
17 #define _TESTINTERNALCAPI_COMPILER_CLEANDOC_METHODDEF \
18 {"compiler_cleandoc", _PyCFunction_CAST(_testinternalcapi_compiler_cleandoc), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_compiler_cleandoc__doc__},
19
20 static PyObject *
21 _testinternalcapi_compiler_cleandoc_impl(PyObject *module, PyObject *doc);
22
23 static PyObject *
_testinternalcapi_compiler_cleandoc(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)24 _testinternalcapi_compiler_cleandoc(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25 {
26 PyObject *return_value = NULL;
27 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
28
29 #define NUM_KEYWORDS 1
30 static struct {
31 PyGC_Head _this_is_not_used;
32 PyObject_VAR_HEAD
33 PyObject *ob_item[NUM_KEYWORDS];
34 } _kwtuple = {
35 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36 .ob_item = { &_Py_ID(doc), },
37 };
38 #undef NUM_KEYWORDS
39 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
40
41 #else // !Py_BUILD_CORE
42 # define KWTUPLE NULL
43 #endif // !Py_BUILD_CORE
44
45 static const char * const _keywords[] = {"doc", NULL};
46 static _PyArg_Parser _parser = {
47 .keywords = _keywords,
48 .fname = "compiler_cleandoc",
49 .kwtuple = KWTUPLE,
50 };
51 #undef KWTUPLE
52 PyObject *argsbuf[1];
53 PyObject *doc;
54
55 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
56 if (!args) {
57 goto exit;
58 }
59 if (!PyUnicode_Check(args[0])) {
60 _PyArg_BadArgument("compiler_cleandoc", "argument 'doc'", "str", args[0]);
61 goto exit;
62 }
63 doc = args[0];
64 return_value = _testinternalcapi_compiler_cleandoc_impl(module, doc);
65
66 exit:
67 return return_value;
68 }
69
70 PyDoc_STRVAR(_testinternalcapi_new_instruction_sequence__doc__,
71 "new_instruction_sequence($module, /)\n"
72 "--\n"
73 "\n"
74 "Return a new, empty InstructionSequence.");
75
76 #define _TESTINTERNALCAPI_NEW_INSTRUCTION_SEQUENCE_METHODDEF \
77 {"new_instruction_sequence", (PyCFunction)_testinternalcapi_new_instruction_sequence, METH_NOARGS, _testinternalcapi_new_instruction_sequence__doc__},
78
79 static PyObject *
80 _testinternalcapi_new_instruction_sequence_impl(PyObject *module);
81
82 static PyObject *
_testinternalcapi_new_instruction_sequence(PyObject * module,PyObject * Py_UNUSED (ignored))83 _testinternalcapi_new_instruction_sequence(PyObject *module, PyObject *Py_UNUSED(ignored))
84 {
85 return _testinternalcapi_new_instruction_sequence_impl(module);
86 }
87
88 PyDoc_STRVAR(_testinternalcapi_compiler_codegen__doc__,
89 "compiler_codegen($module, /, ast, filename, optimize, compile_mode=0)\n"
90 "--\n"
91 "\n"
92 "Apply compiler code generation to an AST.");
93
94 #define _TESTINTERNALCAPI_COMPILER_CODEGEN_METHODDEF \
95 {"compiler_codegen", _PyCFunction_CAST(_testinternalcapi_compiler_codegen), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_compiler_codegen__doc__},
96
97 static PyObject *
98 _testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast,
99 PyObject *filename, int optimize,
100 int compile_mode);
101
102 static PyObject *
_testinternalcapi_compiler_codegen(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)103 _testinternalcapi_compiler_codegen(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
104 {
105 PyObject *return_value = NULL;
106 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
107
108 #define NUM_KEYWORDS 4
109 static struct {
110 PyGC_Head _this_is_not_used;
111 PyObject_VAR_HEAD
112 PyObject *ob_item[NUM_KEYWORDS];
113 } _kwtuple = {
114 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
115 .ob_item = { &_Py_ID(ast), &_Py_ID(filename), &_Py_ID(optimize), &_Py_ID(compile_mode), },
116 };
117 #undef NUM_KEYWORDS
118 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
119
120 #else // !Py_BUILD_CORE
121 # define KWTUPLE NULL
122 #endif // !Py_BUILD_CORE
123
124 static const char * const _keywords[] = {"ast", "filename", "optimize", "compile_mode", NULL};
125 static _PyArg_Parser _parser = {
126 .keywords = _keywords,
127 .fname = "compiler_codegen",
128 .kwtuple = KWTUPLE,
129 };
130 #undef KWTUPLE
131 PyObject *argsbuf[4];
132 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
133 PyObject *ast;
134 PyObject *filename;
135 int optimize;
136 int compile_mode = 0;
137
138 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
139 if (!args) {
140 goto exit;
141 }
142 ast = args[0];
143 filename = args[1];
144 optimize = PyLong_AsInt(args[2]);
145 if (optimize == -1 && PyErr_Occurred()) {
146 goto exit;
147 }
148 if (!noptargs) {
149 goto skip_optional_pos;
150 }
151 compile_mode = PyLong_AsInt(args[3]);
152 if (compile_mode == -1 && PyErr_Occurred()) {
153 goto exit;
154 }
155 skip_optional_pos:
156 return_value = _testinternalcapi_compiler_codegen_impl(module, ast, filename, optimize, compile_mode);
157
158 exit:
159 return return_value;
160 }
161
162 PyDoc_STRVAR(_testinternalcapi_optimize_cfg__doc__,
163 "optimize_cfg($module, /, instructions, consts, nlocals)\n"
164 "--\n"
165 "\n"
166 "Apply compiler optimizations to an instruction list.");
167
168 #define _TESTINTERNALCAPI_OPTIMIZE_CFG_METHODDEF \
169 {"optimize_cfg", _PyCFunction_CAST(_testinternalcapi_optimize_cfg), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_optimize_cfg__doc__},
170
171 static PyObject *
172 _testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions,
173 PyObject *consts, int nlocals);
174
175 static PyObject *
_testinternalcapi_optimize_cfg(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)176 _testinternalcapi_optimize_cfg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
177 {
178 PyObject *return_value = NULL;
179 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
180
181 #define NUM_KEYWORDS 3
182 static struct {
183 PyGC_Head _this_is_not_used;
184 PyObject_VAR_HEAD
185 PyObject *ob_item[NUM_KEYWORDS];
186 } _kwtuple = {
187 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
188 .ob_item = { &_Py_ID(instructions), &_Py_ID(consts), &_Py_ID(nlocals), },
189 };
190 #undef NUM_KEYWORDS
191 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
192
193 #else // !Py_BUILD_CORE
194 # define KWTUPLE NULL
195 #endif // !Py_BUILD_CORE
196
197 static const char * const _keywords[] = {"instructions", "consts", "nlocals", NULL};
198 static _PyArg_Parser _parser = {
199 .keywords = _keywords,
200 .fname = "optimize_cfg",
201 .kwtuple = KWTUPLE,
202 };
203 #undef KWTUPLE
204 PyObject *argsbuf[3];
205 PyObject *instructions;
206 PyObject *consts;
207 int nlocals;
208
209 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
210 if (!args) {
211 goto exit;
212 }
213 instructions = args[0];
214 consts = args[1];
215 nlocals = PyLong_AsInt(args[2]);
216 if (nlocals == -1 && PyErr_Occurred()) {
217 goto exit;
218 }
219 return_value = _testinternalcapi_optimize_cfg_impl(module, instructions, consts, nlocals);
220
221 exit:
222 return return_value;
223 }
224
225 PyDoc_STRVAR(_testinternalcapi_assemble_code_object__doc__,
226 "assemble_code_object($module, /, filename, instructions, metadata)\n"
227 "--\n"
228 "\n"
229 "Create a code object for the given instructions.");
230
231 #define _TESTINTERNALCAPI_ASSEMBLE_CODE_OBJECT_METHODDEF \
232 {"assemble_code_object", _PyCFunction_CAST(_testinternalcapi_assemble_code_object), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_assemble_code_object__doc__},
233
234 static PyObject *
235 _testinternalcapi_assemble_code_object_impl(PyObject *module,
236 PyObject *filename,
237 PyObject *instructions,
238 PyObject *metadata);
239
240 static PyObject *
_testinternalcapi_assemble_code_object(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)241 _testinternalcapi_assemble_code_object(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
242 {
243 PyObject *return_value = NULL;
244 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
245
246 #define NUM_KEYWORDS 3
247 static struct {
248 PyGC_Head _this_is_not_used;
249 PyObject_VAR_HEAD
250 PyObject *ob_item[NUM_KEYWORDS];
251 } _kwtuple = {
252 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
253 .ob_item = { &_Py_ID(filename), &_Py_ID(instructions), &_Py_ID(metadata), },
254 };
255 #undef NUM_KEYWORDS
256 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
257
258 #else // !Py_BUILD_CORE
259 # define KWTUPLE NULL
260 #endif // !Py_BUILD_CORE
261
262 static const char * const _keywords[] = {"filename", "instructions", "metadata", NULL};
263 static _PyArg_Parser _parser = {
264 .keywords = _keywords,
265 .fname = "assemble_code_object",
266 .kwtuple = KWTUPLE,
267 };
268 #undef KWTUPLE
269 PyObject *argsbuf[3];
270 PyObject *filename;
271 PyObject *instructions;
272 PyObject *metadata;
273
274 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
275 if (!args) {
276 goto exit;
277 }
278 filename = args[0];
279 instructions = args[1];
280 metadata = args[2];
281 return_value = _testinternalcapi_assemble_code_object_impl(module, filename, instructions, metadata);
282
283 exit:
284 return return_value;
285 }
286
287 PyDoc_STRVAR(_testinternalcapi_test_long_numbits__doc__,
288 "test_long_numbits($module, /)\n"
289 "--\n"
290 "\n");
291
292 #define _TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF \
293 {"test_long_numbits", (PyCFunction)_testinternalcapi_test_long_numbits, METH_NOARGS, _testinternalcapi_test_long_numbits__doc__},
294
295 static PyObject *
296 _testinternalcapi_test_long_numbits_impl(PyObject *module);
297
298 static PyObject *
_testinternalcapi_test_long_numbits(PyObject * module,PyObject * Py_UNUSED (ignored))299 _testinternalcapi_test_long_numbits(PyObject *module, PyObject *Py_UNUSED(ignored))
300 {
301 return _testinternalcapi_test_long_numbits_impl(module);
302 }
303
304 PyDoc_STRVAR(gh_119213_getargs__doc__,
305 "gh_119213_getargs($module, /, spam=None)\n"
306 "--\n"
307 "\n"
308 "Test _PyArg_Parser.kwtuple");
309
310 #define GH_119213_GETARGS_METHODDEF \
311 {"gh_119213_getargs", _PyCFunction_CAST(gh_119213_getargs), METH_FASTCALL|METH_KEYWORDS, gh_119213_getargs__doc__},
312
313 static PyObject *
314 gh_119213_getargs_impl(PyObject *module, PyObject *spam);
315
316 static PyObject *
gh_119213_getargs(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)317 gh_119213_getargs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
318 {
319 PyObject *return_value = NULL;
320 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
321
322 #define NUM_KEYWORDS 1
323 static struct {
324 PyGC_Head _this_is_not_used;
325 PyObject_VAR_HEAD
326 PyObject *ob_item[NUM_KEYWORDS];
327 } _kwtuple = {
328 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
329 .ob_item = { &_Py_ID(spam), },
330 };
331 #undef NUM_KEYWORDS
332 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
333
334 #else // !Py_BUILD_CORE
335 # define KWTUPLE NULL
336 #endif // !Py_BUILD_CORE
337
338 static const char * const _keywords[] = {"spam", NULL};
339 static _PyArg_Parser _parser = {
340 .keywords = _keywords,
341 .fname = "gh_119213_getargs",
342 .kwtuple = KWTUPLE,
343 };
344 #undef KWTUPLE
345 PyObject *argsbuf[1];
346 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
347 PyObject *spam = Py_None;
348
349 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
350 if (!args) {
351 goto exit;
352 }
353 if (!noptargs) {
354 goto skip_optional_pos;
355 }
356 spam = args[0];
357 skip_optional_pos:
358 return_value = gh_119213_getargs_impl(module, spam);
359
360 exit:
361 return return_value;
362 }
363 /*[clinic end generated code: output=4d0770a1c20fbf40 input=a9049054013a1b77]*/
364