Serhiy Storchaka | 495e880 | 2017-02-01 23:12:20 +0200 | [diff] [blame^] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(int___getnewargs____doc__, |
| 6 | "__getnewargs__($self, /)\n" |
| 7 | "--\n" |
| 8 | "\n"); |
| 9 | |
| 10 | #define INT___GETNEWARGS___METHODDEF \ |
| 11 | {"__getnewargs__", (PyCFunction)int___getnewargs__, METH_NOARGS, int___getnewargs____doc__}, |
| 12 | |
| 13 | static PyObject * |
| 14 | int___getnewargs___impl(PyObject *self); |
| 15 | |
| 16 | static PyObject * |
| 17 | int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 18 | { |
| 19 | return int___getnewargs___impl(self); |
| 20 | } |
| 21 | |
| 22 | PyDoc_STRVAR(int___format____doc__, |
| 23 | "__format__($self, format_spec, /)\n" |
| 24 | "--\n" |
| 25 | "\n"); |
| 26 | |
| 27 | #define INT___FORMAT___METHODDEF \ |
| 28 | {"__format__", (PyCFunction)int___format__, METH_O, int___format____doc__}, |
| 29 | |
| 30 | static PyObject * |
| 31 | int___format___impl(PyObject *self, PyObject *format_spec); |
| 32 | |
| 33 | static PyObject * |
| 34 | int___format__(PyObject *self, PyObject *arg) |
| 35 | { |
| 36 | PyObject *return_value = NULL; |
| 37 | PyObject *format_spec; |
| 38 | |
| 39 | if (!PyArg_Parse(arg, "U:__format__", &format_spec)) { |
| 40 | goto exit; |
| 41 | } |
| 42 | return_value = int___format___impl(self, format_spec); |
| 43 | |
| 44 | exit: |
| 45 | return return_value; |
| 46 | } |
| 47 | |
| 48 | PyDoc_STRVAR(int___sizeof____doc__, |
| 49 | "__sizeof__($self, /)\n" |
| 50 | "--\n" |
| 51 | "\n" |
| 52 | "Returns size in memory, in bytes."); |
| 53 | |
| 54 | #define INT___SIZEOF___METHODDEF \ |
| 55 | {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__}, |
| 56 | |
| 57 | static Py_ssize_t |
| 58 | int___sizeof___impl(PyObject *self); |
| 59 | |
| 60 | static PyObject * |
| 61 | int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 62 | { |
| 63 | PyObject *return_value = NULL; |
| 64 | Py_ssize_t _return_value; |
| 65 | |
| 66 | _return_value = int___sizeof___impl(self); |
| 67 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 68 | goto exit; |
| 69 | } |
| 70 | return_value = PyLong_FromSsize_t(_return_value); |
| 71 | |
| 72 | exit: |
| 73 | return return_value; |
| 74 | } |
| 75 | |
| 76 | PyDoc_STRVAR(int_bit_length__doc__, |
| 77 | "bit_length($self, /)\n" |
| 78 | "--\n" |
| 79 | "\n" |
| 80 | "Number of bits necessary to represent self in binary.\n" |
| 81 | "\n" |
| 82 | ">>> bin(37)\n" |
| 83 | "\'0b100101\'\n" |
| 84 | ">>> (37).bit_length()\n" |
| 85 | "6"); |
| 86 | |
| 87 | #define INT_BIT_LENGTH_METHODDEF \ |
| 88 | {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__}, |
| 89 | |
| 90 | static PyObject * |
| 91 | int_bit_length_impl(PyObject *self); |
| 92 | |
| 93 | static PyObject * |
| 94 | int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 95 | { |
| 96 | return int_bit_length_impl(self); |
| 97 | } |
| 98 | |
| 99 | PyDoc_STRVAR(int_to_bytes__doc__, |
| 100 | "to_bytes($self, /, length, byteorder, *, signed=False)\n" |
| 101 | "--\n" |
| 102 | "\n" |
| 103 | "Return an array of bytes representing an integer.\n" |
| 104 | "\n" |
| 105 | " length\n" |
| 106 | " Length of bytes object to use. An OverflowError is raised if the\n" |
| 107 | " integer is not representable with the given number of bytes.\n" |
| 108 | " byteorder\n" |
| 109 | " The byte order used to represent the integer. If byteorder is \'big\',\n" |
| 110 | " the most significant byte is at the beginning of the byte array. If\n" |
| 111 | " byteorder is \'little\', the most significant byte is at the end of the\n" |
| 112 | " byte array. To request the native byte order of the host system, use\n" |
| 113 | " `sys.byteorder\' as the byte order value.\n" |
| 114 | " signed\n" |
| 115 | " Determines whether two\'s complement is used to represent the integer.\n" |
| 116 | " If signed is False and a negative integer is given, an OverflowError\n" |
| 117 | " is raised."); |
| 118 | |
| 119 | #define INT_TO_BYTES_METHODDEF \ |
| 120 | {"to_bytes", (PyCFunction)int_to_bytes, METH_FASTCALL, int_to_bytes__doc__}, |
| 121 | |
| 122 | static PyObject * |
| 123 | int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, |
| 124 | int is_signed); |
| 125 | |
| 126 | static PyObject * |
| 127 | int_to_bytes(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
| 128 | { |
| 129 | PyObject *return_value = NULL; |
| 130 | static const char * const _keywords[] = {"length", "byteorder", "signed", NULL}; |
| 131 | static _PyArg_Parser _parser = {"nU|$p:to_bytes", _keywords, 0}; |
| 132 | Py_ssize_t length; |
| 133 | PyObject *byteorder; |
| 134 | int is_signed = 0; |
| 135 | |
| 136 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 137 | &length, &byteorder, &is_signed)) { |
| 138 | goto exit; |
| 139 | } |
| 140 | return_value = int_to_bytes_impl(self, length, byteorder, is_signed); |
| 141 | |
| 142 | exit: |
| 143 | return return_value; |
| 144 | } |
| 145 | |
| 146 | PyDoc_STRVAR(int_from_bytes__doc__, |
| 147 | "from_bytes($type, /, bytes, byteorder, *, signed=False)\n" |
| 148 | "--\n" |
| 149 | "\n" |
| 150 | "Return the integer represented by the given array of bytes.\n" |
| 151 | "\n" |
| 152 | " bytes\n" |
| 153 | " Holds the array of bytes to convert. The argument must either\n" |
| 154 | " support the buffer protocol or be an iterable object producing bytes.\n" |
| 155 | " Bytes and bytearray are examples of built-in objects that support the\n" |
| 156 | " buffer protocol.\n" |
| 157 | " byteorder\n" |
| 158 | " The byte order used to represent the integer. If byteorder is \'big\',\n" |
| 159 | " the most significant byte is at the beginning of the byte array. If\n" |
| 160 | " byteorder is \'little\', the most significant byte is at the end of the\n" |
| 161 | " byte array. To request the native byte order of the host system, use\n" |
| 162 | " `sys.byteorder\' as the byte order value.\n" |
| 163 | " signed\n" |
| 164 | " Indicates whether two\'s complement is used to represent the integer."); |
| 165 | |
| 166 | #define INT_FROM_BYTES_METHODDEF \ |
| 167 | {"from_bytes", (PyCFunction)int_from_bytes, METH_FASTCALL|METH_CLASS, int_from_bytes__doc__}, |
| 168 | |
| 169 | static PyObject * |
| 170 | int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, |
| 171 | PyObject *byteorder, int is_signed); |
| 172 | |
| 173 | static PyObject * |
| 174 | int_from_bytes(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
| 175 | { |
| 176 | PyObject *return_value = NULL; |
| 177 | static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL}; |
| 178 | static _PyArg_Parser _parser = {"OU|$p:from_bytes", _keywords, 0}; |
| 179 | PyObject *bytes_obj; |
| 180 | PyObject *byteorder; |
| 181 | int is_signed = 0; |
| 182 | |
| 183 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 184 | &bytes_obj, &byteorder, &is_signed)) { |
| 185 | goto exit; |
| 186 | } |
| 187 | return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed); |
| 188 | |
| 189 | exit: |
| 190 | return return_value; |
| 191 | } |
| 192 | /*[clinic end generated code: output=a9bae2fd016e7b85 input=a9049054013a1b77]*/ |