Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
Serhiy Storchaka | 18b250f | 2017-03-19 08:51:07 +0200 | [diff] [blame] | 5 | static PyObject * |
| 6 | long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase); |
| 7 | |
| 8 | static PyObject * |
| 9 | long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 10 | { |
| 11 | PyObject *return_value = NULL; |
| 12 | static const char * const _keywords[] = {"", "base", NULL}; |
| 13 | static _PyArg_Parser _parser = {"|OO:int", _keywords, 0}; |
| 14 | PyObject *x = NULL; |
| 15 | PyObject *obase = NULL; |
| 16 | |
| 17 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 18 | &x, &obase)) { |
| 19 | goto exit; |
| 20 | } |
| 21 | return_value = long_new_impl(type, x, obase); |
| 22 | |
| 23 | exit: |
| 24 | return return_value; |
| 25 | } |
| 26 | |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 27 | PyDoc_STRVAR(int___getnewargs____doc__, |
| 28 | "__getnewargs__($self, /)\n" |
| 29 | "--\n" |
| 30 | "\n"); |
| 31 | |
| 32 | #define INT___GETNEWARGS___METHODDEF \ |
| 33 | {"__getnewargs__", (PyCFunction)int___getnewargs__, METH_NOARGS, int___getnewargs____doc__}, |
| 34 | |
| 35 | static PyObject * |
| 36 | int___getnewargs___impl(PyObject *self); |
| 37 | |
| 38 | static PyObject * |
| 39 | int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 40 | { |
| 41 | return int___getnewargs___impl(self); |
| 42 | } |
| 43 | |
| 44 | PyDoc_STRVAR(int___format____doc__, |
| 45 | "__format__($self, format_spec, /)\n" |
| 46 | "--\n" |
| 47 | "\n"); |
| 48 | |
| 49 | #define INT___FORMAT___METHODDEF \ |
| 50 | {"__format__", (PyCFunction)int___format__, METH_O, int___format____doc__}, |
| 51 | |
| 52 | static PyObject * |
| 53 | int___format___impl(PyObject *self, PyObject *format_spec); |
| 54 | |
| 55 | static PyObject * |
| 56 | int___format__(PyObject *self, PyObject *arg) |
| 57 | { |
| 58 | PyObject *return_value = NULL; |
| 59 | PyObject *format_spec; |
| 60 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 61 | if (!PyUnicode_Check(arg)) { |
| 62 | _PyArg_BadArgument("__format__", "str", arg); |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 63 | goto exit; |
| 64 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 65 | if (PyUnicode_READY(arg) == -1) { |
| 66 | goto exit; |
| 67 | } |
| 68 | format_spec = arg; |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 69 | return_value = int___format___impl(self, format_spec); |
| 70 | |
| 71 | exit: |
| 72 | return return_value; |
| 73 | } |
| 74 | |
| 75 | PyDoc_STRVAR(int___sizeof____doc__, |
| 76 | "__sizeof__($self, /)\n" |
| 77 | "--\n" |
| 78 | "\n" |
| 79 | "Returns size in memory, in bytes."); |
| 80 | |
| 81 | #define INT___SIZEOF___METHODDEF \ |
| 82 | {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__}, |
| 83 | |
| 84 | static Py_ssize_t |
| 85 | int___sizeof___impl(PyObject *self); |
| 86 | |
| 87 | static PyObject * |
| 88 | int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 89 | { |
| 90 | PyObject *return_value = NULL; |
| 91 | Py_ssize_t _return_value; |
| 92 | |
| 93 | _return_value = int___sizeof___impl(self); |
| 94 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 95 | goto exit; |
| 96 | } |
| 97 | return_value = PyLong_FromSsize_t(_return_value); |
| 98 | |
| 99 | exit: |
| 100 | return return_value; |
| 101 | } |
| 102 | |
| 103 | PyDoc_STRVAR(int_bit_length__doc__, |
| 104 | "bit_length($self, /)\n" |
| 105 | "--\n" |
| 106 | "\n" |
| 107 | "Number of bits necessary to represent self in binary.\n" |
| 108 | "\n" |
| 109 | ">>> bin(37)\n" |
| 110 | "\'0b100101\'\n" |
| 111 | ">>> (37).bit_length()\n" |
| 112 | "6"); |
| 113 | |
| 114 | #define INT_BIT_LENGTH_METHODDEF \ |
| 115 | {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__}, |
| 116 | |
| 117 | static PyObject * |
| 118 | int_bit_length_impl(PyObject *self); |
| 119 | |
| 120 | static PyObject * |
| 121 | int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 122 | { |
| 123 | return int_bit_length_impl(self); |
| 124 | } |
| 125 | |
Lisa Roach | 5ac7043 | 2018-09-13 23:56:23 -0700 | [diff] [blame] | 126 | PyDoc_STRVAR(int_as_integer_ratio__doc__, |
| 127 | "as_integer_ratio($self, /)\n" |
| 128 | "--\n" |
| 129 | "\n" |
| 130 | "Return integer ratio.\n" |
| 131 | "\n" |
| 132 | "Return a pair of integers, whose ratio is exactly equal to the original int\n" |
| 133 | "and with a positive denominator.\n" |
| 134 | "\n" |
| 135 | ">>> (10).as_integer_ratio()\n" |
| 136 | "(10, 1)\n" |
| 137 | ">>> (-10).as_integer_ratio()\n" |
| 138 | "(-10, 1)\n" |
| 139 | ">>> (0).as_integer_ratio()\n" |
| 140 | "(0, 1)"); |
| 141 | |
| 142 | #define INT_AS_INTEGER_RATIO_METHODDEF \ |
| 143 | {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__}, |
| 144 | |
| 145 | static PyObject * |
| 146 | int_as_integer_ratio_impl(PyObject *self); |
| 147 | |
| 148 | static PyObject * |
| 149 | int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 150 | { |
| 151 | return int_as_integer_ratio_impl(self); |
| 152 | } |
| 153 | |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 154 | PyDoc_STRVAR(int_to_bytes__doc__, |
| 155 | "to_bytes($self, /, length, byteorder, *, signed=False)\n" |
| 156 | "--\n" |
| 157 | "\n" |
| 158 | "Return an array of bytes representing an integer.\n" |
| 159 | "\n" |
| 160 | " length\n" |
| 161 | " Length of bytes object to use. An OverflowError is raised if the\n" |
| 162 | " integer is not representable with the given number of bytes.\n" |
| 163 | " byteorder\n" |
| 164 | " The byte order used to represent the integer. If byteorder is \'big\',\n" |
| 165 | " the most significant byte is at the beginning of the byte array. If\n" |
| 166 | " byteorder is \'little\', the most significant byte is at the end of the\n" |
| 167 | " byte array. To request the native byte order of the host system, use\n" |
| 168 | " `sys.byteorder\' as the byte order value.\n" |
| 169 | " signed\n" |
| 170 | " Determines whether two\'s complement is used to represent the integer.\n" |
| 171 | " If signed is False and a negative integer is given, an OverflowError\n" |
| 172 | " is raised."); |
| 173 | |
| 174 | #define INT_TO_BYTES_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 175 | {"to_bytes", (PyCFunction)(void(*)(void))int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__}, |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 176 | |
| 177 | static PyObject * |
| 178 | int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, |
| 179 | int is_signed); |
| 180 | |
| 181 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 182 | int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 183 | { |
| 184 | PyObject *return_value = NULL; |
| 185 | static const char * const _keywords[] = {"length", "byteorder", "signed", NULL}; |
| 186 | static _PyArg_Parser _parser = {"nU|$p:to_bytes", _keywords, 0}; |
| 187 | Py_ssize_t length; |
| 188 | PyObject *byteorder; |
| 189 | int is_signed = 0; |
| 190 | |
| 191 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 192 | &length, &byteorder, &is_signed)) { |
| 193 | goto exit; |
| 194 | } |
| 195 | return_value = int_to_bytes_impl(self, length, byteorder, is_signed); |
| 196 | |
| 197 | exit: |
| 198 | return return_value; |
| 199 | } |
| 200 | |
| 201 | PyDoc_STRVAR(int_from_bytes__doc__, |
| 202 | "from_bytes($type, /, bytes, byteorder, *, signed=False)\n" |
| 203 | "--\n" |
| 204 | "\n" |
| 205 | "Return the integer represented by the given array of bytes.\n" |
| 206 | "\n" |
| 207 | " bytes\n" |
| 208 | " Holds the array of bytes to convert. The argument must either\n" |
| 209 | " support the buffer protocol or be an iterable object producing bytes.\n" |
| 210 | " Bytes and bytearray are examples of built-in objects that support the\n" |
| 211 | " buffer protocol.\n" |
| 212 | " byteorder\n" |
| 213 | " The byte order used to represent the integer. If byteorder is \'big\',\n" |
| 214 | " the most significant byte is at the beginning of the byte array. If\n" |
| 215 | " byteorder is \'little\', the most significant byte is at the end of the\n" |
| 216 | " byte array. To request the native byte order of the host system, use\n" |
| 217 | " `sys.byteorder\' as the byte order value.\n" |
| 218 | " signed\n" |
| 219 | " Indicates whether two\'s complement is used to represent the integer."); |
| 220 | |
| 221 | #define INT_FROM_BYTES_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 222 | {"from_bytes", (PyCFunction)(void(*)(void))int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__}, |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 223 | |
| 224 | static PyObject * |
| 225 | int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, |
| 226 | PyObject *byteorder, int is_signed); |
| 227 | |
| 228 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 229 | int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame] | 230 | { |
| 231 | PyObject *return_value = NULL; |
| 232 | static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL}; |
| 233 | static _PyArg_Parser _parser = {"OU|$p:from_bytes", _keywords, 0}; |
| 234 | PyObject *bytes_obj; |
| 235 | PyObject *byteorder; |
| 236 | int is_signed = 0; |
| 237 | |
| 238 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 239 | &bytes_obj, &byteorder, &is_signed)) { |
| 240 | goto exit; |
| 241 | } |
| 242 | return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed); |
| 243 | |
| 244 | exit: |
| 245 | return return_value; |
| 246 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 247 | /*[clinic end generated code: output=7436b5f4decdcf9d input=a9049054013a1b77]*/ |