@@ -10,6 +10,9 @@ Integer Objects
10
10
11
11
All integers are implemented as "long" integer objects of arbitrary size.
12
12
13
+ On error, most ``PyLong_As* `` APIs return ``(return type)-1 `` which cannot be
14
+ distinguished from a number. Use :c:func: `PyErr_Occurred ` to disambiguate.
15
+
13
16
.. c :type :: PyLongObject
14
17
15
18
This subtype of :c:type: `PyObject ` represents a Python integer object.
@@ -134,6 +137,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
134
137
Raise :exc:`OverflowError` if the value of *obj* is out of range for a
135
138
:c:type:`long`.
136
139
140
+ Returns -1 on error. Use :c:func:`PyErr_Occurred` to disambiguate.
141
+
137
142
138
143
.. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow)
139
144
@@ -146,6 +151,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
146
151
return ``-1``; otherwise, set *\*overflow* to ``0 ``. If any other exception
147
152
occurs set *\* overflow * to ``0 `` and return ``-1 `` as usual.
148
153
154
+ Returns -1 on error. Use :c:func: `PyErr_Occurred ` to disambiguate.
155
+
149
156
150
157
.. c :function :: long long PyLong_AsLongLong (PyObject *obj)
151
158
@@ -159,6 +166,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
159
166
Raise :exc:`OverflowError` if the value of *obj* is out of range for a
160
167
:c:type:`long`.
161
168
169
+ Returns -1 on error. Use :c:func:`PyErr_Occurred` to disambiguate.
170
+
162
171
163
172
.. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
164
173
@@ -171,6 +180,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
171
180
and return ``-1``; otherwise, set *\*overflow* to ``0 ``. If any other
172
181
exception occurs set *\* overflow * to ``0 `` and return ``-1 `` as usual.
173
182
183
+ Returns -1 on error. Use :c:func: `PyErr_Occurred ` to disambiguate.
184
+
174
185
.. versionadded :: 3.2
175
186
176
187
@@ -186,6 +197,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
186
197
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
187
198
:c:type:`Py_ssize_t`.
188
199
200
+ Returns -1 on error. Use :c:func:`PyErr_Occurred` to disambiguate.
201
+
189
202
190
203
.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
191
204
@@ -199,15 +212,25 @@ All integers are implemented as "long" integer objects of arbitrary size.
199
212
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
200
213
:c:type:`unsigned long`.
201
214
215
+ Returns ``(unsigned long)-1`` on error.
216
+ Use :c:func:`PyErr_Occurred` to disambiguate.
217
+
202
218
203
219
.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
204
220
221
+ .. index ::
222
+ single: SIZE_MAX
223
+ single: OverflowError (built-in exception)
224
+
205
225
Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be
206
226
an instance of :c:type:`PyLongObject`.
207
227
208
228
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
209
229
:c:type:`size_t`.
210
230
231
+ Returns ``(size_t)-1`` on error.
232
+ Use :c:func:`PyErr_Occurred` to disambiguate.
233
+
211
234
212
235
.. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong)
213
236
@@ -220,6 +243,9 @@ All integers are implemented as "long" integer objects of arbitrary size.
220
243
Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
221
244
:c:type:`unsigned long long`.
222
245
246
+ Returns ``(unsigned long long)-1`` on error.
247
+ Use :c:func:`PyErr_Occurred` to disambiguate.
248
+
223
249
.. versionchanged:: 3.1
224
250
A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
225
251
@@ -233,6 +259,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
233
259
If the value of *obj* is out of range for an :c:type:`unsigned long`,
234
260
return the reduction of that value modulo ``ULONG_MAX + 1``.
235
261
262
+ Returns -1 on error. Use :c:func:`PyErr_Occurred` to disambiguate.
263
+
236
264
237
265
.. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj)
238
266
@@ -243,6 +271,8 @@ All integers are implemented as "long" integer objects of arbitrary size.
243
271
If the value of *obj* is out of range for an :c:type:`unsigned long long`,
244
272
return the reduction of that value modulo ``PY_ULLONG_MAX + 1``.
245
273
274
+ Returns -1 on error. Use :c:func:`PyErr_Occurred` to disambiguate.
275
+
246
276
247
277
.. c:function:: double PyLong_AsDouble(PyObject *pylong)
248
278
@@ -252,10 +282,14 @@ All integers are implemented as "long" integer objects of arbitrary size.
252
282
Raise :exc: `OverflowError ` if the value of *pylong * is out of range for a
253
283
:c:type: `double `.
254
284
285
+ Returns -1.0 on error. Use :c:func: `PyErr_Occurred ` to disambiguate.
286
+
255
287
256
288
.. c :function :: void * PyLong_AsVoidPtr (PyObject *pylong)
257
289
258
290
Convert a Python integer *pylong * to a C :c:type: `void ` pointer.
259
291
If *pylong * cannot be converted, an :exc: `OverflowError ` will be raised. This
260
292
is only assured to produce a usable :c:type: `void ` pointer for values created
261
293
with :c:func: `PyLong_FromVoidPtr `.
294
+
295
+ Returns NULL on error. Use :c:func: `PyErr_Occurred ` to disambiguate.
0 commit comments