Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(builtin_abs__doc__, |
| 6 | "abs($module, x, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Return the absolute value of the argument."); |
| 10 | |
| 11 | #define BUILTIN_ABS_METHODDEF \ |
| 12 | {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, |
| 13 | |
| 14 | PyDoc_STRVAR(builtin_all__doc__, |
| 15 | "all($module, iterable, /)\n" |
| 16 | "--\n" |
| 17 | "\n" |
| 18 | "Return True if bool(x) is True for all values x in the iterable.\n" |
| 19 | "\n" |
| 20 | "If the iterable is empty, return True."); |
| 21 | |
| 22 | #define BUILTIN_ALL_METHODDEF \ |
| 23 | {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, |
| 24 | |
| 25 | PyDoc_STRVAR(builtin_any__doc__, |
| 26 | "any($module, iterable, /)\n" |
| 27 | "--\n" |
| 28 | "\n" |
| 29 | "Return True if bool(x) is True for any x in the iterable.\n" |
| 30 | "\n" |
| 31 | "If the iterable is empty, return False."); |
| 32 | |
| 33 | #define BUILTIN_ANY_METHODDEF \ |
| 34 | {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, |
| 35 | |
| 36 | PyDoc_STRVAR(builtin_ascii__doc__, |
| 37 | "ascii($module, obj, /)\n" |
| 38 | "--\n" |
| 39 | "\n" |
| 40 | "Return an ASCII-only representation of an object.\n" |
| 41 | "\n" |
| 42 | "As repr(), return a string containing a printable representation of an\n" |
| 43 | "object, but escape the non-ASCII characters in the string returned by\n" |
| 44 | "repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" |
| 45 | "to that returned by repr() in Python 2."); |
| 46 | |
| 47 | #define BUILTIN_ASCII_METHODDEF \ |
| 48 | {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, |
| 49 | |
| 50 | PyDoc_STRVAR(builtin_bin__doc__, |
| 51 | "bin($module, number, /)\n" |
| 52 | "--\n" |
| 53 | "\n" |
| 54 | "Return the binary representation of an integer.\n" |
| 55 | "\n" |
| 56 | " >>> bin(2796202)\n" |
| 57 | " \'0b1010101010101010101010\'"); |
| 58 | |
| 59 | #define BUILTIN_BIN_METHODDEF \ |
| 60 | {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, |
| 61 | |
| 62 | PyDoc_STRVAR(builtin_callable__doc__, |
| 63 | "callable($module, obj, /)\n" |
| 64 | "--\n" |
| 65 | "\n" |
| 66 | "Return whether the object is callable (i.e., some kind of function).\n" |
| 67 | "\n" |
| 68 | "Note that classes are callable, as are instances of classes with a\n" |
| 69 | "__call__() method."); |
| 70 | |
| 71 | #define BUILTIN_CALLABLE_METHODDEF \ |
| 72 | {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, |
| 73 | |
| 74 | PyDoc_STRVAR(builtin_format__doc__, |
| 75 | "format($module, value, format_spec=\'\', /)\n" |
| 76 | "--\n" |
| 77 | "\n" |
| 78 | "Return value.__format__(format_spec)\n" |
| 79 | "\n" |
Amit Kumar | 2e6bb44 | 2017-05-29 06:32:26 +0530 | [diff] [blame] | 80 | "format_spec defaults to the empty string.\n" |
| 81 | "See the Format Specification Mini-Language section of help(\'FORMATTING\') for\n" |
| 82 | "details."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 83 | |
| 84 | #define BUILTIN_FORMAT_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 85 | {"format", (PyCFunction)builtin_format, METH_FASTCALL, builtin_format__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 86 | |
| 87 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 88 | builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 89 | |
| 90 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 91 | builtin_format(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 92 | { |
| 93 | PyObject *return_value = NULL; |
| 94 | PyObject *value; |
| 95 | PyObject *format_spec = NULL; |
| 96 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 97 | if (!_PyArg_ParseStack(args, nargs, "O|U:format", |
| 98 | &value, &format_spec)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 99 | goto exit; |
| 100 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 101 | return_value = builtin_format_impl(module, value, format_spec); |
| 102 | |
| 103 | exit: |
| 104 | return return_value; |
| 105 | } |
| 106 | |
| 107 | PyDoc_STRVAR(builtin_chr__doc__, |
| 108 | "chr($module, i, /)\n" |
| 109 | "--\n" |
| 110 | "\n" |
| 111 | "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
| 112 | |
| 113 | #define BUILTIN_CHR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 114 | {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 115 | |
| 116 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 117 | builtin_chr_impl(PyObject *module, int i); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 118 | |
| 119 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 120 | builtin_chr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 121 | { |
| 122 | PyObject *return_value = NULL; |
| 123 | int i; |
| 124 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 125 | if (!PyArg_Parse(arg, "i:chr", &i)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 126 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 127 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 128 | return_value = builtin_chr_impl(module, i); |
| 129 | |
| 130 | exit: |
| 131 | return return_value; |
| 132 | } |
| 133 | |
| 134 | PyDoc_STRVAR(builtin_compile__doc__, |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 135 | "compile($module, /, source, filename, mode, flags=0,\n" |
| 136 | " dont_inherit=False, optimize=-1)\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 137 | "--\n" |
| 138 | "\n" |
| 139 | "Compile source into a code object that can be executed by exec() or eval().\n" |
| 140 | "\n" |
| 141 | "The source code may represent a Python module, statement or expression.\n" |
| 142 | "The filename will be used for run-time error messages.\n" |
| 143 | "The mode must be \'exec\' to compile a module, \'single\' to compile a\n" |
| 144 | "single (interactive) statement, or \'eval\' to compile an expression.\n" |
| 145 | "The flags argument, if present, controls which future statements influence\n" |
| 146 | "the compilation of the code.\n" |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 147 | "The dont_inherit argument, if true, stops the compilation inheriting\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 148 | "the effects of any future statements in effect in the code calling\n" |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 149 | "compile; if absent or false these statements do influence the compilation,\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 150 | "in addition to any features explicitly specified."); |
| 151 | |
| 152 | #define BUILTIN_COMPILE_METHODDEF \ |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 153 | {"compile", (PyCFunction)builtin_compile, METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 154 | |
| 155 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 156 | builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, |
| 157 | const char *mode, int flags, int dont_inherit, |
| 158 | int optimize); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 159 | |
| 160 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 161 | builtin_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 162 | { |
| 163 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 164 | static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL}; |
| 165 | static _PyArg_Parser _parser = {"OO&s|iii:compile", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 166 | PyObject *source; |
| 167 | PyObject *filename; |
| 168 | const char *mode; |
| 169 | int flags = 0; |
| 170 | int dont_inherit = 0; |
| 171 | int optimize = -1; |
| 172 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 173 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 174 | &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 175 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 176 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 177 | return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); |
| 178 | |
| 179 | exit: |
| 180 | return return_value; |
| 181 | } |
| 182 | |
| 183 | PyDoc_STRVAR(builtin_divmod__doc__, |
| 184 | "divmod($module, x, y, /)\n" |
| 185 | "--\n" |
| 186 | "\n" |
Serhiy Storchaka | df07173 | 2016-05-01 20:33:24 +0300 | [diff] [blame] | 187 | "Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 188 | |
| 189 | #define BUILTIN_DIVMOD_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 190 | {"divmod", (PyCFunction)builtin_divmod, METH_FASTCALL, builtin_divmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 191 | |
| 192 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 193 | builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 194 | |
| 195 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 196 | builtin_divmod(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 197 | { |
| 198 | PyObject *return_value = NULL; |
| 199 | PyObject *x; |
| 200 | PyObject *y; |
| 201 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 202 | if (!_PyArg_UnpackStack(args, nargs, "divmod", |
| 203 | 2, 2, |
| 204 | &x, &y)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 205 | goto exit; |
| 206 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 207 | return_value = builtin_divmod_impl(module, x, y); |
| 208 | |
| 209 | exit: |
| 210 | return return_value; |
| 211 | } |
| 212 | |
| 213 | PyDoc_STRVAR(builtin_eval__doc__, |
| 214 | "eval($module, source, globals=None, locals=None, /)\n" |
| 215 | "--\n" |
| 216 | "\n" |
| 217 | "Evaluate the given source in the context of globals and locals.\n" |
| 218 | "\n" |
| 219 | "The source may be a string representing a Python expression\n" |
| 220 | "or a code object as returned by compile().\n" |
| 221 | "The globals must be a dictionary and locals can be any mapping,\n" |
| 222 | "defaulting to the current globals and locals.\n" |
| 223 | "If only globals is given, locals defaults to it."); |
| 224 | |
| 225 | #define BUILTIN_EVAL_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 226 | {"eval", (PyCFunction)builtin_eval, METH_FASTCALL, builtin_eval__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 227 | |
| 228 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 229 | builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 230 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 231 | |
| 232 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 233 | builtin_eval(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 234 | { |
| 235 | PyObject *return_value = NULL; |
| 236 | PyObject *source; |
| 237 | PyObject *globals = Py_None; |
| 238 | PyObject *locals = Py_None; |
| 239 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 240 | if (!_PyArg_UnpackStack(args, nargs, "eval", |
| 241 | 1, 3, |
| 242 | &source, &globals, &locals)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 243 | goto exit; |
| 244 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 245 | return_value = builtin_eval_impl(module, source, globals, locals); |
| 246 | |
| 247 | exit: |
| 248 | return return_value; |
| 249 | } |
| 250 | |
| 251 | PyDoc_STRVAR(builtin_exec__doc__, |
| 252 | "exec($module, source, globals=None, locals=None, /)\n" |
| 253 | "--\n" |
| 254 | "\n" |
| 255 | "Execute the given source in the context of globals and locals.\n" |
| 256 | "\n" |
| 257 | "The source may be a string representing one or more Python statements\n" |
| 258 | "or a code object as returned by compile().\n" |
| 259 | "The globals must be a dictionary and locals can be any mapping,\n" |
| 260 | "defaulting to the current globals and locals.\n" |
| 261 | "If only globals is given, locals defaults to it."); |
| 262 | |
| 263 | #define BUILTIN_EXEC_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 264 | {"exec", (PyCFunction)builtin_exec, METH_FASTCALL, builtin_exec__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 265 | |
| 266 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 267 | builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 268 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 269 | |
| 270 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 271 | builtin_exec(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 272 | { |
| 273 | PyObject *return_value = NULL; |
| 274 | PyObject *source; |
| 275 | PyObject *globals = Py_None; |
| 276 | PyObject *locals = Py_None; |
| 277 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 278 | if (!_PyArg_UnpackStack(args, nargs, "exec", |
| 279 | 1, 3, |
| 280 | &source, &globals, &locals)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 281 | goto exit; |
| 282 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 283 | return_value = builtin_exec_impl(module, source, globals, locals); |
| 284 | |
| 285 | exit: |
| 286 | return return_value; |
| 287 | } |
| 288 | |
| 289 | PyDoc_STRVAR(builtin_globals__doc__, |
| 290 | "globals($module, /)\n" |
| 291 | "--\n" |
| 292 | "\n" |
| 293 | "Return the dictionary containing the current scope\'s global variables.\n" |
| 294 | "\n" |
| 295 | "NOTE: Updates to this dictionary *will* affect name lookups in the current\n" |
| 296 | "global scope and vice-versa."); |
| 297 | |
| 298 | #define BUILTIN_GLOBALS_METHODDEF \ |
| 299 | {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, |
| 300 | |
| 301 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 302 | builtin_globals_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 303 | |
| 304 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 305 | builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 306 | { |
| 307 | return builtin_globals_impl(module); |
| 308 | } |
| 309 | |
| 310 | PyDoc_STRVAR(builtin_hasattr__doc__, |
| 311 | "hasattr($module, obj, name, /)\n" |
| 312 | "--\n" |
| 313 | "\n" |
| 314 | "Return whether the object has an attribute with the given name.\n" |
| 315 | "\n" |
| 316 | "This is done by calling getattr(obj, name) and catching AttributeError."); |
| 317 | |
| 318 | #define BUILTIN_HASATTR_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 319 | {"hasattr", (PyCFunction)builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 320 | |
| 321 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 322 | builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 323 | |
| 324 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 325 | builtin_hasattr(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 326 | { |
| 327 | PyObject *return_value = NULL; |
| 328 | PyObject *obj; |
| 329 | PyObject *name; |
| 330 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 331 | if (!_PyArg_UnpackStack(args, nargs, "hasattr", |
| 332 | 2, 2, |
| 333 | &obj, &name)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 334 | goto exit; |
| 335 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 336 | return_value = builtin_hasattr_impl(module, obj, name); |
| 337 | |
| 338 | exit: |
| 339 | return return_value; |
| 340 | } |
| 341 | |
| 342 | PyDoc_STRVAR(builtin_id__doc__, |
| 343 | "id($module, obj, /)\n" |
| 344 | "--\n" |
| 345 | "\n" |
| 346 | "Return the identity of an object.\n" |
| 347 | "\n" |
| 348 | "This is guaranteed to be unique among simultaneously existing objects.\n" |
| 349 | "(CPython uses the object\'s memory address.)"); |
| 350 | |
| 351 | #define BUILTIN_ID_METHODDEF \ |
| 352 | {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, |
| 353 | |
| 354 | PyDoc_STRVAR(builtin_setattr__doc__, |
| 355 | "setattr($module, obj, name, value, /)\n" |
| 356 | "--\n" |
| 357 | "\n" |
| 358 | "Sets the named attribute on the given object to the specified value.\n" |
| 359 | "\n" |
| 360 | "setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'"); |
| 361 | |
| 362 | #define BUILTIN_SETATTR_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 363 | {"setattr", (PyCFunction)builtin_setattr, METH_FASTCALL, builtin_setattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 364 | |
| 365 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 366 | builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 367 | PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 368 | |
| 369 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 370 | builtin_setattr(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 371 | { |
| 372 | PyObject *return_value = NULL; |
| 373 | PyObject *obj; |
| 374 | PyObject *name; |
| 375 | PyObject *value; |
| 376 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 377 | if (!_PyArg_UnpackStack(args, nargs, "setattr", |
| 378 | 3, 3, |
| 379 | &obj, &name, &value)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 380 | goto exit; |
| 381 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 382 | return_value = builtin_setattr_impl(module, obj, name, value); |
| 383 | |
| 384 | exit: |
| 385 | return return_value; |
| 386 | } |
| 387 | |
| 388 | PyDoc_STRVAR(builtin_delattr__doc__, |
| 389 | "delattr($module, obj, name, /)\n" |
| 390 | "--\n" |
| 391 | "\n" |
| 392 | "Deletes the named attribute from the given object.\n" |
| 393 | "\n" |
| 394 | "delattr(x, \'y\') is equivalent to ``del x.y\'\'"); |
| 395 | |
| 396 | #define BUILTIN_DELATTR_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 397 | {"delattr", (PyCFunction)builtin_delattr, METH_FASTCALL, builtin_delattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 398 | |
| 399 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 400 | builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 401 | |
| 402 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 403 | builtin_delattr(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 404 | { |
| 405 | PyObject *return_value = NULL; |
| 406 | PyObject *obj; |
| 407 | PyObject *name; |
| 408 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 409 | if (!_PyArg_UnpackStack(args, nargs, "delattr", |
| 410 | 2, 2, |
| 411 | &obj, &name)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 412 | goto exit; |
| 413 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 414 | return_value = builtin_delattr_impl(module, obj, name); |
| 415 | |
| 416 | exit: |
| 417 | return return_value; |
| 418 | } |
| 419 | |
| 420 | PyDoc_STRVAR(builtin_hash__doc__, |
| 421 | "hash($module, obj, /)\n" |
| 422 | "--\n" |
| 423 | "\n" |
| 424 | "Return the hash value for the given object.\n" |
| 425 | "\n" |
| 426 | "Two objects that compare equal must also have the same hash value, but the\n" |
| 427 | "reverse is not necessarily true."); |
| 428 | |
| 429 | #define BUILTIN_HASH_METHODDEF \ |
| 430 | {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, |
| 431 | |
| 432 | PyDoc_STRVAR(builtin_hex__doc__, |
| 433 | "hex($module, number, /)\n" |
| 434 | "--\n" |
| 435 | "\n" |
| 436 | "Return the hexadecimal representation of an integer.\n" |
| 437 | "\n" |
| 438 | " >>> hex(12648430)\n" |
| 439 | " \'0xc0ffee\'"); |
| 440 | |
| 441 | #define BUILTIN_HEX_METHODDEF \ |
| 442 | {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, |
| 443 | |
| 444 | PyDoc_STRVAR(builtin_len__doc__, |
| 445 | "len($module, obj, /)\n" |
| 446 | "--\n" |
| 447 | "\n" |
| 448 | "Return the number of items in a container."); |
| 449 | |
| 450 | #define BUILTIN_LEN_METHODDEF \ |
| 451 | {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, |
| 452 | |
| 453 | PyDoc_STRVAR(builtin_locals__doc__, |
| 454 | "locals($module, /)\n" |
| 455 | "--\n" |
| 456 | "\n" |
| 457 | "Return a dictionary containing the current scope\'s local variables.\n" |
| 458 | "\n" |
| 459 | "NOTE: Whether or not updates to this dictionary will affect name lookups in\n" |
| 460 | "the local scope and vice-versa is *implementation dependent* and not\n" |
| 461 | "covered by any backwards compatibility guarantees."); |
| 462 | |
| 463 | #define BUILTIN_LOCALS_METHODDEF \ |
| 464 | {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, |
| 465 | |
| 466 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 467 | builtin_locals_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 468 | |
| 469 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 470 | builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 471 | { |
| 472 | return builtin_locals_impl(module); |
| 473 | } |
| 474 | |
| 475 | PyDoc_STRVAR(builtin_oct__doc__, |
| 476 | "oct($module, number, /)\n" |
| 477 | "--\n" |
| 478 | "\n" |
| 479 | "Return the octal representation of an integer.\n" |
| 480 | "\n" |
| 481 | " >>> oct(342391)\n" |
| 482 | " \'0o1234567\'"); |
| 483 | |
| 484 | #define BUILTIN_OCT_METHODDEF \ |
| 485 | {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, |
| 486 | |
| 487 | PyDoc_STRVAR(builtin_ord__doc__, |
| 488 | "ord($module, c, /)\n" |
| 489 | "--\n" |
| 490 | "\n" |
| 491 | "Return the Unicode code point for a one-character string."); |
| 492 | |
| 493 | #define BUILTIN_ORD_METHODDEF \ |
| 494 | {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, |
| 495 | |
| 496 | PyDoc_STRVAR(builtin_pow__doc__, |
| 497 | "pow($module, x, y, z=None, /)\n" |
| 498 | "--\n" |
| 499 | "\n" |
| 500 | "Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n" |
| 501 | "\n" |
| 502 | "Some types, such as ints, are able to use a more efficient algorithm when\n" |
| 503 | "invoked using the three argument form."); |
| 504 | |
| 505 | #define BUILTIN_POW_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 506 | {"pow", (PyCFunction)builtin_pow, METH_FASTCALL, builtin_pow__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 507 | |
| 508 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 509 | builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 510 | |
| 511 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 512 | builtin_pow(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 513 | { |
| 514 | PyObject *return_value = NULL; |
| 515 | PyObject *x; |
| 516 | PyObject *y; |
| 517 | PyObject *z = Py_None; |
| 518 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 519 | if (!_PyArg_UnpackStack(args, nargs, "pow", |
| 520 | 2, 3, |
| 521 | &x, &y, &z)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 522 | goto exit; |
| 523 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 524 | return_value = builtin_pow_impl(module, x, y, z); |
| 525 | |
| 526 | exit: |
| 527 | return return_value; |
| 528 | } |
| 529 | |
| 530 | PyDoc_STRVAR(builtin_input__doc__, |
| 531 | "input($module, prompt=None, /)\n" |
| 532 | "--\n" |
| 533 | "\n" |
| 534 | "Read a string from standard input. The trailing newline is stripped.\n" |
| 535 | "\n" |
| 536 | "The prompt string, if given, is printed to standard output without a\n" |
| 537 | "trailing newline before reading input.\n" |
| 538 | "\n" |
| 539 | "If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n" |
| 540 | "On *nix systems, readline is used if available."); |
| 541 | |
| 542 | #define BUILTIN_INPUT_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 543 | {"input", (PyCFunction)builtin_input, METH_FASTCALL, builtin_input__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 544 | |
| 545 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 546 | builtin_input_impl(PyObject *module, PyObject *prompt); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 547 | |
| 548 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 549 | builtin_input(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 550 | { |
| 551 | PyObject *return_value = NULL; |
| 552 | PyObject *prompt = NULL; |
| 553 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 554 | if (!_PyArg_UnpackStack(args, nargs, "input", |
| 555 | 0, 1, |
| 556 | &prompt)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 557 | goto exit; |
| 558 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 559 | return_value = builtin_input_impl(module, prompt); |
| 560 | |
| 561 | exit: |
| 562 | return return_value; |
| 563 | } |
| 564 | |
| 565 | PyDoc_STRVAR(builtin_repr__doc__, |
| 566 | "repr($module, obj, /)\n" |
| 567 | "--\n" |
| 568 | "\n" |
| 569 | "Return the canonical string representation of the object.\n" |
| 570 | "\n" |
| 571 | "For many object types, including most builtins, eval(repr(obj)) == obj."); |
| 572 | |
| 573 | #define BUILTIN_REPR_METHODDEF \ |
| 574 | {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, |
| 575 | |
| 576 | PyDoc_STRVAR(builtin_sum__doc__, |
| 577 | "sum($module, iterable, start=0, /)\n" |
| 578 | "--\n" |
| 579 | "\n" |
| 580 | "Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" |
| 581 | "\n" |
| 582 | "When the iterable is empty, return the start value.\n" |
| 583 | "This function is intended specifically for use with numeric values and may\n" |
| 584 | "reject non-numeric types."); |
| 585 | |
| 586 | #define BUILTIN_SUM_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 587 | {"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 588 | |
| 589 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 590 | builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 591 | |
| 592 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 593 | builtin_sum(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 594 | { |
| 595 | PyObject *return_value = NULL; |
| 596 | PyObject *iterable; |
| 597 | PyObject *start = NULL; |
| 598 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 599 | if (!_PyArg_UnpackStack(args, nargs, "sum", |
| 600 | 1, 2, |
| 601 | &iterable, &start)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 602 | goto exit; |
| 603 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 604 | return_value = builtin_sum_impl(module, iterable, start); |
| 605 | |
| 606 | exit: |
| 607 | return return_value; |
| 608 | } |
| 609 | |
| 610 | PyDoc_STRVAR(builtin_isinstance__doc__, |
| 611 | "isinstance($module, obj, class_or_tuple, /)\n" |
| 612 | "--\n" |
| 613 | "\n" |
| 614 | "Return whether an object is an instance of a class or of a subclass thereof.\n" |
| 615 | "\n" |
| 616 | "A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n" |
| 617 | "check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n" |
| 618 | "or ...`` etc."); |
| 619 | |
| 620 | #define BUILTIN_ISINSTANCE_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 621 | {"isinstance", (PyCFunction)builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 622 | |
| 623 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 624 | builtin_isinstance_impl(PyObject *module, PyObject *obj, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 625 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 626 | |
| 627 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 628 | builtin_isinstance(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 629 | { |
| 630 | PyObject *return_value = NULL; |
| 631 | PyObject *obj; |
| 632 | PyObject *class_or_tuple; |
| 633 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 634 | if (!_PyArg_UnpackStack(args, nargs, "isinstance", |
| 635 | 2, 2, |
| 636 | &obj, &class_or_tuple)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 637 | goto exit; |
| 638 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 639 | return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
| 640 | |
| 641 | exit: |
| 642 | return return_value; |
| 643 | } |
| 644 | |
| 645 | PyDoc_STRVAR(builtin_issubclass__doc__, |
| 646 | "issubclass($module, cls, class_or_tuple, /)\n" |
| 647 | "--\n" |
| 648 | "\n" |
| 649 | "Return whether \'cls\' is a derived from another class or is the same class.\n" |
| 650 | "\n" |
| 651 | "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" |
| 652 | "check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" |
| 653 | "or ...`` etc."); |
| 654 | |
| 655 | #define BUILTIN_ISSUBCLASS_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 656 | {"issubclass", (PyCFunction)builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 657 | |
| 658 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 659 | builtin_issubclass_impl(PyObject *module, PyObject *cls, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 660 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 661 | |
| 662 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 663 | builtin_issubclass(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 664 | { |
| 665 | PyObject *return_value = NULL; |
| 666 | PyObject *cls; |
| 667 | PyObject *class_or_tuple; |
| 668 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 669 | if (!_PyArg_UnpackStack(args, nargs, "issubclass", |
| 670 | 2, 2, |
| 671 | &cls, &class_or_tuple)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 672 | goto exit; |
| 673 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 674 | return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
| 675 | |
| 676 | exit: |
| 677 | return return_value; |
| 678 | } |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 679 | /*[clinic end generated code: output=09752daa8cdd6ec7 input=a9049054013a1b77]*/ |