Debian Codegraph @

Modules/clinic/_testinternalcapi.c.h

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