blob: 8093f4b627a2b9b1a2ffa00b8fc3f5d927654cf1 [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
3.. _longobjects:
4
5Integer Objects
6---------------
7
8.. index:: object: long integer
9 object: integer
10
11All integers are implemented as "long" integer objects of arbitrary size.
12
Gregory P. Smithf5b04a32018-01-28 17:48:31 -080013On error, most ``PyLong_As*`` APIs return ``(return type)-1`` which cannot be
14distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
15
Georg Brandl60203b42010-10-06 10:11:56 +000016.. c:type:: PyLongObject
Georg Brandl54a3faa2008-01-20 09:30:57 +000017
Georg Brandl60203b42010-10-06 10:11:56 +000018 This subtype of :c:type:`PyObject` represents a Python integer object.
Georg Brandl54a3faa2008-01-20 09:30:57 +000019
20
Georg Brandl60203b42010-10-06 10:11:56 +000021.. c:var:: PyTypeObject PyLong_Type
Georg Brandl54a3faa2008-01-20 09:30:57 +000022
Georg Brandl60203b42010-10-06 10:11:56 +000023 This instance of :c:type:`PyTypeObject` represents the Python integer type.
Georg Brandl2aff3352010-10-17 10:59:41 +000024 This is the same object as :class:`int` in the Python layer.
Georg Brandl54a3faa2008-01-20 09:30:57 +000025
26
Georg Brandl60203b42010-10-06 10:11:56 +000027.. c:function:: int PyLong_Check(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000028
Georg Brandl60203b42010-10-06 10:11:56 +000029 Return true if its argument is a :c:type:`PyLongObject` or a subtype of
30 :c:type:`PyLongObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000031
32
Georg Brandl60203b42010-10-06 10:11:56 +000033.. c:function:: int PyLong_CheckExact(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000034
Georg Brandl60203b42010-10-06 10:11:56 +000035 Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of
36 :c:type:`PyLongObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000037
38
Georg Brandl60203b42010-10-06 10:11:56 +000039.. c:function:: PyObject* PyLong_FromLong(long v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000040
Georg Brandl60203b42010-10-06 10:11:56 +000041 Return a new :c:type:`PyLongObject` object from *v*, or *NULL* on failure.
Georg Brandl54a3faa2008-01-20 09:30:57 +000042
43 The current implementation keeps an array of integer objects for all integers
44 between ``-5`` and ``256``, when you create an int in that range you actually
45 just get back a reference to the existing object. So it should be possible to
46 change the value of ``1``. I suspect the behaviour of Python in this case is
47 undefined. :-)
48
49
Georg Brandl60203b42010-10-06 10:11:56 +000050.. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000051
Georg Brandl60203b42010-10-06 10:11:56 +000052 Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long`, or
Georg Brandl54a3faa2008-01-20 09:30:57 +000053 *NULL* on failure.
54
55
Georg Brandl60203b42010-10-06 10:11:56 +000056.. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000057
Georg Brandl60203b42010-10-06 10:11:56 +000058 Return a new :c:type:`PyLongObject` object from a C :c:type:`Py_ssize_t`, or
Christian Heimes81ee3ef2008-05-04 22:42:01 +000059 *NULL* on failure.
Georg Brandl54a3faa2008-01-20 09:30:57 +000060
61
Georg Brandl60203b42010-10-06 10:11:56 +000062.. c:function:: PyObject* PyLong_FromSize_t(size_t v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000063
Georg Brandl60203b42010-10-06 10:11:56 +000064 Return a new :c:type:`PyLongObject` object from a C :c:type:`size_t`, or
Christian Heimes81ee3ef2008-05-04 22:42:01 +000065 *NULL* on failure.
Georg Brandl54a3faa2008-01-20 09:30:57 +000066
67
Benjamin Peterson47ff0732016-09-08 09:15:54 -070068.. c:function:: PyObject* PyLong_FromLongLong(long long v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000069
Georg Brandl60203b42010-10-06 10:11:56 +000070 Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL*
Georg Brandl54a3faa2008-01-20 09:30:57 +000071 on failure.
72
73
Benjamin Peterson47ff0732016-09-08 09:15:54 -070074.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000075
Georg Brandl60203b42010-10-06 10:11:56 +000076 Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`,
Georg Brandl54a3faa2008-01-20 09:30:57 +000077 or *NULL* on failure.
78
79
Georg Brandl60203b42010-10-06 10:11:56 +000080.. c:function:: PyObject* PyLong_FromDouble(double v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000081
Georg Brandl60203b42010-10-06 10:11:56 +000082 Return a new :c:type:`PyLongObject` object from the integer part of *v*, or
Georg Brandl54a3faa2008-01-20 09:30:57 +000083 *NULL* on failure.
84
85
Serhiy Storchakac6792272013-10-19 21:03:34 +030086.. c:function:: PyObject* PyLong_FromString(const char *str, char **pend, int base)
Georg Brandl54a3faa2008-01-20 09:30:57 +000087
Georg Brandl60203b42010-10-06 10:11:56 +000088 Return a new :c:type:`PyLongObject` based on the string value in *str*, which
Georg Brandl54a3faa2008-01-20 09:30:57 +000089 is interpreted according to the radix in *base*. If *pend* is non-*NULL*,
Ezio Melottiea30c6f2010-01-30 13:32:14 +000090 *\*pend* will point to the first character in *str* which follows the
csabella26896f22017-04-23 23:54:08 -040091 representation of the number. If *base* is ``0``, *str* is interpreted using
92 the :ref:`integers` definition; in this case, leading zeros in a
93 non-zero decimal number raises a :exc:`ValueError`. If *base* is not ``0``,
94 it must be between ``2`` and ``36``, inclusive. Leading spaces and single
95 underscores after a base specifier and between digits are ignored. If there
96 are no digits, :exc:`ValueError` will be raised.
Georg Brandl54a3faa2008-01-20 09:30:57 +000097
98
Georg Brandl60203b42010-10-06 10:11:56 +000099.. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000100
101 Convert a sequence of Unicode digits to a Python integer value. The Unicode
Georg Brandl60203b42010-10-06 10:11:56 +0000102 string is first encoded to a byte string using :c:func:`PyUnicode_EncodeDecimal`
103 and then converted using :c:func:`PyLong_FromString`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000104
Georg Brandldb6c7f52011-10-07 11:19:11 +0200105 .. deprecated-removed:: 3.3 4.0
106 Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
107 :c:func:`PyLong_FromUnicodeObject`.
108
109
110.. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base)
111
112 Convert a sequence of Unicode digits in the string *u* to a Python integer
113 value. The Unicode string is first encoded to a byte string using
114 :c:func:`PyUnicode_EncodeDecimal` and then converted using
115 :c:func:`PyLong_FromString`.
116
117 .. versionadded:: 3.3
118
Georg Brandl54a3faa2008-01-20 09:30:57 +0000119
Georg Brandl60203b42010-10-06 10:11:56 +0000120.. c:function:: PyObject* PyLong_FromVoidPtr(void *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000121
122 Create a Python integer from the pointer *p*. The pointer value can be
Georg Brandl60203b42010-10-06 10:11:56 +0000123 retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000124
125
Georg Brandl48310cd2009-01-03 21:18:54 +0000126.. XXX alias PyLong_AS_LONG (for now)
Mark Dickinson0a229242012-06-23 10:49:12 +0100127.. c:function:: long PyLong_AsLong(PyObject *obj)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000128
129 .. index::
130 single: LONG_MAX
131 single: OverflowError (built-in exception)
132
Mark Dickinson0a229242012-06-23 10:49:12 +0100133 Return a C :c:type:`long` representation of *obj*. If *obj* is not an
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200134 instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
135 :meth:`__int__` method (if present) to convert it to a
136 :c:type:`PyLongObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000137
Mark Dickinson0a229242012-06-23 10:49:12 +0100138 Raise :exc:`OverflowError` if the value of *obj* is out of range for a
139 :c:type:`long`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000140
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200141 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800142
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200143 .. versionchanged:: 3.8
144 Use :meth:`__index__` if available.
145
146 .. deprecated:: 3.8
147 Using :meth:`__int__` is deprecated.
148
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100149
Mark Dickinson0a229242012-06-23 10:49:12 +0100150.. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow)
151
152 Return a C :c:type:`long` representation of *obj*. If *obj* is not an
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200153 instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
154 :meth:`__int__` method (if present) to convert it to a
155 :c:type:`PyLongObject`.
Mark Dickinson0a229242012-06-23 10:49:12 +0100156
157 If the value of *obj* is greater than :const:`LONG_MAX` or less than
158 :const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and
159 return ``-1``; otherwise, set *\*overflow* to ``0``. If any other exception
160 occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000161
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200162 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800163
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200164 .. versionchanged:: 3.8
165 Use :meth:`__index__` if available.
166
167 .. deprecated:: 3.8
168 Using :meth:`__int__` is deprecated.
169
Georg Brandl54a3faa2008-01-20 09:30:57 +0000170
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700171.. c:function:: long long PyLong_AsLongLong(PyObject *obj)
Mark Dickinson93f562c2010-01-30 10:30:15 +0000172
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100173 .. index::
174 single: OverflowError (built-in exception)
175
176 Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200177 instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
178 :meth:`__int__` method (if present) to convert it to a
179 :c:type:`PyLongObject`.
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100180
181 Raise :exc:`OverflowError` if the value of *obj* is out of range for a
182 :c:type:`long`.
183
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200184 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800185
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200186 .. versionchanged:: 3.8
187 Use :meth:`__index__` if available.
188
189 .. deprecated:: 3.8
190 Using :meth:`__int__` is deprecated.
191
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100192
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700193.. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100194
195 Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200196 instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or
197 :meth:`__int__` method (if present) to convert it to a
198 :c:type:`PyLongObject`.
Mark Dickinsonf0acfee2012-06-23 11:14:22 +0100199
200 If the value of *obj* is greater than :const:`PY_LLONG_MAX` or less than
201 :const:`PY_LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
202 and return ``-1``; otherwise, set *\*overflow* to ``0``. If any other
203 exception occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
Mark Dickinson93f562c2010-01-30 10:30:15 +0000204
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200205 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800206
Mark Dickinson93f562c2010-01-30 10:30:15 +0000207 .. versionadded:: 3.2
208
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200209 .. versionchanged:: 3.8
210 Use :meth:`__index__` if available.
211
212 .. deprecated:: 3.8
213 Using :meth:`__int__` is deprecated.
214
Mark Dickinson93f562c2010-01-30 10:30:15 +0000215
Georg Brandl60203b42010-10-06 10:11:56 +0000216.. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong)
Christian Heimes81ee3ef2008-05-04 22:42:01 +0000217
218 .. index::
219 single: PY_SSIZE_T_MAX
220 single: OverflowError (built-in exception)
221
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100222 Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must
223 be an instance of :c:type:`PyLongObject`.
224
225 Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
226 :c:type:`Py_ssize_t`.
Christian Heimes81ee3ef2008-05-04 22:42:01 +0000227
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200228 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800229
Christian Heimes81ee3ef2008-05-04 22:42:01 +0000230
Georg Brandl60203b42010-10-06 10:11:56 +0000231.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000232
233 .. index::
234 single: ULONG_MAX
235 single: OverflowError (built-in exception)
236
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100237 Return a C :c:type:`unsigned long` representation of *pylong*. *pylong*
238 must be an instance of :c:type:`PyLongObject`.
239
240 Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
241 :c:type:`unsigned long`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000242
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800243 Returns ``(unsigned long)-1`` on error.
244 Use :c:func:`PyErr_Occurred` to disambiguate.
245
Georg Brandl54a3faa2008-01-20 09:30:57 +0000246
Georg Brandl60203b42010-10-06 10:11:56 +0000247.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000248
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800249 .. index::
250 single: SIZE_MAX
251 single: OverflowError (built-in exception)
252
Terry Jan Reedy65e69b32013-03-11 17:23:46 -0400253 Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100254 an instance of :c:type:`PyLongObject`.
255
256 Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
257 :c:type:`size_t`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000258
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800259 Returns ``(size_t)-1`` on error.
260 Use :c:func:`PyErr_Occurred` to disambiguate.
261
Georg Brandl54a3faa2008-01-20 09:30:57 +0000262
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700263.. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000264
Mark Dickinson21776072009-02-10 16:13:25 +0000265 .. index::
266 single: OverflowError (built-in exception)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000267
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700268 Return a C :c:type:`unsigned long long` representation of *pylong*. *pylong*
269 must be an instance of :c:type:`PyLongObject`.
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100270
271 Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700272 :c:type:`unsigned long long`.
Mark Dickinson21776072009-02-10 16:13:25 +0000273
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800274 Returns ``(unsigned long long)-1`` on error.
275 Use :c:func:`PyErr_Occurred` to disambiguate.
276
Mark Dickinson21776072009-02-10 16:13:25 +0000277 .. versionchanged:: 3.1
Georg Brandl67b21b72010-08-17 15:07:14 +0000278 A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
279
Georg Brandl54a3faa2008-01-20 09:30:57 +0000280
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100281.. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *obj)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000282
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100283 Return a C :c:type:`unsigned long` representation of *obj*. If *obj*
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200284 is not an instance of :c:type:`PyLongObject`, first call its
285 :meth:`__index__` or :meth:`__int__` method (if present) to convert
286 it to a :c:type:`PyLongObject`.
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100287
288 If the value of *obj* is out of range for an :c:type:`unsigned long`,
Serhiy Storchaka1ecf7d22016-10-27 21:41:19 +0300289 return the reduction of that value modulo ``ULONG_MAX + 1``.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000290
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200291 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800292
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200293 .. versionchanged:: 3.8
294 Use :meth:`__index__` if available.
295
296 .. deprecated:: 3.8
297 Using :meth:`__int__` is deprecated.
298
Georg Brandl54a3faa2008-01-20 09:30:57 +0000299
Benjamin Peterson47ff0732016-09-08 09:15:54 -0700300.. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000301
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100302 Return a C :c:type:`unsigned long long` representation of *obj*. If *obj*
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200303 is not an instance of :c:type:`PyLongObject`, first call its
304 :meth:`__index__` or :meth:`__int__` method (if present) to convert
305 it to a :c:type:`PyLongObject`.
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100306
307 If the value of *obj* is out of range for an :c:type:`unsigned long long`,
Serhiy Storchaka1ecf7d22016-10-27 21:41:19 +0300308 return the reduction of that value modulo ``PY_ULLONG_MAX + 1``.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000309
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200310 Returns ``-1`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800311
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200312 .. versionchanged:: 3.8
313 Use :meth:`__index__` if available.
314
315 .. deprecated:: 3.8
316 Using :meth:`__int__` is deprecated.
317
Georg Brandl54a3faa2008-01-20 09:30:57 +0000318
Georg Brandl60203b42010-10-06 10:11:56 +0000319.. c:function:: double PyLong_AsDouble(PyObject *pylong)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000320
Mark Dickinsonb8dc3ab2012-06-23 12:12:52 +0100321 Return a C :c:type:`double` representation of *pylong*. *pylong* must be
322 an instance of :c:type:`PyLongObject`.
323
324 Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
325 :c:type:`double`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000326
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200327 Returns ``-1.0`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800328
Georg Brandl54a3faa2008-01-20 09:30:57 +0000329
Georg Brandl60203b42010-10-06 10:11:56 +0000330.. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000331
Georg Brandl60203b42010-10-06 10:11:56 +0000332 Convert a Python integer *pylong* to a C :c:type:`void` pointer.
Christian Heimesc3f30c42008-02-22 16:37:40 +0000333 If *pylong* cannot be converted, an :exc:`OverflowError` will be raised. This
Georg Brandl60203b42010-10-06 10:11:56 +0000334 is only assured to produce a usable :c:type:`void` pointer for values created
335 with :c:func:`PyLong_FromVoidPtr`.
Gregory P. Smithf5b04a32018-01-28 17:48:31 -0800336
Serhiy Storchaka5bb00052018-02-09 13:31:19 +0200337 Returns *NULL* on error. Use :c:func:`PyErr_Occurred` to disambiguate.