| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | /*[clinic input]
 | 
					
						
							|  |  |  | preserve | 
					
						
							|  |  |  | [clinic start generated code]*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2023-08-31 23:42:34 +02:00
										 |  |  | #  include "pycore_gc.h"          // PyGC_Head
 | 
					
						
							|  |  |  | #  include "pycore_runtime.h"     // _Py_ID()
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2023-08-31 23:42:34 +02:00
										 |  |  | #include "pycore_abstract.h"      // _PyNumber_Index()
 | 
					
						
							| 
									
										
										
										
											2023-10-17 14:30:31 +02:00
										 |  |  | #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define NUM_KEYWORDS 1
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static struct { | 
					
						
							|  |  |  |         PyGC_Head _this_is_not_used; | 
					
						
							|  |  |  |         PyObject_VAR_HEAD | 
					
						
							|  |  |  |         PyObject *ob_item[NUM_KEYWORDS]; | 
					
						
							|  |  |  |     } _kwtuple = { | 
					
						
							|  |  |  |         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) | 
					
						
							|  |  |  |         .ob_item = { &_Py_ID(base), }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef NUM_KEYWORDS
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #else  // !Py_BUILD_CORE
 | 
					
						
							|  |  |  |     #  define KWTUPLE NULL
 | 
					
						
							|  |  |  |     #endif  // !Py_BUILD_CORE
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |     static const char * const _keywords[] = {"", "base", NULL}; | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |         .keywords = _keywords, | 
					
						
							|  |  |  |         .fname = "int", | 
					
						
							|  |  |  |         .kwtuple = KWTUPLE, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef KWTUPLE
 | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     PyObject *argsbuf[2]; | 
					
						
							|  |  |  |     PyObject * const *fastargs; | 
					
						
							|  |  |  |     Py_ssize_t nargs = PyTuple_GET_SIZE(args); | 
					
						
							|  |  |  |     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |     PyObject *x = NULL; | 
					
						
							|  |  |  |     PyObject *obase = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf); | 
					
						
							|  |  |  |     if (!fastargs) { | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     if (nargs < 1) { | 
					
						
							|  |  |  |         goto skip_optional_posonly; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     noptargs--; | 
					
						
							|  |  |  |     x = fastargs[0]; | 
					
						
							|  |  |  | skip_optional_posonly: | 
					
						
							|  |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_pos; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     obase = fastargs[1]; | 
					
						
							|  |  |  | skip_optional_pos: | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |     return_value = long_new_impl(type, x, obase); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | PyDoc_STRVAR(int___getnewargs____doc__, | 
					
						
							|  |  |  | "__getnewargs__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT___GETNEWARGS___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__getnewargs__", (PyCFunction)int___getnewargs__, METH_NOARGS, int___getnewargs____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___getnewargs___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return int___getnewargs___impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(int___format____doc__, | 
					
						
							|  |  |  | "__format__($self, format_spec, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							| 
									
										
										
										
											2022-10-04 00:28:02 +02:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "Convert to a string according to format_spec."); | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define INT___FORMAT___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__format__", (PyCFunction)int___format__, METH_O, int___format____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___format___impl(PyObject *self, PyObject *format_spec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___format__(PyObject *self, PyObject *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							|  |  |  |     PyObject *format_spec; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |     if (!PyUnicode_Check(arg)) { | 
					
						
							| 
									
										
										
										
											2019-08-29 16:49:08 +02:00
										 |  |  |         _PyArg_BadArgument("__format__", "argument", "str", arg); | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |     format_spec = arg; | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     return_value = int___format___impl(self, format_spec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 15:57:37 +03:00
										 |  |  | PyDoc_STRVAR(int___round____doc__, | 
					
						
							| 
									
										
										
										
											2024-06-07 11:03:28 +03:00
										 |  |  | "__round__($self, ndigits=None, /)\n" | 
					
						
							| 
									
										
										
										
											2020-07-20 15:57:37 +03:00
										 |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Rounding an Integral returns itself.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Rounding with an ndigits argument also returns an integer."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT___ROUND___METHODDEF    \
 | 
					
						
							| 
									
										
										
										
											2022-05-03 20:25:41 +02:00
										 |  |  |     {"__round__", _PyCFunction_CAST(int___round__), METH_FASTCALL, int___round____doc__}, | 
					
						
							| 
									
										
										
										
											2020-07-20 15:57:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___round___impl(PyObject *self, PyObject *o_ndigits); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2024-06-07 11:03:28 +03:00
										 |  |  |     PyObject *o_ndigits = Py_None; | 
					
						
							| 
									
										
										
										
											2020-07-20 15:57:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (nargs < 1) { | 
					
						
							|  |  |  |         goto skip_optional; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     o_ndigits = args[0]; | 
					
						
							|  |  |  | skip_optional: | 
					
						
							|  |  |  |     return_value = int___round___impl(self, o_ndigits); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | PyDoc_STRVAR(int___sizeof____doc__, | 
					
						
							|  |  |  | "__sizeof__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Returns size in memory, in bytes."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT___SIZEOF___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Py_ssize_t | 
					
						
							|  |  |  | int___sizeof___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							|  |  |  |     Py_ssize_t _return_value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _return_value = int___sizeof___impl(self); | 
					
						
							|  |  |  |     if ((_return_value == -1) && PyErr_Occurred()) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return_value = PyLong_FromSsize_t(_return_value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(int_bit_length__doc__, | 
					
						
							|  |  |  | "bit_length($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Number of bits necessary to represent self in binary.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | ">>> bin(37)\n" | 
					
						
							|  |  |  | "\'0b100101\'\n" | 
					
						
							|  |  |  | ">>> (37).bit_length()\n" | 
					
						
							|  |  |  | "6"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_BIT_LENGTH_METHODDEF    \
 | 
					
						
							|  |  |  |     {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_bit_length_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return int_bit_length_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 18:28:02 +02:00
										 |  |  | PyDoc_STRVAR(int_bit_count__doc__, | 
					
						
							|  |  |  | "bit_count($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Number of ones in the binary representation of the absolute value of self.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Also known as the population count.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | ">>> bin(13)\n" | 
					
						
							|  |  |  | "\'0b1101\'\n" | 
					
						
							|  |  |  | ">>> (13).bit_count()\n" | 
					
						
							|  |  |  | "3"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_BIT_COUNT_METHODDEF    \
 | 
					
						
							|  |  |  |     {"bit_count", (PyCFunction)int_bit_count, METH_NOARGS, int_bit_count__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_bit_count_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_bit_count(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return int_bit_count_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-13 23:56:23 -07:00
										 |  |  | PyDoc_STRVAR(int_as_integer_ratio__doc__, | 
					
						
							|  |  |  | "as_integer_ratio($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2023-02-27 22:11:28 +03:00
										 |  |  | "Return a pair of integers, whose ratio is equal to the original int.\n" | 
					
						
							| 
									
										
										
										
											2018-09-13 23:56:23 -07:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2023-02-27 22:11:28 +03:00
										 |  |  | "The ratio is in lowest terms and has a positive denominator.\n" | 
					
						
							| 
									
										
										
										
											2018-09-13 23:56:23 -07:00
										 |  |  | "\n" | 
					
						
							|  |  |  | ">>> (10).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(10, 1)\n" | 
					
						
							|  |  |  | ">>> (-10).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(-10, 1)\n" | 
					
						
							|  |  |  | ">>> (0).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(0, 1)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_AS_INTEGER_RATIO_METHODDEF    \
 | 
					
						
							|  |  |  |     {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_as_integer_ratio_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return int_as_integer_ratio_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | PyDoc_STRVAR(int_to_bytes__doc__, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  | "to_bytes($self, /, length=1, byteorder=\'big\', *, signed=False)\n" | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return an array of bytes representing an integer.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "  length\n" | 
					
						
							|  |  |  | "    Length of bytes object to use.  An OverflowError is raised if the\n" | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  | "    integer is not representable with the given number of bytes.  Default\n" | 
					
						
							|  |  |  | "    is length 1.\n" | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | "  byteorder\n" | 
					
						
							|  |  |  | "    The byte order used to represent the integer.  If byteorder is \'big\',\n" | 
					
						
							|  |  |  | "    the most significant byte is at the beginning of the byte array.  If\n" | 
					
						
							|  |  |  | "    byteorder is \'little\', the most significant byte is at the end of the\n" | 
					
						
							|  |  |  | "    byte array.  To request the native byte order of the host system, use\n" | 
					
						
							| 
									
										
										
										
											2024-04-18 11:01:58 +02:00
										 |  |  | "    sys.byteorder as the byte order value.  Default is to use \'big\'.\n" | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | "  signed\n" | 
					
						
							|  |  |  | "    Determines whether two\'s complement is used to represent the integer.\n" | 
					
						
							|  |  |  | "    If signed is False and a negative integer is given, an OverflowError\n" | 
					
						
							|  |  |  | "    is raised."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_TO_BYTES_METHODDEF    \
 | 
					
						
							| 
									
										
										
										
											2022-05-03 20:25:41 +02:00
										 |  |  |     {"to_bytes", _PyCFunction_CAST(int_to_bytes), METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__}, | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, | 
					
						
							|  |  |  |                   int is_signed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2017-12-15 13:11:11 +02:00
										 |  |  | int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define NUM_KEYWORDS 3
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static struct { | 
					
						
							|  |  |  |         PyGC_Head _this_is_not_used; | 
					
						
							|  |  |  |         PyObject_VAR_HEAD | 
					
						
							|  |  |  |         PyObject *ob_item[NUM_KEYWORDS]; | 
					
						
							|  |  |  |     } _kwtuple = { | 
					
						
							|  |  |  |         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) | 
					
						
							|  |  |  |         .ob_item = { &_Py_ID(length), &_Py_ID(byteorder), &_Py_ID(signed), }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef NUM_KEYWORDS
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #else  // !Py_BUILD_CORE
 | 
					
						
							|  |  |  |     #  define KWTUPLE NULL
 | 
					
						
							|  |  |  |     #endif  // !Py_BUILD_CORE
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     static const char * const _keywords[] = {"length", "byteorder", "signed", NULL}; | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |         .keywords = _keywords, | 
					
						
							|  |  |  |         .fname = "to_bytes", | 
					
						
							|  |  |  |         .kwtuple = KWTUPLE, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef KWTUPLE
 | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     PyObject *argsbuf[3]; | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; | 
					
						
							|  |  |  |     Py_ssize_t length = 1; | 
					
						
							|  |  |  |     PyObject *byteorder = NULL; | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     int is_signed = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     if (!args) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_pos; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (args[0]) { | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Py_ssize_t ival = -1; | 
					
						
							|  |  |  |             PyObject *iobj = _PyNumber_Index(args[0]); | 
					
						
							|  |  |  |             if (iobj != NULL) { | 
					
						
							|  |  |  |                 ival = PyLong_AsSsize_t(iobj); | 
					
						
							|  |  |  |                 Py_DECREF(iobj); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (ival == -1 && PyErr_Occurred()) { | 
					
						
							|  |  |  |                 goto exit; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             length = ival; | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |         if (!--noptargs) { | 
					
						
							|  |  |  |             goto skip_optional_pos; | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     if (args[1]) { | 
					
						
							|  |  |  |         if (!PyUnicode_Check(args[1])) { | 
					
						
							|  |  |  |             _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]); | 
					
						
							|  |  |  |             goto exit; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         byteorder = args[1]; | 
					
						
							|  |  |  |         if (!--noptargs) { | 
					
						
							|  |  |  |             goto skip_optional_pos; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  | skip_optional_pos: | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_kwonly; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     is_signed = PyObject_IsTrue(args[2]); | 
					
						
							|  |  |  |     if (is_signed < 0) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | skip_optional_kwonly: | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     return_value = int_to_bytes_impl(self, length, byteorder, is_signed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(int_from_bytes__doc__, | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  | "from_bytes($type, /, bytes, byteorder=\'big\', *, signed=False)\n" | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return the integer represented by the given array of bytes.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "  bytes\n" | 
					
						
							|  |  |  | "    Holds the array of bytes to convert.  The argument must either\n" | 
					
						
							|  |  |  | "    support the buffer protocol or be an iterable object producing bytes.\n" | 
					
						
							|  |  |  | "    Bytes and bytearray are examples of built-in objects that support the\n" | 
					
						
							|  |  |  | "    buffer protocol.\n" | 
					
						
							|  |  |  | "  byteorder\n" | 
					
						
							|  |  |  | "    The byte order used to represent the integer.  If byteorder is \'big\',\n" | 
					
						
							|  |  |  | "    the most significant byte is at the beginning of the byte array.  If\n" | 
					
						
							|  |  |  | "    byteorder is \'little\', the most significant byte is at the end of the\n" | 
					
						
							|  |  |  | "    byte array.  To request the native byte order of the host system, use\n" | 
					
						
							| 
									
										
										
										
											2024-04-18 11:01:58 +02:00
										 |  |  | "    sys.byteorder as the byte order value.  Default is to use \'big\'.\n" | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | "  signed\n" | 
					
						
							|  |  |  | "    Indicates whether two\'s complement is used to represent the integer."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_FROM_BYTES_METHODDEF    \
 | 
					
						
							| 
									
										
										
										
											2022-05-03 20:25:41 +02:00
										 |  |  |     {"from_bytes", _PyCFunction_CAST(int_from_bytes), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__}, | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, | 
					
						
							|  |  |  |                     PyObject *byteorder, int is_signed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2017-12-15 13:11:11 +02:00
										 |  |  | int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define NUM_KEYWORDS 3
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static struct { | 
					
						
							|  |  |  |         PyGC_Head _this_is_not_used; | 
					
						
							|  |  |  |         PyObject_VAR_HEAD | 
					
						
							|  |  |  |         PyObject *ob_item[NUM_KEYWORDS]; | 
					
						
							|  |  |  |     } _kwtuple = { | 
					
						
							|  |  |  |         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) | 
					
						
							|  |  |  |         .ob_item = { &_Py_ID(bytes), &_Py_ID(byteorder), &_Py_ID(signed), }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef NUM_KEYWORDS
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #else  // !Py_BUILD_CORE
 | 
					
						
							|  |  |  |     #  define KWTUPLE NULL
 | 
					
						
							|  |  |  |     #endif  // !Py_BUILD_CORE
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL}; | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |         .keywords = _keywords, | 
					
						
							|  |  |  |         .fname = "from_bytes", | 
					
						
							|  |  |  |         .kwtuple = KWTUPLE, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef KWTUPLE
 | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     PyObject *argsbuf[3]; | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     PyObject *bytes_obj; | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     PyObject *byteorder = NULL; | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     int is_signed = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     if (!args) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     bytes_obj = args[0]; | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_pos; | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  |     if (args[1]) { | 
					
						
							|  |  |  |         if (!PyUnicode_Check(args[1])) { | 
					
						
							|  |  |  |             _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]); | 
					
						
							|  |  |  |             goto exit; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         byteorder = args[1]; | 
					
						
							|  |  |  |         if (!--noptargs) { | 
					
						
							|  |  |  |             goto skip_optional_pos; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-15 19:55:24 -07:00
										 |  |  | skip_optional_pos: | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_kwonly; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     is_signed = PyObject_IsTrue(args[2]); | 
					
						
							|  |  |  |     if (is_signed < 0) { | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-14 10:32:22 +02:00
										 |  |  | skip_optional_kwonly: | 
					
						
							| 
									
										
										
										
											2017-02-01 23:12:20 +02:00
										 |  |  |     return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-12-23 20:30:27 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(int_is_integer__doc__, | 
					
						
							|  |  |  | "is_integer($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Returns True. Exists for duck type compatibility with float.is_integer."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INT_IS_INTEGER_METHODDEF    \
 | 
					
						
							|  |  |  |     {"is_integer", (PyCFunction)int_is_integer, METH_NOARGS, int_is_integer__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_is_integer_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return int_is_integer_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-06-07 11:03:28 +03:00
										 |  |  | /*[clinic end generated code: output=a53f5ba9a6c16737 input=a9049054013a1b77]*/ |