Coverage Report

Created: 2022-07-08 09:39

/home/mdboom/Work/builds/cpython/Objects/clinic/longobject.c.h
Line
Count
Source (jump to first uncovered line)
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
{
11
    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
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
17
    Py_ssize_t noptargs = nargs + (kwargs ? 
PyDict_GET_SIZE20.1k
(kwargs) :
05.34M
) - 0;
  Branch (17:36): [True: 20.1k, False: 5.34M]
18
    PyObject *x = NULL;
19
    PyObject *obase = NULL;
20
21
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
22
    if (!fastargs) {
  Branch (22:9): [True: 5, False: 5.36M]
23
        goto exit;
24
    }
25
    if (nargs < 1) {
  Branch (25:9): [True: 21.0k, False: 5.34M]
26
        goto skip_optional_posonly;
27
    }
28
    noptargs--;
29
    x = fastargs[0];
30
skip_optional_posonly:
31
    if (!noptargs) {
  Branch (31:9): [True: 5.12M, False: 237k]
32
        goto skip_optional_pos;
33
    }
34
    obase = fastargs[1];
35
skip_optional_pos:
36
    return_value = long_new_impl(type, x, obase);
37
38
exit:
39
    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
int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
55
{
56
    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
int___format__(PyObject *self, PyObject *arg)
72
{
73
    PyObject *return_value = NULL;
74
    PyObject *format_spec;
75
76
    if (!PyUnicode_Check(arg)) {
  Branch (76:9): [True: 2, False: 2.11k]
77
        _PyArg_BadArgument("__format__", "argument", "str", arg);
78
        goto exit;
79
    }
80
    if (PyUnicode_READY(arg) == -1) {
  Branch (80:9): [True: 0, False: 2.11k]
81
        goto exit;
82
    }
83
    format_spec = arg;
84
    return_value = int___format___impl(self, format_spec);
85
86
exit:
87
    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
int___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
106
{
107
    PyObject *return_value = NULL;
108
    PyObject *o_ndigits = NULL;
109
110
    if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
111
        goto exit;
112
    }
113
    if (nargs < 1) {
  Branch (113:9): [True: 168, False: 1.67k]
114
        goto skip_optional;
115
    }
116
    o_ndigits = args[0];
117
skip_optional:
118
    return_value = int___round___impl(self, o_ndigits);
119
120
exit:
121
    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
int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
138
{
139
    PyObject *return_value = NULL;
140
    Py_ssize_t _return_value;
141
142
    _return_value = int___sizeof___impl(self);
143
    if ((_return_value == -1) && 
PyErr_Occurred()0
) {
  Branch (143:9): [True: 0, False: 12]
  Branch (143:34): [True: 0, False: 0]
144
        goto exit;
145
    }
146
    return_value = PyLong_FromSsize_t(_return_value);
147
148
exit:
149
    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
int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored))
171
{
172
    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
int_bit_count(PyObject *self, PyObject *Py_UNUSED(ignored))
196
{
197
    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
int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
224
{
225
    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
int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
258
{
259
    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
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE3.79k
(kwnames) :
0204k
) - 0;
  Branch (263:36): [True: 3.79k, False: 204k]
264
    Py_ssize_t length = 1;
265
    PyObject *byteorder = NULL;
266
    int is_signed = 0;
267
268
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
269
    if (!args) {
  Branch (269:9): [True: 0, False: 208k]
270
        goto exit;
271
    }
272
    if (!noptargs) {
  Branch (272:9): [True: 5, False: 208k]
273
        goto skip_optional_pos;
274
    }
275
    if (args[0]) {
  Branch (275:9): [True: 208k, False: 0]
276
        {
277
            Py_ssize_t ival = -1;
278
            PyObject *iobj = _PyNumber_Index(args[0]);
279
            if (iobj != NULL) {
  Branch (279:17): [True: 208k, False: 0]
280
                ival = PyLong_AsSsize_t(iobj);
281
                Py_DECREF(iobj);
282
            }
283
            if (ival == -1 && 
PyErr_Occurred()0
) {
  Branch (283:17): [True: 0, False: 208k]
  Branch (283:31): [True: 0, False: 0]
284
                goto exit;
285
            }
286
            length = ival;
287
        }
288
        if (!--noptargs) {
  Branch (288:13): [True: 700, False: 208k]
289
            goto skip_optional_pos;
290
        }
291
    }
292
    if (args[1]) {
  Branch (292:9): [True: 207k, False: 262]
293
        if (!PyUnicode_Check(args[1])) {
  Branch (293:13): [True: 0, False: 207k]
294
            _PyArg_BadArgument("to_bytes", "argument 'byteorder'", "str", args[1]);
295
            goto exit;
296
        }
297
        if (PyUnicode_READY(args[1]) == -1) {
  Branch (297:13): [True: 0, False: 207k]
298
            goto exit;
299
        }
300
        byteorder = args[1];
301
        if (!--noptargs) {
  Branch (301:13): [True: 204k, False: 3.53k]
302
            goto skip_optional_pos;
303
        }
304
    }
305
skip_optional_pos:
306
    if (!noptargs) {
  Branch (306:9): [True: 204k, False: 3.79k]
307
        goto skip_optional_kwonly;
308
    }
309
    is_signed = PyObject_IsTrue(args[2]);
310
    if (is_signed < 0) {
  Branch (310:9): [True: 0, False: 3.79k]
311
        goto exit;
312
    }
313
skip_optional_kwonly:
314
    return_value = int_to_bytes_impl(self, length, byteorder, is_signed);
315
316
exit:
317
    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
int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
349
{
350
    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
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE2.74k
(kwnames) :
0185k
) - 1;
  Branch (354:36): [True: 2.74k, False: 185k]
355
    PyObject *bytes_obj;
356
    PyObject *byteorder = NULL;
357
    int is_signed = 0;
358
359
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
360
    if (!args) {
  Branch (360:9): [True: 3, False: 188k]
361
        goto exit;
362
    }
363
    bytes_obj = args[0];
364
    if (!noptargs) {
  Branch (364:9): [True: 164k, False: 23.5k]
365
        goto skip_optional_pos;
366
    }
367
    if (args[1]) {
  Branch (367:9): [True: 23.3k, False: 262]
368
        if (!PyUnicode_Check(args[1])) {
  Branch (368:13): [True: 0, False: 23.3k]
369
            _PyArg_BadArgument("from_bytes", "argument 'byteorder'", "str", args[1]);
370
            goto exit;
371
        }
372
        if (PyUnicode_READY(args[1]) == -1) {
  Branch (372:13): [True: 0, False: 23.3k]
373
            goto exit;
374
        }
375
        byteorder = args[1];
376
        if (!--noptargs) {
  Branch (376:13): [True: 20.8k, False: 2.46k]
377
            goto skip_optional_pos;
378
        }
379
    }
380
skip_optional_pos:
381
    if (!noptargs) {
  Branch (381:9): [True: 185k, False: 2.73k]
382
        goto skip_optional_kwonly;
383
    }
384
    is_signed = PyObject_IsTrue(args[2]);
385
    if (is_signed < 0) {
  Branch (385:9): [True: 0, False: 2.73k]
386
        goto exit;
387
    }
388
skip_optional_kwonly:
389
    return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);
390
391
exit:
392
    return return_value;
393
}
394
/*[clinic end generated code: output=899e57c41861a8e9 input=a9049054013a1b77]*/