• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
long_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)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 
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 *
int___getnewargs__(PyObject * self,PyObject * Py_UNUSED (ignored))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 *
int___format__(PyObject * self,PyObject * arg)56 int___format__(PyObject *self, PyObject *arg)
57 {
58     PyObject *return_value = NULL;
59     PyObject *format_spec;
60 
61     if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
62         goto exit;
63     }
64     return_value = int___format___impl(self, format_spec);
65 
66 exit:
67     return return_value;
68 }
69 
70 PyDoc_STRVAR(int___sizeof____doc__,
71 "__sizeof__($self, /)\n"
72 "--\n"
73 "\n"
74 "Returns size in memory, in bytes.");
75 
76 #define INT___SIZEOF___METHODDEF    \
77     {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__},
78 
79 static Py_ssize_t
80 int___sizeof___impl(PyObject *self);
81 
82 static PyObject *
int___sizeof__(PyObject * self,PyObject * Py_UNUSED (ignored))83 int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
84 {
85     PyObject *return_value = NULL;
86     Py_ssize_t _return_value;
87 
88     _return_value = int___sizeof___impl(self);
89     if ((_return_value == -1) && PyErr_Occurred()) {
90         goto exit;
91     }
92     return_value = PyLong_FromSsize_t(_return_value);
93 
94 exit:
95     return return_value;
96 }
97 
98 PyDoc_STRVAR(int_bit_length__doc__,
99 "bit_length($self, /)\n"
100 "--\n"
101 "\n"
102 "Number of bits necessary to represent self in binary.\n"
103 "\n"
104 ">>> bin(37)\n"
105 "\'0b100101\'\n"
106 ">>> (37).bit_length()\n"
107 "6");
108 
109 #define INT_BIT_LENGTH_METHODDEF    \
110     {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__},
111 
112 static PyObject *
113 int_bit_length_impl(PyObject *self);
114 
115 static PyObject *
int_bit_length(PyObject * self,PyObject * Py_UNUSED (ignored))116 int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored))
117 {
118     return int_bit_length_impl(self);
119 }
120 
121 PyDoc_STRVAR(int_to_bytes__doc__,
122 "to_bytes($self, /, length, byteorder, *, signed=False)\n"
123 "--\n"
124 "\n"
125 "Return an array of bytes representing an integer.\n"
126 "\n"
127 "  length\n"
128 "    Length of bytes object to use.  An OverflowError is raised if the\n"
129 "    integer is not representable with the given number of bytes.\n"
130 "  byteorder\n"
131 "    The byte order used to represent the integer.  If byteorder is \'big\',\n"
132 "    the most significant byte is at the beginning of the byte array.  If\n"
133 "    byteorder is \'little\', the most significant byte is at the end of the\n"
134 "    byte array.  To request the native byte order of the host system, use\n"
135 "    `sys.byteorder\' as the byte order value.\n"
136 "  signed\n"
137 "    Determines whether two\'s complement is used to represent the integer.\n"
138 "    If signed is False and a negative integer is given, an OverflowError\n"
139 "    is raised.");
140 
141 #define INT_TO_BYTES_METHODDEF    \
142     {"to_bytes", (PyCFunction)int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__},
143 
144 static PyObject *
145 int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
146                   int is_signed);
147 
148 static PyObject *
int_to_bytes(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)149 int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
150 {
151     PyObject *return_value = NULL;
152     static const char * const _keywords[] = {"length", "byteorder", "signed", NULL};
153     static _PyArg_Parser _parser = {"nU|$p:to_bytes", _keywords, 0};
154     Py_ssize_t length;
155     PyObject *byteorder;
156     int is_signed = 0;
157 
158     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
159         &length, &byteorder, &is_signed)) {
160         goto exit;
161     }
162     return_value = int_to_bytes_impl(self, length, byteorder, is_signed);
163 
164 exit:
165     return return_value;
166 }
167 
168 PyDoc_STRVAR(int_from_bytes__doc__,
169 "from_bytes($type, /, bytes, byteorder, *, signed=False)\n"
170 "--\n"
171 "\n"
172 "Return the integer represented by the given array of bytes.\n"
173 "\n"
174 "  bytes\n"
175 "    Holds the array of bytes to convert.  The argument must either\n"
176 "    support the buffer protocol or be an iterable object producing bytes.\n"
177 "    Bytes and bytearray are examples of built-in objects that support the\n"
178 "    buffer protocol.\n"
179 "  byteorder\n"
180 "    The byte order used to represent the integer.  If byteorder is \'big\',\n"
181 "    the most significant byte is at the beginning of the byte array.  If\n"
182 "    byteorder is \'little\', the most significant byte is at the end of the\n"
183 "    byte array.  To request the native byte order of the host system, use\n"
184 "    `sys.byteorder\' as the byte order value.\n"
185 "  signed\n"
186 "    Indicates whether two\'s complement is used to represent the integer.");
187 
188 #define INT_FROM_BYTES_METHODDEF    \
189     {"from_bytes", (PyCFunction)int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__},
190 
191 static PyObject *
192 int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
193                     PyObject *byteorder, int is_signed);
194 
195 static PyObject *
int_from_bytes(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)196 int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
197 {
198     PyObject *return_value = NULL;
199     static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL};
200     static _PyArg_Parser _parser = {"OU|$p:from_bytes", _keywords, 0};
201     PyObject *bytes_obj;
202     PyObject *byteorder;
203     int is_signed = 0;
204 
205     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
206         &bytes_obj, &byteorder, &is_signed)) {
207         goto exit;
208     }
209     return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);
210 
211 exit:
212     return return_value;
213 }
214 /*[clinic end generated code: output=fd64beb83bd16df3 input=a9049054013a1b77]*/
215