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