Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : static PyObject *
6 : long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
7 :
8 : static PyObject *
9 4252410 : long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
10 : {
11 4252410 : PyObject *return_value = NULL;
12 : static const char * const _keywords[] = {"", "base", NULL};
13 : static _PyArg_Parser _parser = {NULL, _keywords, "int", 0};
14 : PyObject *argsbuf[2];
15 : PyObject * const *fastargs;
16 4252410 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
17 4252410 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
18 4252410 : PyObject *x = NULL;
19 4252410 : PyObject *obase = NULL;
20 :
21 4252410 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
22 4252410 : if (!fastargs) {
23 5 : goto exit;
24 : }
25 4252410 : if (nargs < 1) {
26 23258 : goto skip_optional_posonly;
27 : }
28 4229150 : noptargs--;
29 4229150 : x = fastargs[0];
30 4252410 : skip_optional_posonly:
31 4252410 : if (!noptargs) {
32 3318990 : goto skip_optional_pos;
33 : }
34 933421 : obase = fastargs[1];
35 4252410 : skip_optional_pos:
36 4252410 : return_value = long_new_impl(type, x, obase);
37 :
38 4252410 : exit:
39 4252410 : return return_value;
40 : }
41 :
42 : PyDoc_STRVAR(int___getnewargs____doc__,
43 : "__getnewargs__($self, /)\n"
44 : "--\n"
45 : "\n");
46 :
47 : #define INT___GETNEWARGS___METHODDEF \
48 : {"__getnewargs__", (PyCFunction)int___getnewargs__, METH_NOARGS, int___getnewargs____doc__},
49 :
50 : static PyObject *
51 : int___getnewargs___impl(PyObject *self);
52 :
53 : static PyObject *
54 102 : int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
55 : {
56 102 : return int___getnewargs___impl(self);
57 : }
58 :
59 : PyDoc_STRVAR(int___format____doc__,
60 : "__format__($self, format_spec, /)\n"
61 : "--\n"
62 : "\n");
63 :
64 : #define INT___FORMAT___METHODDEF \
65 : {"__format__", (PyCFunction)int___format__, METH_O, int___format____doc__},
66 :
67 : static PyObject *
68 : int___format___impl(PyObject *self, PyObject *format_spec);
69 :
70 : static PyObject *
71 3643250 : int___format__(PyObject *self, PyObject *arg)
72 : {
73 3643250 : PyObject *return_value = NULL;
74 : PyObject *format_spec;
75 :
76 3643250 : if (!PyUnicode_Check(arg)) {
77 2 : _PyArg_BadArgument("__format__", "argument", "str", arg);
78 2 : goto exit;
79 : }
80 3643250 : if (PyUnicode_READY(arg) == -1) {
81 0 : goto exit;
82 : }
83 3643250 : format_spec = arg;
84 3643250 : return_value = int___format___impl(self, format_spec);
85 :
86 3643250 : exit:
87 3643250 : return return_value;
88 : }
89 :
90 : PyDoc_STRVAR(int___round____doc__,
91 : "__round__($self, ndigits=<unrepresentable>, /)\n"
92 : "--\n"
93 : "\n"
94 : "Rounding an Integral returns itself.\n"
95 : "\n"
96 : "Rounding with an ndigits argument also returns an integer.");
97 :
98 : #define INT___ROUND___METHODDEF \
99 : {"__round__", _PyCFunction_CAST(int___round__), METH_FASTCALL, int___round____doc__},
100 :
101 : static PyObject *
102 : int___round___impl(PyObject *self, PyObject *o_ndigits);
103 :
104 : static PyObject *
105 1855 : int___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
106 : {
107 1855 : PyObject *return_value = NULL;
108 1855 : PyObject *o_ndigits = NULL;
109 :
110 1855 : if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
111 0 : goto exit;
112 : }
113 1855 : if (nargs < 1) {
114 168 : goto skip_optional;
115 : }
116 1687 : o_ndigits = args[0];
117 1855 : skip_optional:
118 1855 : return_value = int___round___impl(self, o_ndigits);
119 :
120 1855 : exit:
121 1855 : return return_value;
122 : }
123 :
124 : PyDoc_STRVAR(int___sizeof____doc__,
125 : "__sizeof__($self, /)\n"
126 : "--\n"
127 : "\n"
128 : "Returns size in memory, in bytes.");
129 :
130 : #define INT___SIZEOF___METHODDEF \
131 : {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__},
132 :
133 : static Py_ssize_t
134 : int___sizeof___impl(PyObject *self);
135 :
136 : static PyObject *
137 12 : int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
138 : {
139 12 : PyObject *return_value = NULL;
140 : Py_ssize_t _return_value;
141 :
142 12 : _return_value = int___sizeof___impl(self);
143 12 : if ((_return_value == -1) && PyErr_Occurred()) {
144 0 : goto exit;
145 : }
146 12 : return_value = PyLong_FromSsize_t(_return_value);
147 :
148 12 : exit:
149 12 : return return_value;
150 : }
151 :
152 : PyDoc_STRVAR(int_bit_length__doc__,
153 : "bit_length($self, /)\n"
154 : "--\n"
155 : "\n"
156 : "Number of bits necessary to represent self in binary.\n"
157 : "\n"
158 : ">>> bin(37)\n"
159 : "\'0b100101\'\n"
160 : ">>> (37).bit_length()\n"
161 : "6");
162 :
163 : #define INT_BIT_LENGTH_METHODDEF \
164 : {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__},
165 :
166 : static PyObject *
167 : int_bit_length_impl(PyObject *self);
168 :
169 : static PyObject *
170 4923740 : int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored))
171 : {
172 4923740 : return int_bit_length_impl(self);
173 : }
174 :
175 : PyDoc_STRVAR(int_bit_count__doc__,
176 : "bit_count($self, /)\n"
177 : "--\n"
178 : "\n"
179 : "Number of ones in the binary representation of the absolute value of self.\n"
180 : "\n"
181 : "Also known as the population count.\n"
182 : "\n"
183 : ">>> bin(13)\n"
184 : "\'0b1101\'\n"
185 : ">>> (13).bit_count()\n"
186 : "3");
187 :
188 : #define INT_BIT_COUNT_METHODDEF \
189 : {"bit_count", (PyCFunction)int_bit_count, METH_NOARGS, int_bit_count__doc__},
190 :
191 : static PyObject *
192 : int_bit_count_impl(PyObject *self);
193 :
194 : static PyObject *
195 2052 : int_bit_count(PyObject *self, PyObject *Py_UNUSED(ignored))
196 : {
197 2052 : return int_bit_count_impl(self);
198 : }
199 :
200 : PyDoc_STRVAR(int_as_integer_ratio__doc__,
201 : "as_integer_ratio($self, /)\n"
202 : "--\n"
203 : "\n"
204 : "Return integer ratio.\n"
205 : "\n"
206 : "Return a pair of integers, whose ratio is exactly equal to the original int\n"
207 : "and with a positive denominator.\n"
208 : "\n"
209 : ">>> (10).as_integer_ratio()\n"
210 : "(10, 1)\n"
211 : ">>> (-10).as_integer_ratio()\n"
212 : "(-10, 1)\n"
213 : ">>> (0).as_integer_ratio()\n"
214 : "(0, 1)");
215 :
216 : #define INT_AS_INTEGER_RATIO_METHODDEF \
217 : {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__},
218 :
219 : static PyObject *
220 : int_as_integer_ratio_impl(PyObject *self);
221 :
222 : static PyObject *
223 79995 : int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
224 : {
225 79995 : return int_as_integer_ratio_impl(self);
226 : }
227 :
228 : PyDoc_STRVAR(int_to_bytes__doc__,
229 : "to_bytes($self, /, length=1, byteorder=\'big\', *, signed=False)\n"
230 : "--\n"
231 : "\n"
232 : "Return an array of bytes representing an integer.\n"
233 : "\n"
234 : " length\n"
235 : " Length of bytes object to use. An OverflowError is raised if the\n"
236 : " integer is not representable with the given number of bytes. Default\n"
237 : " is length 1.\n"
238 : " byteorder\n"
239 : " The byte order used to represent the integer. If byteorder is \'big\',\n"
240 : " the most significant byte is at the beginning of the byte array. If\n"
241 : " byteorder is \'little\', the most significant byte is at the end of the\n"
242 : " byte array. To request the native byte order of the host system, use\n"
243 : " `sys.byteorder\' as the byte order value. Default is to use \'big\'.\n"
244 : " signed\n"
245 : " Determines whether two\'s complement is used to represent the integer.\n"
246 : " If signed is False and a negative integer is given, an OverflowError\n"
247 : " is raised.");
248 :
249 : #define INT_TO_BYTES_METHODDEF \
250 : {"to_bytes", _PyCFunction_CAST(int_to_bytes), METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__},
251 :
252 : static PyObject *
253 : int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
254 : int is_signed);
255 :
256 : static PyObject *
257 230849 : int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
258 : {
259 230849 : PyObject *return_value = NULL;
260 : static const char * const _keywords[] = {"length", "byteorder", "signed", NULL};
261 : static _PyArg_Parser _parser = {NULL, _keywords, "to_bytes", 0};
262 : PyObject *argsbuf[3];
263 230849 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
264 230849 : Py_ssize_t length = 1;
265 230849 : PyObject *byteorder = NULL;
266 230849 : int is_signed = 0;
267 :
268 230849 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
269 230849 : if (!args) {
270 0 : goto exit;
271 : }
272 230849 : if (!noptargs) {
273 5 : goto skip_optional_pos;
274 : }
275 230844 : if (args[0]) {
276 : {
277 230844 : Py_ssize_t ival = -1;
278 230844 : PyObject *iobj = _PyNumber_Index(args[0]);
279 230844 : if (iobj != NULL) {
280 230844 : ival = PyLong_AsSsize_t(iobj);
281 230844 : Py_DECREF(iobj);
282 : }
283 230844 : if (ival == -1 && PyErr_Occurred()) {
284 0 : goto exit;
285 : }
286 230844 : length = ival;
287 : }
288 230844 : if (!--noptargs) {
289 700 : goto skip_optional_pos;
290 : }
291 : }
292 230144 : if (args[1]) {
293 229882 : if (!PyUnicode_Check(args[1])) {
294 0 : _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]);
295 0 : goto exit;
296 : }
297 229882 : if (PyUnicode_READY(args[1]) == -1) {
298 0 : goto exit;
299 : }
300 229882 : byteorder = args[1];
301 229882 : if (!--noptargs) {
302 226346 : goto skip_optional_pos;
303 : }
304 : }
305 3798 : skip_optional_pos:
306 230849 : if (!noptargs) {
307 227051 : goto skip_optional_kwonly;
308 : }
309 3798 : is_signed = PyObject_IsTrue(args[2]);
310 3798 : if (is_signed < 0) {
311 0 : goto exit;
312 : }
313 3798 : skip_optional_kwonly:
314 230849 : return_value = int_to_bytes_impl(self, length, byteorder, is_signed);
315 :
316 230849 : exit:
317 230849 : return return_value;
318 : }
319 :
320 : PyDoc_STRVAR(int_from_bytes__doc__,
321 : "from_bytes($type, /, bytes, byteorder=\'big\', *, signed=False)\n"
322 : "--\n"
323 : "\n"
324 : "Return the integer represented by the given array of bytes.\n"
325 : "\n"
326 : " bytes\n"
327 : " Holds the array of bytes to convert. The argument must either\n"
328 : " support the buffer protocol or be an iterable object producing bytes.\n"
329 : " Bytes and bytearray are examples of built-in objects that support the\n"
330 : " buffer protocol.\n"
331 : " byteorder\n"
332 : " The byte order used to represent the integer. If byteorder is \'big\',\n"
333 : " the most significant byte is at the beginning of the byte array. If\n"
334 : " byteorder is \'little\', the most significant byte is at the end of the\n"
335 : " byte array. To request the native byte order of the host system, use\n"
336 : " `sys.byteorder\' as the byte order value. Default is to use \'big\'.\n"
337 : " signed\n"
338 : " Indicates whether two\'s complement is used to represent the integer.");
339 :
340 : #define INT_FROM_BYTES_METHODDEF \
341 : {"from_bytes", _PyCFunction_CAST(int_from_bytes), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__},
342 :
343 : static PyObject *
344 : int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
345 : PyObject *byteorder, int is_signed);
346 :
347 : static PyObject *
348 820202 : int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
349 : {
350 820202 : PyObject *return_value = NULL;
351 : static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL};
352 : static _PyArg_Parser _parser = {NULL, _keywords, "from_bytes", 0};
353 : PyObject *argsbuf[3];
354 820202 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
355 : PyObject *bytes_obj;
356 820202 : PyObject *byteorder = NULL;
357 820202 : int is_signed = 0;
358 :
359 820202 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
360 820202 : if (!args) {
361 3 : goto exit;
362 : }
363 820199 : bytes_obj = args[0];
364 820199 : if (!noptargs) {
365 165621 : goto skip_optional_pos;
366 : }
367 654578 : if (args[1]) {
368 654316 : if (!PyUnicode_Check(args[1])) {
369 0 : _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]);
370 0 : goto exit;
371 : }
372 654316 : if (PyUnicode_READY(args[1]) == -1) {
373 0 : goto exit;
374 : }
375 654316 : byteorder = args[1];
376 654316 : if (!--noptargs) {
377 651847 : goto skip_optional_pos;
378 : }
379 : }
380 2731 : skip_optional_pos:
381 820199 : if (!noptargs) {
382 817468 : goto skip_optional_kwonly;
383 : }
384 2731 : is_signed = PyObject_IsTrue(args[2]);
385 2731 : if (is_signed < 0) {
386 0 : goto exit;
387 : }
388 2731 : skip_optional_kwonly:
389 820199 : return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);
390 :
391 820202 : exit:
392 820202 : return return_value;
393 : }
394 : /*[clinic end generated code: output=899e57c41861a8e9 input=a9049054013a1b77]*/
|