/src/Python-3.8.3/Objects/clinic/longobject.c.h
Line  | Count  | Source  | 
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  |  | long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)  | 
10  | 463  | { | 
11  | 463  |     PyObject *return_value = NULL;  | 
12  | 463  |     static const char * const _keywords[] = {"", "base", NULL}; | 
13  | 463  |     static _PyArg_Parser _parser = {NULL, _keywords, "int", 0}; | 
14  | 463  |     PyObject *argsbuf[2];  | 
15  | 463  |     PyObject * const *fastargs;  | 
16  | 463  |     Py_ssize_t nargs = PyTuple_GET_SIZE(args);  | 
17  | 463  |     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;  | 
18  | 463  |     PyObject *x = NULL;  | 
19  | 463  |     PyObject *obase = NULL;  | 
20  |  |  | 
21  | 463  |     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);  | 
22  | 463  |     if (!fastargs) { | 
23  | 0  |         goto exit;  | 
24  | 0  |     }  | 
25  | 463  |     if (nargs < 1) { | 
26  | 0  |         goto skip_optional_posonly;  | 
27  | 0  |     }  | 
28  | 463  |     noptargs--;  | 
29  | 463  |     x = fastargs[0];  | 
30  | 463  | skip_optional_posonly:  | 
31  | 463  |     if (!noptargs) { | 
32  | 359  |         goto skip_optional_pos;  | 
33  | 359  |     }  | 
34  | 104  |     obase = fastargs[1];  | 
35  | 463  | skip_optional_pos:  | 
36  | 463  |     return_value = long_new_impl(type, x, obase);  | 
37  |  |  | 
38  | 463  | exit:  | 
39  | 463  |     return return_value;  | 
40  | 463  | }  | 
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  |  | int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))  | 
55  | 0  | { | 
56  | 0  |     return int___getnewargs___impl(self);  | 
57  | 0  | }  | 
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  |  | int___format__(PyObject *self, PyObject *arg)  | 
72  | 0  | { | 
73  | 0  |     PyObject *return_value = NULL;  | 
74  | 0  |     PyObject *format_spec;  | 
75  |  | 
  | 
76  | 0  |     if (!PyUnicode_Check(arg)) { | 
77  | 0  |         _PyArg_BadArgument("__format__", "argument", "str", arg); | 
78  | 0  |         goto exit;  | 
79  | 0  |     }  | 
80  | 0  |     if (PyUnicode_READY(arg) == -1) { | 
81  | 0  |         goto exit;  | 
82  | 0  |     }  | 
83  | 0  |     format_spec = arg;  | 
84  | 0  |     return_value = int___format___impl(self, format_spec);  | 
85  |  | 
  | 
86  | 0  | exit:  | 
87  | 0  |     return return_value;  | 
88  | 0  | }  | 
89  |  |  | 
90  |  | PyDoc_STRVAR(int___sizeof____doc__,  | 
91  |  | "__sizeof__($self, /)\n"  | 
92  |  | "--\n"  | 
93  |  | "\n"  | 
94  |  | "Returns size in memory, in bytes.");  | 
95  |  |  | 
96  |  | #define INT___SIZEOF___METHODDEF    \  | 
97  |  |     {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__}, | 
98  |  |  | 
99  |  | static Py_ssize_t  | 
100  |  | int___sizeof___impl(PyObject *self);  | 
101  |  |  | 
102  |  | static PyObject *  | 
103  |  | int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))  | 
104  | 0  | { | 
105  | 0  |     PyObject *return_value = NULL;  | 
106  | 0  |     Py_ssize_t _return_value;  | 
107  |  | 
  | 
108  | 0  |     _return_value = int___sizeof___impl(self);  | 
109  | 0  |     if ((_return_value == -1) && PyErr_Occurred()) { | 
110  | 0  |         goto exit;  | 
111  | 0  |     }  | 
112  | 0  |     return_value = PyLong_FromSsize_t(_return_value);  | 
113  |  | 
  | 
114  | 0  | exit:  | 
115  | 0  |     return return_value;  | 
116  | 0  | }  | 
117  |  |  | 
118  |  | PyDoc_STRVAR(int_bit_length__doc__,  | 
119  |  | "bit_length($self, /)\n"  | 
120  |  | "--\n"  | 
121  |  | "\n"  | 
122  |  | "Number of bits necessary to represent self in binary.\n"  | 
123  |  | "\n"  | 
124  |  | ">>> bin(37)\n"  | 
125  |  | "\'0b100101\'\n"  | 
126  |  | ">>> (37).bit_length()\n"  | 
127  |  | "6");  | 
128  |  |  | 
129  |  | #define INT_BIT_LENGTH_METHODDEF    \  | 
130  |  |     {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__}, | 
131  |  |  | 
132  |  | static PyObject *  | 
133  |  | int_bit_length_impl(PyObject *self);  | 
134  |  |  | 
135  |  | static PyObject *  | 
136  |  | int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored))  | 
137  | 0  | { | 
138  | 0  |     return int_bit_length_impl(self);  | 
139  | 0  | }  | 
140  |  |  | 
141  |  | PyDoc_STRVAR(int_as_integer_ratio__doc__,  | 
142  |  | "as_integer_ratio($self, /)\n"  | 
143  |  | "--\n"  | 
144  |  | "\n"  | 
145  |  | "Return integer ratio.\n"  | 
146  |  | "\n"  | 
147  |  | "Return a pair of integers, whose ratio is exactly equal to the original int\n"  | 
148  |  | "and with a positive denominator.\n"  | 
149  |  | "\n"  | 
150  |  | ">>> (10).as_integer_ratio()\n"  | 
151  |  | "(10, 1)\n"  | 
152  |  | ">>> (-10).as_integer_ratio()\n"  | 
153  |  | "(-10, 1)\n"  | 
154  |  | ">>> (0).as_integer_ratio()\n"  | 
155  |  | "(0, 1)");  | 
156  |  |  | 
157  |  | #define INT_AS_INTEGER_RATIO_METHODDEF    \  | 
158  |  |     {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__}, | 
159  |  |  | 
160  |  | static PyObject *  | 
161  |  | int_as_integer_ratio_impl(PyObject *self);  | 
162  |  |  | 
163  |  | static PyObject *  | 
164  |  | int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))  | 
165  | 0  | { | 
166  | 0  |     return int_as_integer_ratio_impl(self);  | 
167  | 0  | }  | 
168  |  |  | 
169  |  | PyDoc_STRVAR(int_to_bytes__doc__,  | 
170  |  | "to_bytes($self, /, length, byteorder, *, signed=False)\n"  | 
171  |  | "--\n"  | 
172  |  | "\n"  | 
173  |  | "Return an array of bytes representing an integer.\n"  | 
174  |  | "\n"  | 
175  |  | "  length\n"  | 
176  |  | "    Length of bytes object to use.  An OverflowError is raised if the\n"  | 
177  |  | "    integer is not representable with the given number of bytes.\n"  | 
178  |  | "  byteorder\n"  | 
179  |  | "    The byte order used to represent the integer.  If byteorder is \'big\',\n"  | 
180  |  | "    the most significant byte is at the beginning of the byte array.  If\n"  | 
181  |  | "    byteorder is \'little\', the most significant byte is at the end of the\n"  | 
182  |  | "    byte array.  To request the native byte order of the host system, use\n"  | 
183  |  | "    `sys.byteorder\' as the byte order value.\n"  | 
184  |  | "  signed\n"  | 
185  |  | "    Determines whether two\'s complement is used to represent the integer.\n"  | 
186  |  | "    If signed is False and a negative integer is given, an OverflowError\n"  | 
187  |  | "    is raised.");  | 
188  |  |  | 
189  |  | #define INT_TO_BYTES_METHODDEF    \  | 
190  |  |     {"to_bytes", (PyCFunction)(void(*)(void))int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__}, | 
191  |  |  | 
192  |  | static PyObject *  | 
193  |  | int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,  | 
194  |  |                   int is_signed);  | 
195  |  |  | 
196  |  | static PyObject *  | 
197  |  | int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)  | 
198  | 14  | { | 
199  | 14  |     PyObject *return_value = NULL;  | 
200  | 14  |     static const char * const _keywords[] = {"length", "byteorder", "signed", NULL}; | 
201  | 14  |     static _PyArg_Parser _parser = {NULL, _keywords, "to_bytes", 0}; | 
202  | 14  |     PyObject *argsbuf[3];  | 
203  | 14  |     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;  | 
204  | 14  |     Py_ssize_t length;  | 
205  | 14  |     PyObject *byteorder;  | 
206  | 14  |     int is_signed = 0;  | 
207  |  |  | 
208  | 14  |     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);  | 
209  | 14  |     if (!args) { | 
210  | 0  |         goto exit;  | 
211  | 0  |     }  | 
212  | 14  |     if (PyFloat_Check(args[0])) { | 
213  | 0  |         PyErr_SetString(PyExc_TypeError,  | 
214  | 0  |                         "integer argument expected, got float" );  | 
215  | 0  |         goto exit;  | 
216  | 0  |     }  | 
217  | 14  |     { | 
218  | 14  |         Py_ssize_t ival = -1;  | 
219  | 14  |         PyObject *iobj = PyNumber_Index(args[0]);  | 
220  | 14  |         if (iobj != NULL) { | 
221  | 14  |             ival = PyLong_AsSsize_t(iobj);  | 
222  | 14  |             Py_DECREF(iobj);  | 
223  | 14  |         }  | 
224  | 14  |         if (ival == -1 && PyErr_Occurred()) { | 
225  | 0  |             goto exit;  | 
226  | 0  |         }  | 
227  | 14  |         length = ival;  | 
228  | 14  |     }  | 
229  | 14  |     if (!PyUnicode_Check(args[1])) { | 
230  | 0  |         _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]); | 
231  | 0  |         goto exit;  | 
232  | 0  |     }  | 
233  | 14  |     if (PyUnicode_READY(args[1]) == -1) { | 
234  | 0  |         goto exit;  | 
235  | 0  |     }  | 
236  | 14  |     byteorder = args[1];  | 
237  | 14  |     if (!noptargs) { | 
238  | 14  |         goto skip_optional_kwonly;  | 
239  | 14  |     }  | 
240  | 0  |     is_signed = PyObject_IsTrue(args[2]);  | 
241  | 0  |     if (is_signed < 0) { | 
242  | 0  |         goto exit;  | 
243  | 0  |     }  | 
244  | 14  | skip_optional_kwonly:  | 
245  | 14  |     return_value = int_to_bytes_impl(self, length, byteorder, is_signed);  | 
246  |  |  | 
247  | 14  | exit:  | 
248  | 14  |     return return_value;  | 
249  | 14  | }  | 
250  |  |  | 
251  |  | PyDoc_STRVAR(int_from_bytes__doc__,  | 
252  |  | "from_bytes($type, /, bytes, byteorder, *, signed=False)\n"  | 
253  |  | "--\n"  | 
254  |  | "\n"  | 
255  |  | "Return the integer represented by the given array of bytes.\n"  | 
256  |  | "\n"  | 
257  |  | "  bytes\n"  | 
258  |  | "    Holds the array of bytes to convert.  The argument must either\n"  | 
259  |  | "    support the buffer protocol or be an iterable object producing bytes.\n"  | 
260  |  | "    Bytes and bytearray are examples of built-in objects that support the\n"  | 
261  |  | "    buffer protocol.\n"  | 
262  |  | "  byteorder\n"  | 
263  |  | "    The byte order used to represent the integer.  If byteorder is \'big\',\n"  | 
264  |  | "    the most significant byte is at the beginning of the byte array.  If\n"  | 
265  |  | "    byteorder is \'little\', the most significant byte is at the end of the\n"  | 
266  |  | "    byte array.  To request the native byte order of the host system, use\n"  | 
267  |  | "    `sys.byteorder\' as the byte order value.\n"  | 
268  |  | "  signed\n"  | 
269  |  | "    Indicates whether two\'s complement is used to represent the integer.");  | 
270  |  |  | 
271  |  | #define INT_FROM_BYTES_METHODDEF    \  | 
272  |  |     {"from_bytes", (PyCFunction)(void(*)(void))int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__}, | 
273  |  |  | 
274  |  | static PyObject *  | 
275  |  | int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,  | 
276  |  |                     PyObject *byteorder, int is_signed);  | 
277  |  |  | 
278  |  | static PyObject *  | 
279  |  | int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)  | 
280  | 719  | { | 
281  | 719  |     PyObject *return_value = NULL;  | 
282  | 719  |     static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL}; | 
283  | 719  |     static _PyArg_Parser _parser = {NULL, _keywords, "from_bytes", 0}; | 
284  | 719  |     PyObject *argsbuf[3];  | 
285  | 719  |     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;  | 
286  | 719  |     PyObject *bytes_obj;  | 
287  | 719  |     PyObject *byteorder;  | 
288  | 719  |     int is_signed = 0;  | 
289  |  |  | 
290  | 719  |     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);  | 
291  | 719  |     if (!args) { | 
292  | 0  |         goto exit;  | 
293  | 0  |     }  | 
294  | 719  |     bytes_obj = args[0];  | 
295  | 719  |     if (!PyUnicode_Check(args[1])) { | 
296  | 0  |         _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]); | 
297  | 0  |         goto exit;  | 
298  | 0  |     }  | 
299  | 719  |     if (PyUnicode_READY(args[1]) == -1) { | 
300  | 0  |         goto exit;  | 
301  | 0  |     }  | 
302  | 719  |     byteorder = args[1];  | 
303  | 719  |     if (!noptargs) { | 
304  | 719  |         goto skip_optional_kwonly;  | 
305  | 719  |     }  | 
306  | 0  |     is_signed = PyObject_IsTrue(args[2]);  | 
307  | 0  |     if (is_signed < 0) { | 
308  | 0  |         goto exit;  | 
309  | 0  |     }  | 
310  | 719  | skip_optional_kwonly:  | 
311  | 719  |     return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);  | 
312  |  |  | 
313  | 719  | exit:  | 
314  | 719  |     return return_value;  | 
315  | 719  | }  | 
316  |  | /*[clinic end generated code: output=77bc3b2615822cb8 input=a9049054013a1b77]*/  |