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