/src/cpython/Python/clinic/bltinmodule.c.h
Line | Count | Source |
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(builtin___import____doc__, |
12 | | "__import__($module, /, name, globals=None, locals=None, fromlist=(),\n" |
13 | | " level=0)\n" |
14 | | "--\n" |
15 | | "\n" |
16 | | "Import a module.\n" |
17 | | "\n" |
18 | | "Because this function is meant for use by the Python\n" |
19 | | "interpreter and not for general use, it is better to use\n" |
20 | | "importlib.import_module() to programmatically import a module.\n" |
21 | | "\n" |
22 | | "The globals argument is only used to determine the context;\n" |
23 | | "they are not modified. The locals argument is unused. The fromlist\n" |
24 | | "should be a list of names to emulate ``from name import ...``, or an\n" |
25 | | "empty list to emulate ``import name``.\n" |
26 | | "When importing a module from a package, note that __import__(\'A.B\', ...)\n" |
27 | | "returns package A when fromlist is empty, but its submodule B when\n" |
28 | | "fromlist is not empty. The level argument is used to determine whether\n" |
29 | | "to perform absolute or relative imports: 0 is absolute, while a positive\n" |
30 | | "number is the number of parent directories to search relative to the\n" |
31 | | "current module."); |
32 | | |
33 | | #define BUILTIN___IMPORT___METHODDEF \ |
34 | | {"__import__", _PyCFunction_CAST(builtin___import__), METH_FASTCALL|METH_KEYWORDS, builtin___import____doc__}, |
35 | | |
36 | | static PyObject * |
37 | | builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals, |
38 | | PyObject *locals, PyObject *fromlist, int level); |
39 | | |
40 | | static PyObject * |
41 | | builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
42 | 288k | { |
43 | 288k | PyObject *return_value = NULL; |
44 | 288k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
45 | | |
46 | 288k | #define NUM_KEYWORDS 5 |
47 | 288k | static struct { |
48 | 288k | PyGC_Head _this_is_not_used; |
49 | 288k | PyObject_VAR_HEAD |
50 | 288k | Py_hash_t ob_hash; |
51 | 288k | PyObject *ob_item[NUM_KEYWORDS]; |
52 | 288k | } _kwtuple = { |
53 | 288k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
54 | 288k | .ob_hash = -1, |
55 | 288k | .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), }, |
56 | 288k | }; |
57 | 288k | #undef NUM_KEYWORDS |
58 | 288k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
59 | | |
60 | | #else // !Py_BUILD_CORE |
61 | | # define KWTUPLE NULL |
62 | | #endif // !Py_BUILD_CORE |
63 | | |
64 | 288k | static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; |
65 | 288k | static _PyArg_Parser _parser = { |
66 | 288k | .keywords = _keywords, |
67 | 288k | .fname = "__import__", |
68 | 288k | .kwtuple = KWTUPLE, |
69 | 288k | }; |
70 | 288k | #undef KWTUPLE |
71 | 288k | PyObject *argsbuf[5]; |
72 | 288k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
73 | 288k | PyObject *name; |
74 | 288k | PyObject *globals = NULL; |
75 | 288k | PyObject *locals = NULL; |
76 | 288k | PyObject *fromlist = NULL; |
77 | 288k | int level = 0; |
78 | | |
79 | 288k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
80 | 288k | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
81 | 288k | if (!args) { |
82 | 0 | goto exit; |
83 | 0 | } |
84 | 288k | name = args[0]; |
85 | 288k | if (!noptargs) { |
86 | 842 | goto skip_optional_pos; |
87 | 842 | } |
88 | 287k | if (args[1]) { |
89 | 284k | globals = args[1]; |
90 | 284k | if (!--noptargs) { |
91 | 0 | goto skip_optional_pos; |
92 | 0 | } |
93 | 284k | } |
94 | 287k | if (args[2]) { |
95 | 284k | locals = args[2]; |
96 | 284k | if (!--noptargs) { |
97 | 0 | goto skip_optional_pos; |
98 | 0 | } |
99 | 284k | } |
100 | 287k | if (args[3]) { |
101 | 287k | fromlist = args[3]; |
102 | 287k | if (!--noptargs) { |
103 | 0 | goto skip_optional_pos; |
104 | 0 | } |
105 | 287k | } |
106 | 287k | level = PyLong_AsInt(args[4]); |
107 | 287k | if (level == -1 && PyErr_Occurred()) { |
108 | 0 | goto exit; |
109 | 0 | } |
110 | 288k | skip_optional_pos: |
111 | 288k | return_value = builtin___import___impl(module, name, globals, locals, fromlist, level); |
112 | | |
113 | 288k | exit: |
114 | 288k | return return_value; |
115 | 288k | } |
116 | | |
117 | | PyDoc_STRVAR(builtin___lazy_import____doc__, |
118 | | "__lazy_import__($module, /, name, globals=None, locals=None,\n" |
119 | | " fromlist=(), level=0)\n" |
120 | | "--\n" |
121 | | "\n" |
122 | | "Lazily imports a module.\n" |
123 | | "\n" |
124 | | "Returns either the module to be imported or a imp.lazy_module object\n" |
125 | | "which indicates the module to be lazily imported."); |
126 | | |
127 | | #define BUILTIN___LAZY_IMPORT___METHODDEF \ |
128 | | {"__lazy_import__", _PyCFunction_CAST(builtin___lazy_import__), METH_FASTCALL|METH_KEYWORDS, builtin___lazy_import____doc__}, |
129 | | |
130 | | static PyObject * |
131 | | builtin___lazy_import___impl(PyObject *module, PyObject *name, |
132 | | PyObject *globals, PyObject *locals, |
133 | | PyObject *fromlist, int level); |
134 | | |
135 | | static PyObject * |
136 | | builtin___lazy_import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
137 | 0 | { |
138 | 0 | PyObject *return_value = NULL; |
139 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
140 | |
|
141 | 0 | #define NUM_KEYWORDS 5 |
142 | 0 | static struct { |
143 | 0 | PyGC_Head _this_is_not_used; |
144 | 0 | PyObject_VAR_HEAD |
145 | 0 | Py_hash_t ob_hash; |
146 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
147 | 0 | } _kwtuple = { |
148 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
149 | 0 | .ob_hash = -1, |
150 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), }, |
151 | 0 | }; |
152 | 0 | #undef NUM_KEYWORDS |
153 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
154 | |
|
155 | | #else // !Py_BUILD_CORE |
156 | | # define KWTUPLE NULL |
157 | | #endif // !Py_BUILD_CORE |
158 | |
|
159 | 0 | static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; |
160 | 0 | static _PyArg_Parser _parser = { |
161 | 0 | .keywords = _keywords, |
162 | 0 | .fname = "__lazy_import__", |
163 | 0 | .kwtuple = KWTUPLE, |
164 | 0 | }; |
165 | 0 | #undef KWTUPLE |
166 | 0 | PyObject *argsbuf[5]; |
167 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
168 | 0 | PyObject *name; |
169 | 0 | PyObject *globals = NULL; |
170 | 0 | PyObject *locals = NULL; |
171 | 0 | PyObject *fromlist = NULL; |
172 | 0 | int level = 0; |
173 | |
|
174 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
175 | 0 | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
176 | 0 | if (!args) { |
177 | 0 | goto exit; |
178 | 0 | } |
179 | 0 | name = args[0]; |
180 | 0 | if (!noptargs) { |
181 | 0 | goto skip_optional_pos; |
182 | 0 | } |
183 | 0 | if (args[1]) { |
184 | 0 | globals = args[1]; |
185 | 0 | if (!--noptargs) { |
186 | 0 | goto skip_optional_pos; |
187 | 0 | } |
188 | 0 | } |
189 | 0 | if (args[2]) { |
190 | 0 | locals = args[2]; |
191 | 0 | if (!--noptargs) { |
192 | 0 | goto skip_optional_pos; |
193 | 0 | } |
194 | 0 | } |
195 | 0 | if (args[3]) { |
196 | 0 | fromlist = args[3]; |
197 | 0 | if (!--noptargs) { |
198 | 0 | goto skip_optional_pos; |
199 | 0 | } |
200 | 0 | } |
201 | 0 | level = PyLong_AsInt(args[4]); |
202 | 0 | if (level == -1 && PyErr_Occurred()) { |
203 | 0 | goto exit; |
204 | 0 | } |
205 | 0 | skip_optional_pos: |
206 | 0 | return_value = builtin___lazy_import___impl(module, name, globals, locals, fromlist, level); |
207 | |
|
208 | 0 | exit: |
209 | 0 | return return_value; |
210 | 0 | } |
211 | | |
212 | | PyDoc_STRVAR(builtin_abs__doc__, |
213 | | "abs($module, number, /)\n" |
214 | | "--\n" |
215 | | "\n" |
216 | | "Return the absolute value of the argument."); |
217 | | |
218 | | #define BUILTIN_ABS_METHODDEF \ |
219 | | {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, |
220 | | |
221 | | PyDoc_STRVAR(builtin_all__doc__, |
222 | | "all($module, iterable, /)\n" |
223 | | "--\n" |
224 | | "\n" |
225 | | "Return True if bool(x) is True for all values x in the iterable.\n" |
226 | | "\n" |
227 | | "If the iterable is empty, return True."); |
228 | | |
229 | | #define BUILTIN_ALL_METHODDEF \ |
230 | | {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, |
231 | | |
232 | | PyDoc_STRVAR(builtin_any__doc__, |
233 | | "any($module, iterable, /)\n" |
234 | | "--\n" |
235 | | "\n" |
236 | | "Return True if bool(x) is True for any x in the iterable.\n" |
237 | | "\n" |
238 | | "If the iterable is empty, return False."); |
239 | | |
240 | | #define BUILTIN_ANY_METHODDEF \ |
241 | | {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, |
242 | | |
243 | | PyDoc_STRVAR(builtin_ascii__doc__, |
244 | | "ascii($module, obj, /)\n" |
245 | | "--\n" |
246 | | "\n" |
247 | | "Return an ASCII-only representation of an object.\n" |
248 | | "\n" |
249 | | "As repr(), return a string containing a printable representation of an\n" |
250 | | "object, but escape the non-ASCII characters in the string returned by\n" |
251 | | "repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" |
252 | | "to that returned by repr() in Python 2."); |
253 | | |
254 | | #define BUILTIN_ASCII_METHODDEF \ |
255 | | {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, |
256 | | |
257 | | PyDoc_STRVAR(builtin_bin__doc__, |
258 | | "bin($module, integer, /)\n" |
259 | | "--\n" |
260 | | "\n" |
261 | | "Return the binary representation of an integer.\n" |
262 | | "\n" |
263 | | " >>> bin(2796202)\n" |
264 | | " \'0b1010101010101010101010\'"); |
265 | | |
266 | | #define BUILTIN_BIN_METHODDEF \ |
267 | | {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, |
268 | | |
269 | | PyDoc_STRVAR(builtin_callable__doc__, |
270 | | "callable($module, obj, /)\n" |
271 | | "--\n" |
272 | | "\n" |
273 | | "Return whether the object is callable (i.e., some kind of function).\n" |
274 | | "\n" |
275 | | "Note that classes are callable, as are instances of classes with a\n" |
276 | | "__call__() method."); |
277 | | |
278 | | #define BUILTIN_CALLABLE_METHODDEF \ |
279 | | {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, |
280 | | |
281 | | PyDoc_STRVAR(builtin_format__doc__, |
282 | | "format($module, value, format_spec=\'\', /)\n" |
283 | | "--\n" |
284 | | "\n" |
285 | | "Return type(value).__format__(value, format_spec)\n" |
286 | | "\n" |
287 | | "Many built-in types implement format_spec according to the\n" |
288 | | "Format Specification Mini-language. See help(\'FORMATTING\').\n" |
289 | | "\n" |
290 | | "If type(value) does not supply a method named __format__\n" |
291 | | "and format_spec is empty, then str(value) is returned.\n" |
292 | | "See also help(\'SPECIALMETHODS\')."); |
293 | | |
294 | | #define BUILTIN_FORMAT_METHODDEF \ |
295 | | {"format", _PyCFunction_CAST(builtin_format), METH_FASTCALL, builtin_format__doc__}, |
296 | | |
297 | | static PyObject * |
298 | | builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec); |
299 | | |
300 | | static PyObject * |
301 | | builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
302 | 0 | { |
303 | 0 | PyObject *return_value = NULL; |
304 | 0 | PyObject *value; |
305 | 0 | PyObject *format_spec = NULL; |
306 | |
|
307 | 0 | if (!_PyArg_CheckPositional("format", nargs, 1, 2)) { |
308 | 0 | goto exit; |
309 | 0 | } |
310 | 0 | value = args[0]; |
311 | 0 | if (nargs < 2) { |
312 | 0 | goto skip_optional; |
313 | 0 | } |
314 | 0 | if (!PyUnicode_Check(args[1])) { |
315 | 0 | _PyArg_BadArgument("format", "argument 2", "str", args[1]); |
316 | 0 | goto exit; |
317 | 0 | } |
318 | 0 | format_spec = args[1]; |
319 | 0 | skip_optional: |
320 | 0 | return_value = builtin_format_impl(module, value, format_spec); |
321 | |
|
322 | 0 | exit: |
323 | 0 | return return_value; |
324 | 0 | } |
325 | | |
326 | | PyDoc_STRVAR(builtin_chr__doc__, |
327 | | "chr($module, i, /)\n" |
328 | | "--\n" |
329 | | "\n" |
330 | | "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
331 | | |
332 | | #define BUILTIN_CHR_METHODDEF \ |
333 | | {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
334 | | |
335 | | PyDoc_STRVAR(builtin_compile__doc__, |
336 | | "compile($module, /, source, filename, mode, flags=0,\n" |
337 | | " dont_inherit=False, optimize=-1, *, module=None,\n" |
338 | | " _feature_version=-1)\n" |
339 | | "--\n" |
340 | | "\n" |
341 | | "Compile source into a code object that can be executed by exec() or eval().\n" |
342 | | "\n" |
343 | | "The source code may represent a Python module, statement or\n" |
344 | | "expression.\n" |
345 | | "The filename will be used for run-time error messages.\n" |
346 | | "The mode must be \'exec\' to compile a module, \'single\' to compile a\n" |
347 | | "single (interactive) statement, or \'eval\' to compile an expression.\n" |
348 | | "The flags argument, if present, controls which future statements\n" |
349 | | "influence the compilation of the code.\n" |
350 | | "The dont_inherit argument, if true, stops the compilation inheriting\n" |
351 | | "the effects of any future statements in effect in the code calling\n" |
352 | | "compile; if absent or false these statements do influence the\n" |
353 | | "compilation, in addition to any features explicitly specified."); |
354 | | |
355 | | #define BUILTIN_COMPILE_METHODDEF \ |
356 | | {"compile", _PyCFunction_CAST(builtin_compile), METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__}, |
357 | | |
358 | | static PyObject * |
359 | | builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, |
360 | | const char *mode, int flags, int dont_inherit, |
361 | | int optimize, PyObject *modname, int feature_version); |
362 | | |
363 | | static PyObject * |
364 | | builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
365 | 99.2k | { |
366 | 99.2k | PyObject *return_value = NULL; |
367 | 99.2k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
368 | | |
369 | 99.2k | #define NUM_KEYWORDS 8 |
370 | 99.2k | static struct { |
371 | 99.2k | PyGC_Head _this_is_not_used; |
372 | 99.2k | PyObject_VAR_HEAD |
373 | 99.2k | Py_hash_t ob_hash; |
374 | 99.2k | PyObject *ob_item[NUM_KEYWORDS]; |
375 | 99.2k | } _kwtuple = { |
376 | 99.2k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
377 | 99.2k | .ob_hash = -1, |
378 | 99.2k | .ob_item = { &_Py_ID(source), &_Py_ID(filename), &_Py_ID(mode), &_Py_ID(flags), &_Py_ID(dont_inherit), &_Py_ID(optimize), &_Py_ID(module), &_Py_ID(_feature_version), }, |
379 | 99.2k | }; |
380 | 99.2k | #undef NUM_KEYWORDS |
381 | 99.2k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
382 | | |
383 | | #else // !Py_BUILD_CORE |
384 | | # define KWTUPLE NULL |
385 | | #endif // !Py_BUILD_CORE |
386 | | |
387 | 99.2k | static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "module", "_feature_version", NULL}; |
388 | 99.2k | static _PyArg_Parser _parser = { |
389 | 99.2k | .keywords = _keywords, |
390 | 99.2k | .fname = "compile", |
391 | 99.2k | .kwtuple = KWTUPLE, |
392 | 99.2k | }; |
393 | 99.2k | #undef KWTUPLE |
394 | 99.2k | PyObject *argsbuf[8]; |
395 | 99.2k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
396 | 99.2k | PyObject *source; |
397 | 99.2k | PyObject *filename = NULL; |
398 | 99.2k | const char *mode; |
399 | 99.2k | int flags = 0; |
400 | 99.2k | int dont_inherit = 0; |
401 | 99.2k | int optimize = -1; |
402 | 99.2k | PyObject *modname = Py_None; |
403 | 99.2k | int feature_version = -1; |
404 | | |
405 | 99.2k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
406 | 99.2k | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
407 | 99.2k | if (!args) { |
408 | 0 | goto exit; |
409 | 0 | } |
410 | 99.2k | source = args[0]; |
411 | 99.2k | if (!PyUnicode_FSDecoder(args[1], &filename)) { |
412 | 0 | goto exit; |
413 | 0 | } |
414 | 99.2k | if (!PyUnicode_Check(args[2])) { |
415 | 0 | _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]); |
416 | 0 | goto exit; |
417 | 0 | } |
418 | 99.2k | Py_ssize_t mode_length; |
419 | 99.2k | mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length); |
420 | 99.2k | if (mode == NULL) { |
421 | 0 | goto exit; |
422 | 0 | } |
423 | 99.2k | if (strlen(mode) != (size_t)mode_length) { |
424 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
425 | 0 | goto exit; |
426 | 0 | } |
427 | 99.2k | if (!noptargs) { |
428 | 32 | goto skip_optional_pos; |
429 | 32 | } |
430 | 99.2k | if (args[3]) { |
431 | 99.0k | flags = PyLong_AsInt(args[3]); |
432 | 99.0k | if (flags == -1 && PyErr_Occurred()) { |
433 | 0 | goto exit; |
434 | 0 | } |
435 | 99.0k | if (!--noptargs) { |
436 | 0 | goto skip_optional_pos; |
437 | 0 | } |
438 | 99.0k | } |
439 | 99.2k | if (args[4]) { |
440 | 173 | dont_inherit = PyObject_IsTrue(args[4]); |
441 | 173 | if (dont_inherit < 0) { |
442 | 0 | goto exit; |
443 | 0 | } |
444 | 173 | if (!--noptargs) { |
445 | 0 | goto skip_optional_pos; |
446 | 0 | } |
447 | 173 | } |
448 | 99.2k | if (args[5]) { |
449 | 99.2k | optimize = PyLong_AsInt(args[5]); |
450 | 99.2k | if (optimize == -1 && PyErr_Occurred()) { |
451 | 0 | goto exit; |
452 | 0 | } |
453 | 99.2k | if (!--noptargs) { |
454 | 0 | goto skip_optional_pos; |
455 | 0 | } |
456 | 99.2k | } |
457 | 99.2k | skip_optional_pos: |
458 | 99.2k | if (!noptargs) { |
459 | 32 | goto skip_optional_kwonly; |
460 | 32 | } |
461 | 99.2k | if (args[6]) { |
462 | 99.2k | modname = args[6]; |
463 | 99.2k | if (!--noptargs) { |
464 | 173 | goto skip_optional_kwonly; |
465 | 173 | } |
466 | 99.2k | } |
467 | 99.0k | feature_version = PyLong_AsInt(args[7]); |
468 | 99.0k | if (feature_version == -1 && PyErr_Occurred()) { |
469 | 0 | goto exit; |
470 | 0 | } |
471 | 99.2k | skip_optional_kwonly: |
472 | 99.2k | return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, modname, feature_version); |
473 | | |
474 | 99.2k | exit: |
475 | | /* Cleanup for filename */ |
476 | 99.2k | Py_XDECREF(filename); |
477 | | |
478 | 99.2k | return return_value; |
479 | 99.2k | } |
480 | | |
481 | | PyDoc_STRVAR(builtin_divmod__doc__, |
482 | | "divmod($module, x, y, /)\n" |
483 | | "--\n" |
484 | | "\n" |
485 | | "Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); |
486 | | |
487 | | #define BUILTIN_DIVMOD_METHODDEF \ |
488 | | {"divmod", _PyCFunction_CAST(builtin_divmod), METH_FASTCALL, builtin_divmod__doc__}, |
489 | | |
490 | | static PyObject * |
491 | | builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y); |
492 | | |
493 | | static PyObject * |
494 | | builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
495 | 741k | { |
496 | 741k | PyObject *return_value = NULL; |
497 | 741k | PyObject *x; |
498 | 741k | PyObject *y; |
499 | | |
500 | 741k | if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { |
501 | 0 | goto exit; |
502 | 0 | } |
503 | 741k | x = args[0]; |
504 | 741k | y = args[1]; |
505 | 741k | return_value = builtin_divmod_impl(module, x, y); |
506 | | |
507 | 741k | exit: |
508 | 741k | return return_value; |
509 | 741k | } |
510 | | |
511 | | PyDoc_STRVAR(builtin_eval__doc__, |
512 | | "eval($module, source, /, globals=None, locals=None)\n" |
513 | | "--\n" |
514 | | "\n" |
515 | | "Evaluate the given source in the context of globals and locals.\n" |
516 | | "\n" |
517 | | "The source may be a string representing a Python expression\n" |
518 | | "or a code object as returned by compile().\n" |
519 | | "The globals must be a dictionary and locals can be any mapping,\n" |
520 | | "defaulting to the current globals and locals.\n" |
521 | | "If only globals is given, locals defaults to it."); |
522 | | |
523 | | #define BUILTIN_EVAL_METHODDEF \ |
524 | | {"eval", _PyCFunction_CAST(builtin_eval), METH_FASTCALL|METH_KEYWORDS, builtin_eval__doc__}, |
525 | | |
526 | | static PyObject * |
527 | | builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, |
528 | | PyObject *locals); |
529 | | |
530 | | static PyObject * |
531 | | builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
532 | 197 | { |
533 | 197 | PyObject *return_value = NULL; |
534 | 197 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
535 | | |
536 | 197 | #define NUM_KEYWORDS 2 |
537 | 197 | static struct { |
538 | 197 | PyGC_Head _this_is_not_used; |
539 | 197 | PyObject_VAR_HEAD |
540 | 197 | Py_hash_t ob_hash; |
541 | 197 | PyObject *ob_item[NUM_KEYWORDS]; |
542 | 197 | } _kwtuple = { |
543 | 197 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
544 | 197 | .ob_hash = -1, |
545 | 197 | .ob_item = { &_Py_ID(globals), &_Py_ID(locals), }, |
546 | 197 | }; |
547 | 197 | #undef NUM_KEYWORDS |
548 | 197 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
549 | | |
550 | | #else // !Py_BUILD_CORE |
551 | | # define KWTUPLE NULL |
552 | | #endif // !Py_BUILD_CORE |
553 | | |
554 | 197 | static const char * const _keywords[] = {"", "globals", "locals", NULL}; |
555 | 197 | static _PyArg_Parser _parser = { |
556 | 197 | .keywords = _keywords, |
557 | 197 | .fname = "eval", |
558 | 197 | .kwtuple = KWTUPLE, |
559 | 197 | }; |
560 | 197 | #undef KWTUPLE |
561 | 197 | PyObject *argsbuf[3]; |
562 | 197 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
563 | 197 | PyObject *source; |
564 | 197 | PyObject *globals = Py_None; |
565 | 197 | PyObject *locals = Py_None; |
566 | | |
567 | 197 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
568 | 197 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
569 | 197 | if (!args) { |
570 | 0 | goto exit; |
571 | 0 | } |
572 | 197 | source = args[0]; |
573 | 197 | if (!noptargs) { |
574 | 0 | goto skip_optional_pos; |
575 | 0 | } |
576 | 197 | if (args[1]) { |
577 | 197 | globals = args[1]; |
578 | 197 | if (!--noptargs) { |
579 | 197 | goto skip_optional_pos; |
580 | 197 | } |
581 | 197 | } |
582 | 0 | locals = args[2]; |
583 | 197 | skip_optional_pos: |
584 | 197 | return_value = builtin_eval_impl(module, source, globals, locals); |
585 | | |
586 | 197 | exit: |
587 | 197 | return return_value; |
588 | 197 | } |
589 | | |
590 | | PyDoc_STRVAR(builtin_exec__doc__, |
591 | | "exec($module, source, /, globals=None, locals=None, *, closure=None)\n" |
592 | | "--\n" |
593 | | "\n" |
594 | | "Execute the given source in the context of globals and locals.\n" |
595 | | "\n" |
596 | | "The source may be a string representing one or more Python statements\n" |
597 | | "or a code object as returned by compile().\n" |
598 | | "The globals must be a dictionary and locals can be any mapping,\n" |
599 | | "defaulting to the current globals and locals.\n" |
600 | | "If only globals is given, locals defaults to it.\n" |
601 | | "The closure must be a tuple of cellvars, and can only be used\n" |
602 | | "when source is a code object requiring exactly that many cellvars."); |
603 | | |
604 | | #define BUILTIN_EXEC_METHODDEF \ |
605 | | {"exec", _PyCFunction_CAST(builtin_exec), METH_FASTCALL|METH_KEYWORDS, builtin_exec__doc__}, |
606 | | |
607 | | static PyObject * |
608 | | builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, |
609 | | PyObject *locals, PyObject *closure); |
610 | | |
611 | | static PyObject * |
612 | | builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
613 | 7.21k | { |
614 | 7.21k | PyObject *return_value = NULL; |
615 | 7.21k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
616 | | |
617 | 7.21k | #define NUM_KEYWORDS 3 |
618 | 7.21k | static struct { |
619 | 7.21k | PyGC_Head _this_is_not_used; |
620 | 7.21k | PyObject_VAR_HEAD |
621 | 7.21k | Py_hash_t ob_hash; |
622 | 7.21k | PyObject *ob_item[NUM_KEYWORDS]; |
623 | 7.21k | } _kwtuple = { |
624 | 7.21k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
625 | 7.21k | .ob_hash = -1, |
626 | 7.21k | .ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), }, |
627 | 7.21k | }; |
628 | 7.21k | #undef NUM_KEYWORDS |
629 | 7.21k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
630 | | |
631 | | #else // !Py_BUILD_CORE |
632 | | # define KWTUPLE NULL |
633 | | #endif // !Py_BUILD_CORE |
634 | | |
635 | 7.21k | static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL}; |
636 | 7.21k | static _PyArg_Parser _parser = { |
637 | 7.21k | .keywords = _keywords, |
638 | 7.21k | .fname = "exec", |
639 | 7.21k | .kwtuple = KWTUPLE, |
640 | 7.21k | }; |
641 | 7.21k | #undef KWTUPLE |
642 | 7.21k | PyObject *argsbuf[4]; |
643 | 7.21k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
644 | 7.21k | PyObject *source; |
645 | 7.21k | PyObject *globals = Py_None; |
646 | 7.21k | PyObject *locals = Py_None; |
647 | 7.21k | PyObject *closure = NULL; |
648 | | |
649 | 7.21k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
650 | 7.21k | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
651 | 7.21k | if (!args) { |
652 | 0 | goto exit; |
653 | 0 | } |
654 | 7.21k | source = args[0]; |
655 | 7.21k | if (!noptargs) { |
656 | 0 | goto skip_optional_pos; |
657 | 0 | } |
658 | 7.21k | if (args[1]) { |
659 | 7.21k | globals = args[1]; |
660 | 7.21k | if (!--noptargs) { |
661 | 7.11k | goto skip_optional_pos; |
662 | 7.11k | } |
663 | 7.21k | } |
664 | 107 | if (args[2]) { |
665 | 107 | locals = args[2]; |
666 | 107 | if (!--noptargs) { |
667 | 107 | goto skip_optional_pos; |
668 | 107 | } |
669 | 107 | } |
670 | 7.21k | skip_optional_pos: |
671 | 7.21k | if (!noptargs) { |
672 | 7.21k | goto skip_optional_kwonly; |
673 | 7.21k | } |
674 | 0 | closure = args[3]; |
675 | 7.21k | skip_optional_kwonly: |
676 | 7.21k | return_value = builtin_exec_impl(module, source, globals, locals, closure); |
677 | | |
678 | 7.21k | exit: |
679 | 7.21k | return return_value; |
680 | 7.21k | } |
681 | | |
682 | | PyDoc_STRVAR(builtin_globals__doc__, |
683 | | "globals($module, /)\n" |
684 | | "--\n" |
685 | | "\n" |
686 | | "Return the dictionary containing the current scope\'s global variables.\n" |
687 | | "\n" |
688 | | "NOTE: Updates to this dictionary *will* affect name lookups in the\n" |
689 | | "current global scope and vice-versa."); |
690 | | |
691 | | #define BUILTIN_GLOBALS_METHODDEF \ |
692 | | {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, |
693 | | |
694 | | static PyObject * |
695 | | builtin_globals_impl(PyObject *module); |
696 | | |
697 | | static PyObject * |
698 | | builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
699 | 941 | { |
700 | 941 | return builtin_globals_impl(module); |
701 | 941 | } |
702 | | |
703 | | PyDoc_STRVAR(builtin_hasattr__doc__, |
704 | | "hasattr($module, obj, name, /)\n" |
705 | | "--\n" |
706 | | "\n" |
707 | | "Return whether the object has an attribute with the given name.\n" |
708 | | "\n" |
709 | | "This is done by calling getattr(obj, name) and catching AttributeError."); |
710 | | |
711 | | #define BUILTIN_HASATTR_METHODDEF \ |
712 | | {"hasattr", _PyCFunction_CAST(builtin_hasattr), METH_FASTCALL, builtin_hasattr__doc__}, |
713 | | |
714 | | static PyObject * |
715 | | builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
716 | | |
717 | | static PyObject * |
718 | | builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
719 | 10.5M | { |
720 | 10.5M | PyObject *return_value = NULL; |
721 | 10.5M | PyObject *obj; |
722 | 10.5M | PyObject *name; |
723 | | |
724 | 10.5M | if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) { |
725 | 0 | goto exit; |
726 | 0 | } |
727 | 10.5M | obj = args[0]; |
728 | 10.5M | name = args[1]; |
729 | 10.5M | return_value = builtin_hasattr_impl(module, obj, name); |
730 | | |
731 | 10.5M | exit: |
732 | 10.5M | return return_value; |
733 | 10.5M | } |
734 | | |
735 | | PyDoc_STRVAR(builtin_id__doc__, |
736 | | "id($module, obj, /)\n" |
737 | | "--\n" |
738 | | "\n" |
739 | | "Return the identity of an object.\n" |
740 | | "\n" |
741 | | "This is guaranteed to be unique among simultaneously existing objects.\n" |
742 | | "(CPython uses the object\'s memory address.)"); |
743 | | |
744 | | #define BUILTIN_ID_METHODDEF \ |
745 | | {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, |
746 | | |
747 | | static PyObject * |
748 | | builtin_id_impl(PyModuleDef *self, PyObject *v); |
749 | | |
750 | | static PyObject * |
751 | | builtin_id(PyObject *self, PyObject *v) |
752 | 25.5k | { |
753 | 25.5k | PyObject *return_value = NULL; |
754 | | |
755 | 25.5k | return_value = builtin_id_impl((PyModuleDef *)self, v); |
756 | | |
757 | 25.5k | return return_value; |
758 | 25.5k | } |
759 | | |
760 | | PyDoc_STRVAR(builtin_setattr__doc__, |
761 | | "setattr($module, obj, name, value, /)\n" |
762 | | "--\n" |
763 | | "\n" |
764 | | "Sets the named attribute on the given object to the specified value.\n" |
765 | | "\n" |
766 | | "setattr(x, \'y\', v) is equivalent to ``x.y = v``"); |
767 | | |
768 | | #define BUILTIN_SETATTR_METHODDEF \ |
769 | | {"setattr", _PyCFunction_CAST(builtin_setattr), METH_FASTCALL, builtin_setattr__doc__}, |
770 | | |
771 | | static PyObject * |
772 | | builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, |
773 | | PyObject *value); |
774 | | |
775 | | static PyObject * |
776 | | builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
777 | 1.42M | { |
778 | 1.42M | PyObject *return_value = NULL; |
779 | 1.42M | PyObject *obj; |
780 | 1.42M | PyObject *name; |
781 | 1.42M | PyObject *value; |
782 | | |
783 | 1.42M | if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) { |
784 | 0 | goto exit; |
785 | 0 | } |
786 | 1.42M | obj = args[0]; |
787 | 1.42M | name = args[1]; |
788 | 1.42M | value = args[2]; |
789 | 1.42M | return_value = builtin_setattr_impl(module, obj, name, value); |
790 | | |
791 | 1.42M | exit: |
792 | 1.42M | return return_value; |
793 | 1.42M | } |
794 | | |
795 | | PyDoc_STRVAR(builtin_delattr__doc__, |
796 | | "delattr($module, obj, name, /)\n" |
797 | | "--\n" |
798 | | "\n" |
799 | | "Deletes the named attribute from the given object.\n" |
800 | | "\n" |
801 | | "delattr(x, \'y\') is equivalent to ``del x.y``"); |
802 | | |
803 | | #define BUILTIN_DELATTR_METHODDEF \ |
804 | | {"delattr", _PyCFunction_CAST(builtin_delattr), METH_FASTCALL, builtin_delattr__doc__}, |
805 | | |
806 | | static PyObject * |
807 | | builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
808 | | |
809 | | static PyObject * |
810 | | builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
811 | 2.13k | { |
812 | 2.13k | PyObject *return_value = NULL; |
813 | 2.13k | PyObject *obj; |
814 | 2.13k | PyObject *name; |
815 | | |
816 | 2.13k | if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) { |
817 | 0 | goto exit; |
818 | 0 | } |
819 | 2.13k | obj = args[0]; |
820 | 2.13k | name = args[1]; |
821 | 2.13k | return_value = builtin_delattr_impl(module, obj, name); |
822 | | |
823 | 2.13k | exit: |
824 | 2.13k | return return_value; |
825 | 2.13k | } |
826 | | |
827 | | PyDoc_STRVAR(builtin_hash__doc__, |
828 | | "hash($module, obj, /)\n" |
829 | | "--\n" |
830 | | "\n" |
831 | | "Return the integer hash value for the given object.\n" |
832 | | "\n" |
833 | | "Two objects that compare equal must also have the same hash value, but\n" |
834 | | "the reverse is not necessarily true. Hash values may differ between\n" |
835 | | "Python processes. Not all objects are hashable; calling hash() on an\n" |
836 | | "unhashable object raises TypeError."); |
837 | | |
838 | | #define BUILTIN_HASH_METHODDEF \ |
839 | | {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, |
840 | | |
841 | | PyDoc_STRVAR(builtin_hex__doc__, |
842 | | "hex($module, integer, /)\n" |
843 | | "--\n" |
844 | | "\n" |
845 | | "Return the hexadecimal representation of an integer.\n" |
846 | | "\n" |
847 | | " >>> hex(12648430)\n" |
848 | | " \'0xc0ffee\'"); |
849 | | |
850 | | #define BUILTIN_HEX_METHODDEF \ |
851 | | {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, |
852 | | |
853 | | PyDoc_STRVAR(builtin_aiter__doc__, |
854 | | "aiter($module, async_iterable, /)\n" |
855 | | "--\n" |
856 | | "\n" |
857 | | "Return an AsyncIterator for an AsyncIterable object."); |
858 | | |
859 | | #define BUILTIN_AITER_METHODDEF \ |
860 | | {"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__}, |
861 | | |
862 | | PyDoc_STRVAR(builtin_anext__doc__, |
863 | | "anext($module, async_iterator, default=<unrepresentable>, /)\n" |
864 | | "--\n" |
865 | | "\n" |
866 | | "Return the next item from the async iterator.\n" |
867 | | "\n" |
868 | | "If default is given and the async iterator is exhausted,\n" |
869 | | "it is returned instead of raising StopAsyncIteration."); |
870 | | |
871 | | #define BUILTIN_ANEXT_METHODDEF \ |
872 | | {"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__}, |
873 | | |
874 | | static PyObject * |
875 | | builtin_anext_impl(PyObject *module, PyObject *aiterator, |
876 | | PyObject *default_value); |
877 | | |
878 | | static PyObject * |
879 | | builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
880 | 0 | { |
881 | 0 | PyObject *return_value = NULL; |
882 | 0 | PyObject *aiterator; |
883 | 0 | PyObject *default_value = NULL; |
884 | |
|
885 | 0 | if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) { |
886 | 0 | goto exit; |
887 | 0 | } |
888 | 0 | aiterator = args[0]; |
889 | 0 | if (nargs < 2) { |
890 | 0 | goto skip_optional; |
891 | 0 | } |
892 | 0 | default_value = args[1]; |
893 | 0 | skip_optional: |
894 | 0 | return_value = builtin_anext_impl(module, aiterator, default_value); |
895 | |
|
896 | 0 | exit: |
897 | 0 | return return_value; |
898 | 0 | } |
899 | | |
900 | | PyDoc_STRVAR(builtin_len__doc__, |
901 | | "len($module, obj, /)\n" |
902 | | "--\n" |
903 | | "\n" |
904 | | "Return the number of items in a container."); |
905 | | |
906 | | #define BUILTIN_LEN_METHODDEF \ |
907 | | {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, |
908 | | |
909 | | PyDoc_STRVAR(builtin_locals__doc__, |
910 | | "locals($module, /)\n" |
911 | | "--\n" |
912 | | "\n" |
913 | | "Return a dictionary containing the current scope\'s local variables.\n" |
914 | | "\n" |
915 | | "NOTE: Whether or not updates to this dictionary will affect name\n" |
916 | | "lookups in the local scope and vice-versa is *implementation\n" |
917 | | "dependent* and not covered by any backwards compatibility\n" |
918 | | "guarantees."); |
919 | | |
920 | | #define BUILTIN_LOCALS_METHODDEF \ |
921 | | {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, |
922 | | |
923 | | static PyObject * |
924 | | builtin_locals_impl(PyObject *module); |
925 | | |
926 | | static PyObject * |
927 | | builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
928 | 8 | { |
929 | 8 | return builtin_locals_impl(module); |
930 | 8 | } |
931 | | |
932 | | PyDoc_STRVAR(builtin_oct__doc__, |
933 | | "oct($module, integer, /)\n" |
934 | | "--\n" |
935 | | "\n" |
936 | | "Return the octal representation of an integer.\n" |
937 | | "\n" |
938 | | " >>> oct(342391)\n" |
939 | | " \'0o1234567\'"); |
940 | | |
941 | | #define BUILTIN_OCT_METHODDEF \ |
942 | | {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, |
943 | | |
944 | | PyDoc_STRVAR(builtin_ord__doc__, |
945 | | "ord($module, character, /)\n" |
946 | | "--\n" |
947 | | "\n" |
948 | | "Return the ordinal value of a character.\n" |
949 | | "\n" |
950 | | "If the argument is a one-character string, return the Unicode code\n" |
951 | | "point of that character.\n" |
952 | | "\n" |
953 | | "If the argument is a bytes or bytearray object of length 1, return its\n" |
954 | | "single byte value."); |
955 | | |
956 | | #define BUILTIN_ORD_METHODDEF \ |
957 | | {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, |
958 | | |
959 | | PyDoc_STRVAR(builtin_pow__doc__, |
960 | | "pow($module, /, base, exp, mod=None)\n" |
961 | | "--\n" |
962 | | "\n" |
963 | | "Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n" |
964 | | "\n" |
965 | | "Some types, such as ints, are able to use a more efficient algorithm\n" |
966 | | "when invoked using the three argument form."); |
967 | | |
968 | | #define BUILTIN_POW_METHODDEF \ |
969 | | {"pow", _PyCFunction_CAST(builtin_pow), METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__}, |
970 | | |
971 | | static PyObject * |
972 | | builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp, |
973 | | PyObject *mod); |
974 | | |
975 | | static PyObject * |
976 | | builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
977 | 4 | { |
978 | 4 | PyObject *return_value = NULL; |
979 | 4 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
980 | | |
981 | 4 | #define NUM_KEYWORDS 3 |
982 | 4 | static struct { |
983 | 4 | PyGC_Head _this_is_not_used; |
984 | 4 | PyObject_VAR_HEAD |
985 | 4 | Py_hash_t ob_hash; |
986 | 4 | PyObject *ob_item[NUM_KEYWORDS]; |
987 | 4 | } _kwtuple = { |
988 | 4 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
989 | 4 | .ob_hash = -1, |
990 | 4 | .ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), }, |
991 | 4 | }; |
992 | 4 | #undef NUM_KEYWORDS |
993 | 4 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
994 | | |
995 | | #else // !Py_BUILD_CORE |
996 | | # define KWTUPLE NULL |
997 | | #endif // !Py_BUILD_CORE |
998 | | |
999 | 4 | static const char * const _keywords[] = {"base", "exp", "mod", NULL}; |
1000 | 4 | static _PyArg_Parser _parser = { |
1001 | 4 | .keywords = _keywords, |
1002 | 4 | .fname = "pow", |
1003 | 4 | .kwtuple = KWTUPLE, |
1004 | 4 | }; |
1005 | 4 | #undef KWTUPLE |
1006 | 4 | PyObject *argsbuf[3]; |
1007 | 4 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1008 | 4 | PyObject *base; |
1009 | 4 | PyObject *exp; |
1010 | 4 | PyObject *mod = Py_None; |
1011 | | |
1012 | 4 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1013 | 4 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1014 | 4 | if (!args) { |
1015 | 0 | goto exit; |
1016 | 0 | } |
1017 | 4 | base = args[0]; |
1018 | 4 | exp = args[1]; |
1019 | 4 | if (!noptargs) { |
1020 | 0 | goto skip_optional_pos; |
1021 | 0 | } |
1022 | 4 | mod = args[2]; |
1023 | 4 | skip_optional_pos: |
1024 | 4 | return_value = builtin_pow_impl(module, base, exp, mod); |
1025 | | |
1026 | 4 | exit: |
1027 | 4 | return return_value; |
1028 | 4 | } |
1029 | | |
1030 | | PyDoc_STRVAR(builtin_print__doc__, |
1031 | | "print($module, /, *objects, sep=\' \', end=\'\\n\', file=None, flush=False)\n" |
1032 | | "--\n" |
1033 | | "\n" |
1034 | | "Prints the values to a stream, or to sys.stdout by default.\n" |
1035 | | "\n" |
1036 | | " sep\n" |
1037 | | " string inserted between values, default a space.\n" |
1038 | | " end\n" |
1039 | | " string appended after the last value, default a newline.\n" |
1040 | | " file\n" |
1041 | | " a file-like object (stream); defaults to the current sys.stdout.\n" |
1042 | | " flush\n" |
1043 | | " whether to forcibly flush the stream."); |
1044 | | |
1045 | | #define BUILTIN_PRINT_METHODDEF \ |
1046 | | {"print", _PyCFunction_CAST(builtin_print), METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__}, |
1047 | | |
1048 | | static PyObject * |
1049 | | builtin_print_impl(PyObject *module, PyObject * const *objects, |
1050 | | Py_ssize_t objects_length, PyObject *sep, PyObject *end, |
1051 | | PyObject *file, int flush); |
1052 | | |
1053 | | static PyObject * |
1054 | | builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1055 | 0 | { |
1056 | 0 | PyObject *return_value = NULL; |
1057 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1058 | |
|
1059 | 0 | #define NUM_KEYWORDS 4 |
1060 | 0 | static struct { |
1061 | 0 | PyGC_Head _this_is_not_used; |
1062 | 0 | PyObject_VAR_HEAD |
1063 | 0 | Py_hash_t ob_hash; |
1064 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1065 | 0 | } _kwtuple = { |
1066 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1067 | 0 | .ob_hash = -1, |
1068 | 0 | .ob_item = { &_Py_ID(sep), &_Py_ID(end), &_Py_ID(file), &_Py_ID(flush), }, |
1069 | 0 | }; |
1070 | 0 | #undef NUM_KEYWORDS |
1071 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1072 | |
|
1073 | | #else // !Py_BUILD_CORE |
1074 | | # define KWTUPLE NULL |
1075 | | #endif // !Py_BUILD_CORE |
1076 | |
|
1077 | 0 | static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL}; |
1078 | 0 | static _PyArg_Parser _parser = { |
1079 | 0 | .keywords = _keywords, |
1080 | 0 | .fname = "print", |
1081 | 0 | .kwtuple = KWTUPLE, |
1082 | 0 | }; |
1083 | 0 | #undef KWTUPLE |
1084 | 0 | PyObject *argsbuf[4]; |
1085 | 0 | PyObject * const *fastargs; |
1086 | 0 | Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1087 | 0 | PyObject * const *objects; |
1088 | 0 | Py_ssize_t objects_length; |
1089 | 0 | PyObject *sep = Py_None; |
1090 | 0 | PyObject *end = Py_None; |
1091 | 0 | PyObject *file = Py_None; |
1092 | 0 | int flush = 0; |
1093 | |
|
1094 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1095 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf); |
1096 | 0 | if (!fastargs) { |
1097 | 0 | goto exit; |
1098 | 0 | } |
1099 | 0 | if (!noptargs) { |
1100 | 0 | goto skip_optional_kwonly; |
1101 | 0 | } |
1102 | 0 | if (fastargs[0]) { |
1103 | 0 | sep = fastargs[0]; |
1104 | 0 | if (!--noptargs) { |
1105 | 0 | goto skip_optional_kwonly; |
1106 | 0 | } |
1107 | 0 | } |
1108 | 0 | if (fastargs[1]) { |
1109 | 0 | end = fastargs[1]; |
1110 | 0 | if (!--noptargs) { |
1111 | 0 | goto skip_optional_kwonly; |
1112 | 0 | } |
1113 | 0 | } |
1114 | 0 | if (fastargs[2]) { |
1115 | 0 | file = fastargs[2]; |
1116 | 0 | if (!--noptargs) { |
1117 | 0 | goto skip_optional_kwonly; |
1118 | 0 | } |
1119 | 0 | } |
1120 | 0 | flush = PyObject_IsTrue(fastargs[3]); |
1121 | 0 | if (flush < 0) { |
1122 | 0 | goto exit; |
1123 | 0 | } |
1124 | 0 | skip_optional_kwonly: |
1125 | 0 | objects = args; |
1126 | 0 | objects_length = nargs; |
1127 | 0 | return_value = builtin_print_impl(module, objects, objects_length, sep, end, file, flush); |
1128 | |
|
1129 | 0 | exit: |
1130 | 0 | return return_value; |
1131 | 0 | } |
1132 | | |
1133 | | PyDoc_STRVAR(builtin_input__doc__, |
1134 | | "input($module, prompt=\'\', /)\n" |
1135 | | "--\n" |
1136 | | "\n" |
1137 | | "Read a string from standard input. The trailing newline is stripped.\n" |
1138 | | "\n" |
1139 | | "The prompt string, if given, is printed to standard output without a\n" |
1140 | | "trailing newline before reading input.\n" |
1141 | | "\n" |
1142 | | "If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise\n" |
1143 | | "EOFError.\n" |
1144 | | "On *nix systems, readline is used if available."); |
1145 | | |
1146 | | #define BUILTIN_INPUT_METHODDEF \ |
1147 | | {"input", _PyCFunction_CAST(builtin_input), METH_FASTCALL, builtin_input__doc__}, |
1148 | | |
1149 | | static PyObject * |
1150 | | builtin_input_impl(PyObject *module, PyObject *prompt); |
1151 | | |
1152 | | static PyObject * |
1153 | | builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1154 | 0 | { |
1155 | 0 | PyObject *return_value = NULL; |
1156 | 0 | PyObject *prompt = NULL; |
1157 | |
|
1158 | 0 | if (!_PyArg_CheckPositional("input", nargs, 0, 1)) { |
1159 | 0 | goto exit; |
1160 | 0 | } |
1161 | 0 | if (nargs < 1) { |
1162 | 0 | goto skip_optional; |
1163 | 0 | } |
1164 | 0 | prompt = args[0]; |
1165 | 0 | skip_optional: |
1166 | 0 | return_value = builtin_input_impl(module, prompt); |
1167 | |
|
1168 | 0 | exit: |
1169 | 0 | return return_value; |
1170 | 0 | } |
1171 | | |
1172 | | PyDoc_STRVAR(builtin_repr__doc__, |
1173 | | "repr($module, obj, /)\n" |
1174 | | "--\n" |
1175 | | "\n" |
1176 | | "Return the canonical string representation of the object.\n" |
1177 | | "\n" |
1178 | | "For many object types, including most builtins, eval(repr(obj)) == obj."); |
1179 | | |
1180 | | #define BUILTIN_REPR_METHODDEF \ |
1181 | | {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, |
1182 | | |
1183 | | PyDoc_STRVAR(builtin_round__doc__, |
1184 | | "round($module, /, number, ndigits=None)\n" |
1185 | | "--\n" |
1186 | | "\n" |
1187 | | "Round a number to a given precision in decimal digits.\n" |
1188 | | "\n" |
1189 | | "The return value is an integer if ndigits is omitted or None.\n" |
1190 | | "Otherwise the return value has the same type as the number. ndigits\n" |
1191 | | "may be negative."); |
1192 | | |
1193 | | #define BUILTIN_ROUND_METHODDEF \ |
1194 | | {"round", _PyCFunction_CAST(builtin_round), METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__}, |
1195 | | |
1196 | | static PyObject * |
1197 | | builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits); |
1198 | | |
1199 | | static PyObject * |
1200 | | builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1201 | 0 | { |
1202 | 0 | PyObject *return_value = NULL; |
1203 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1204 | |
|
1205 | 0 | #define NUM_KEYWORDS 2 |
1206 | 0 | static struct { |
1207 | 0 | PyGC_Head _this_is_not_used; |
1208 | 0 | PyObject_VAR_HEAD |
1209 | 0 | Py_hash_t ob_hash; |
1210 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1211 | 0 | } _kwtuple = { |
1212 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1213 | 0 | .ob_hash = -1, |
1214 | 0 | .ob_item = { &_Py_ID(number), &_Py_ID(ndigits), }, |
1215 | 0 | }; |
1216 | 0 | #undef NUM_KEYWORDS |
1217 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1218 | |
|
1219 | | #else // !Py_BUILD_CORE |
1220 | | # define KWTUPLE NULL |
1221 | | #endif // !Py_BUILD_CORE |
1222 | |
|
1223 | 0 | static const char * const _keywords[] = {"number", "ndigits", NULL}; |
1224 | 0 | static _PyArg_Parser _parser = { |
1225 | 0 | .keywords = _keywords, |
1226 | 0 | .fname = "round", |
1227 | 0 | .kwtuple = KWTUPLE, |
1228 | 0 | }; |
1229 | 0 | #undef KWTUPLE |
1230 | 0 | PyObject *argsbuf[2]; |
1231 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1232 | 0 | PyObject *number; |
1233 | 0 | PyObject *ndigits = Py_None; |
1234 | |
|
1235 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1236 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1237 | 0 | if (!args) { |
1238 | 0 | goto exit; |
1239 | 0 | } |
1240 | 0 | number = args[0]; |
1241 | 0 | if (!noptargs) { |
1242 | 0 | goto skip_optional_pos; |
1243 | 0 | } |
1244 | 0 | ndigits = args[1]; |
1245 | 0 | skip_optional_pos: |
1246 | 0 | return_value = builtin_round_impl(module, number, ndigits); |
1247 | |
|
1248 | 0 | exit: |
1249 | 0 | return return_value; |
1250 | 0 | } |
1251 | | |
1252 | | PyDoc_STRVAR(builtin_sum__doc__, |
1253 | | "sum($module, iterable, /, start=0)\n" |
1254 | | "--\n" |
1255 | | "\n" |
1256 | | "Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" |
1257 | | "\n" |
1258 | | "When the iterable is empty, return the start value.\n" |
1259 | | "This function is intended specifically for use with numeric values and\n" |
1260 | | "may reject non-numeric types."); |
1261 | | |
1262 | | #define BUILTIN_SUM_METHODDEF \ |
1263 | | {"sum", _PyCFunction_CAST(builtin_sum), METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__}, |
1264 | | |
1265 | | static PyObject * |
1266 | | builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start); |
1267 | | |
1268 | | static PyObject * |
1269 | | builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1270 | 11.8M | { |
1271 | 11.8M | PyObject *return_value = NULL; |
1272 | 11.8M | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1273 | | |
1274 | 11.8M | #define NUM_KEYWORDS 1 |
1275 | 11.8M | static struct { |
1276 | 11.8M | PyGC_Head _this_is_not_used; |
1277 | 11.8M | PyObject_VAR_HEAD |
1278 | 11.8M | Py_hash_t ob_hash; |
1279 | 11.8M | PyObject *ob_item[NUM_KEYWORDS]; |
1280 | 11.8M | } _kwtuple = { |
1281 | 11.8M | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1282 | 11.8M | .ob_hash = -1, |
1283 | 11.8M | .ob_item = { &_Py_ID(start), }, |
1284 | 11.8M | }; |
1285 | 11.8M | #undef NUM_KEYWORDS |
1286 | 11.8M | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1287 | | |
1288 | | #else // !Py_BUILD_CORE |
1289 | | # define KWTUPLE NULL |
1290 | | #endif // !Py_BUILD_CORE |
1291 | | |
1292 | 11.8M | static const char * const _keywords[] = {"", "start", NULL}; |
1293 | 11.8M | static _PyArg_Parser _parser = { |
1294 | 11.8M | .keywords = _keywords, |
1295 | 11.8M | .fname = "sum", |
1296 | 11.8M | .kwtuple = KWTUPLE, |
1297 | 11.8M | }; |
1298 | 11.8M | #undef KWTUPLE |
1299 | 11.8M | PyObject *argsbuf[2]; |
1300 | 11.8M | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1301 | 11.8M | PyObject *iterable; |
1302 | 11.8M | PyObject *start = NULL; |
1303 | | |
1304 | 11.8M | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1305 | 11.8M | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1306 | 11.8M | if (!args) { |
1307 | 0 | goto exit; |
1308 | 0 | } |
1309 | 11.8M | iterable = args[0]; |
1310 | 11.8M | if (!noptargs) { |
1311 | 3.33M | goto skip_optional_pos; |
1312 | 3.33M | } |
1313 | 8.53M | start = args[1]; |
1314 | 11.8M | skip_optional_pos: |
1315 | 11.8M | return_value = builtin_sum_impl(module, iterable, start); |
1316 | | |
1317 | 11.8M | exit: |
1318 | 11.8M | return return_value; |
1319 | 11.8M | } |
1320 | | |
1321 | | PyDoc_STRVAR(builtin_isinstance__doc__, |
1322 | | "isinstance($module, obj, class_or_tuple, /)\n" |
1323 | | "--\n" |
1324 | | "\n" |
1325 | | "Return whether an object is an instance of a class or of a subclass thereof.\n" |
1326 | | "\n" |
1327 | | "A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the\n" |
1328 | | "target to check against. This is equivalent to ``isinstance(x, A) or\n" |
1329 | | "isinstance(x, B) or ...`` etc."); |
1330 | | |
1331 | | #define BUILTIN_ISINSTANCE_METHODDEF \ |
1332 | | {"isinstance", _PyCFunction_CAST(builtin_isinstance), METH_FASTCALL, builtin_isinstance__doc__}, |
1333 | | |
1334 | | static PyObject * |
1335 | | builtin_isinstance_impl(PyObject *module, PyObject *obj, |
1336 | | PyObject *class_or_tuple); |
1337 | | |
1338 | | static PyObject * |
1339 | | builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1340 | 2.43k | { |
1341 | 2.43k | PyObject *return_value = NULL; |
1342 | 2.43k | PyObject *obj; |
1343 | 2.43k | PyObject *class_or_tuple; |
1344 | | |
1345 | 2.43k | if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) { |
1346 | 0 | goto exit; |
1347 | 0 | } |
1348 | 2.43k | obj = args[0]; |
1349 | 2.43k | class_or_tuple = args[1]; |
1350 | 2.43k | return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
1351 | | |
1352 | 2.43k | exit: |
1353 | 2.43k | return return_value; |
1354 | 2.43k | } |
1355 | | |
1356 | | PyDoc_STRVAR(builtin_issubclass__doc__, |
1357 | | "issubclass($module, cls, class_or_tuple, /)\n" |
1358 | | "--\n" |
1359 | | "\n" |
1360 | | "Return whether \'cls\' is derived from another class or is the same class.\n" |
1361 | | "\n" |
1362 | | "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the\n" |
1363 | | "target to check against. This is equivalent to ``issubclass(x, A) or\n" |
1364 | | "issubclass(x, B) or ...``."); |
1365 | | |
1366 | | #define BUILTIN_ISSUBCLASS_METHODDEF \ |
1367 | | {"issubclass", _PyCFunction_CAST(builtin_issubclass), METH_FASTCALL, builtin_issubclass__doc__}, |
1368 | | |
1369 | | static PyObject * |
1370 | | builtin_issubclass_impl(PyObject *module, PyObject *cls, |
1371 | | PyObject *class_or_tuple); |
1372 | | |
1373 | | static PyObject * |
1374 | | builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1375 | 18.2k | { |
1376 | 18.2k | PyObject *return_value = NULL; |
1377 | 18.2k | PyObject *cls; |
1378 | 18.2k | PyObject *class_or_tuple; |
1379 | | |
1380 | 18.2k | if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) { |
1381 | 0 | goto exit; |
1382 | 0 | } |
1383 | 18.2k | cls = args[0]; |
1384 | 18.2k | class_or_tuple = args[1]; |
1385 | 18.2k | return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
1386 | | |
1387 | 18.2k | exit: |
1388 | 18.2k | return return_value; |
1389 | 18.2k | } |
1390 | | /*[clinic end generated code: output=84efa9c5cc737ce5 input=a9049054013a1b77]*/ |