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