Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _longobjects: |
| 4 | |
| 5 | Integer Objects |
| 6 | --------------- |
| 7 | |
| 8 | .. index:: object: long integer |
| 9 | object: integer |
| 10 | |
| 11 | All integers are implemented as "long" integer objects of arbitrary size. |
| 12 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 13 | .. c:type:: PyLongObject |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 14 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 15 | This subtype of :c:type:`PyObject` represents a Python integer object. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 16 | |
| 17 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 18 | .. c:var:: PyTypeObject PyLong_Type |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 19 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 20 | This instance of :c:type:`PyTypeObject` represents the Python integer type. |
Georg Brandl | 2aff335 | 2010-10-17 10:59:41 +0000 | [diff] [blame] | 21 | This is the same object as :class:`int` in the Python layer. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 22 | |
| 23 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 24 | .. c:function:: int PyLong_Check(PyObject *p) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 25 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 26 | Return true if its argument is a :c:type:`PyLongObject` or a subtype of |
| 27 | :c:type:`PyLongObject`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 28 | |
| 29 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 30 | .. c:function:: int PyLong_CheckExact(PyObject *p) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 31 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 32 | Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of |
| 33 | :c:type:`PyLongObject`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 34 | |
| 35 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 36 | .. c:function:: PyObject* PyLong_FromLong(long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 37 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 38 | Return a new :c:type:`PyLongObject` object from *v*, or *NULL* on failure. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 39 | |
| 40 | The current implementation keeps an array of integer objects for all integers |
| 41 | between ``-5`` and ``256``, when you create an int in that range you actually |
| 42 | just get back a reference to the existing object. So it should be possible to |
| 43 | change the value of ``1``. I suspect the behaviour of Python in this case is |
| 44 | undefined. :-) |
| 45 | |
| 46 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 47 | .. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 48 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 49 | Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long`, or |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 50 | *NULL* on failure. |
| 51 | |
| 52 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 53 | .. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 54 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 55 | Return a new :c:type:`PyLongObject` object from a C :c:type:`Py_ssize_t`, or |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 56 | *NULL* on failure. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 57 | |
| 58 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 59 | .. c:function:: PyObject* PyLong_FromSize_t(size_t v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 60 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 61 | Return a new :c:type:`PyLongObject` object from a C :c:type:`size_t`, or |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 62 | *NULL* on failure. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 63 | |
| 64 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 65 | .. c:function:: PyObject* PyLong_FromLongLong(long long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 66 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 67 | Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL* |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 68 | on failure. |
| 69 | |
| 70 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 71 | .. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 72 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 73 | Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`, |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 74 | or *NULL* on failure. |
| 75 | |
| 76 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 77 | .. c:function:: PyObject* PyLong_FromDouble(double v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 78 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 79 | Return a new :c:type:`PyLongObject` object from the integer part of *v*, or |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 80 | *NULL* on failure. |
| 81 | |
| 82 | |
Serhiy Storchaka | c679227 | 2013-10-19 21:03:34 +0300 | [diff] [blame] | 83 | .. c:function:: PyObject* PyLong_FromString(const char *str, char **pend, int base) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 84 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 85 | Return a new :c:type:`PyLongObject` based on the string value in *str*, which |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 86 | is interpreted according to the radix in *base*. If *pend* is non-*NULL*, |
Ezio Melotti | ea30c6f | 2010-01-30 13:32:14 +0000 | [diff] [blame] | 87 | *\*pend* will point to the first character in *str* which follows the |
csabella | 26896f2 | 2017-04-23 23:54:08 -0400 | [diff] [blame] | 88 | representation of the number. If *base* is ``0``, *str* is interpreted using |
| 89 | the :ref:`integers` definition; in this case, leading zeros in a |
| 90 | non-zero decimal number raises a :exc:`ValueError`. If *base* is not ``0``, |
| 91 | it must be between ``2`` and ``36``, inclusive. Leading spaces and single |
| 92 | underscores after a base specifier and between digits are ignored. If there |
| 93 | are no digits, :exc:`ValueError` will be raised. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 94 | |
| 95 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 96 | .. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 97 | |
| 98 | Convert a sequence of Unicode digits to a Python integer value. The Unicode |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 99 | string is first encoded to a byte string using :c:func:`PyUnicode_EncodeDecimal` |
| 100 | and then converted using :c:func:`PyLong_FromString`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 101 | |
Georg Brandl | db6c7f5 | 2011-10-07 11:19:11 +0200 | [diff] [blame] | 102 | .. deprecated-removed:: 3.3 4.0 |
| 103 | Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using |
| 104 | :c:func:`PyLong_FromUnicodeObject`. |
| 105 | |
| 106 | |
| 107 | .. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base) |
| 108 | |
| 109 | Convert a sequence of Unicode digits in the string *u* to a Python integer |
| 110 | value. The Unicode string is first encoded to a byte string using |
| 111 | :c:func:`PyUnicode_EncodeDecimal` and then converted using |
| 112 | :c:func:`PyLong_FromString`. |
| 113 | |
| 114 | .. versionadded:: 3.3 |
| 115 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 116 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 117 | .. c:function:: PyObject* PyLong_FromVoidPtr(void *p) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 118 | |
| 119 | Create a Python integer from the pointer *p*. The pointer value can be |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 120 | retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 121 | |
| 122 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 123 | .. XXX alias PyLong_AS_LONG (for now) |
Mark Dickinson | 0a22924 | 2012-06-23 10:49:12 +0100 | [diff] [blame] | 124 | .. c:function:: long PyLong_AsLong(PyObject *obj) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 125 | |
| 126 | .. index:: |
| 127 | single: LONG_MAX |
| 128 | single: OverflowError (built-in exception) |
| 129 | |
Mark Dickinson | 0a22924 | 2012-06-23 10:49:12 +0100 | [diff] [blame] | 130 | Return a C :c:type:`long` representation of *obj*. If *obj* is not an |
| 131 | instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method |
| 132 | (if present) to convert it to a :c:type:`PyLongObject`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 133 | |
Mark Dickinson | 0a22924 | 2012-06-23 10:49:12 +0100 | [diff] [blame] | 134 | Raise :exc:`OverflowError` if the value of *obj* is out of range for a |
| 135 | :c:type:`long`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 136 | |
Mark Dickinson | f0acfee | 2012-06-23 11:14:22 +0100 | [diff] [blame] | 137 | |
Mark Dickinson | 0a22924 | 2012-06-23 10:49:12 +0100 | [diff] [blame] | 138 | .. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow) |
| 139 | |
| 140 | Return a C :c:type:`long` representation of *obj*. If *obj* is not an |
| 141 | instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method |
| 142 | (if present) to convert it to a :c:type:`PyLongObject`. |
| 143 | |
| 144 | If the value of *obj* is greater than :const:`LONG_MAX` or less than |
| 145 | :const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and |
| 146 | return ``-1``; otherwise, set *\*overflow* to ``0``. If any other exception |
| 147 | occurs set *\*overflow* to ``0`` and return ``-1`` as usual. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 148 | |
| 149 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 150 | .. c:function:: long long PyLong_AsLongLong(PyObject *obj) |
Mark Dickinson | 93f562c | 2010-01-30 10:30:15 +0000 | [diff] [blame] | 151 | |
Mark Dickinson | f0acfee | 2012-06-23 11:14:22 +0100 | [diff] [blame] | 152 | .. index:: |
| 153 | single: OverflowError (built-in exception) |
| 154 | |
| 155 | Return a C :c:type:`long long` representation of *obj*. If *obj* is not an |
| 156 | instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method |
| 157 | (if present) to convert it to a :c:type:`PyLongObject`. |
| 158 | |
| 159 | Raise :exc:`OverflowError` if the value of *obj* is out of range for a |
| 160 | :c:type:`long`. |
| 161 | |
| 162 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 163 | .. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow) |
Mark Dickinson | f0acfee | 2012-06-23 11:14:22 +0100 | [diff] [blame] | 164 | |
| 165 | Return a C :c:type:`long long` representation of *obj*. If *obj* is not an |
| 166 | instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method |
| 167 | (if present) to convert it to a :c:type:`PyLongObject`. |
| 168 | |
| 169 | If the value of *obj* is greater than :const:`PY_LLONG_MAX` or less than |
| 170 | :const:`PY_LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, |
| 171 | and return ``-1``; otherwise, set *\*overflow* to ``0``. If any other |
| 172 | exception occurs set *\*overflow* to ``0`` and return ``-1`` as usual. |
Mark Dickinson | 93f562c | 2010-01-30 10:30:15 +0000 | [diff] [blame] | 173 | |
| 174 | .. versionadded:: 3.2 |
| 175 | |
| 176 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 177 | .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 178 | |
| 179 | .. index:: |
| 180 | single: PY_SSIZE_T_MAX |
| 181 | single: OverflowError (built-in exception) |
| 182 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 183 | Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must |
| 184 | be an instance of :c:type:`PyLongObject`. |
| 185 | |
| 186 | Raise :exc:`OverflowError` if the value of *pylong* is out of range for a |
| 187 | :c:type:`Py_ssize_t`. |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 188 | |
| 189 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 190 | .. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 191 | |
| 192 | .. index:: |
| 193 | single: ULONG_MAX |
| 194 | single: OverflowError (built-in exception) |
| 195 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 196 | Return a C :c:type:`unsigned long` representation of *pylong*. *pylong* |
| 197 | must be an instance of :c:type:`PyLongObject`. |
| 198 | |
| 199 | Raise :exc:`OverflowError` if the value of *pylong* is out of range for a |
| 200 | :c:type:`unsigned long`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 201 | |
| 202 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 203 | .. c:function:: size_t PyLong_AsSize_t(PyObject *pylong) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 204 | |
Terry Jan Reedy | 65e69b3 | 2013-03-11 17:23:46 -0400 | [diff] [blame] | 205 | Return a C :c:type:`size_t` representation of *pylong*. *pylong* must be |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 206 | an instance of :c:type:`PyLongObject`. |
| 207 | |
| 208 | Raise :exc:`OverflowError` if the value of *pylong* is out of range for a |
| 209 | :c:type:`size_t`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 210 | |
| 211 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 212 | .. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 213 | |
Mark Dickinson | 2177607 | 2009-02-10 16:13:25 +0000 | [diff] [blame] | 214 | .. index:: |
| 215 | single: OverflowError (built-in exception) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 216 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 217 | Return a C :c:type:`unsigned long long` representation of *pylong*. *pylong* |
| 218 | must be an instance of :c:type:`PyLongObject`. |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 219 | |
| 220 | Raise :exc:`OverflowError` if the value of *pylong* is out of range for an |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 221 | :c:type:`unsigned long long`. |
Mark Dickinson | 2177607 | 2009-02-10 16:13:25 +0000 | [diff] [blame] | 222 | |
| 223 | .. versionchanged:: 3.1 |
Georg Brandl | 67b21b7 | 2010-08-17 15:07:14 +0000 | [diff] [blame] | 224 | A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`. |
| 225 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 226 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 227 | .. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *obj) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 228 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 229 | Return a C :c:type:`unsigned long` representation of *obj*. If *obj* |
| 230 | is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__` |
| 231 | method (if present) to convert it to a :c:type:`PyLongObject`. |
| 232 | |
| 233 | If the value of *obj* is out of range for an :c:type:`unsigned long`, |
Serhiy Storchaka | 1ecf7d2 | 2016-10-27 21:41:19 +0300 | [diff] [blame] | 234 | return the reduction of that value modulo ``ULONG_MAX + 1``. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 235 | |
| 236 | |
Benjamin Peterson | 47ff073 | 2016-09-08 09:15:54 -0700 | [diff] [blame] | 237 | .. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 238 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 239 | Return a C :c:type:`unsigned long long` representation of *obj*. If *obj* |
| 240 | is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__` |
| 241 | method (if present) to convert it to a :c:type:`PyLongObject`. |
| 242 | |
| 243 | If the value of *obj* is out of range for an :c:type:`unsigned long long`, |
Serhiy Storchaka | 1ecf7d2 | 2016-10-27 21:41:19 +0300 | [diff] [blame] | 244 | return the reduction of that value modulo ``PY_ULLONG_MAX + 1``. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 245 | |
| 246 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 247 | .. c:function:: double PyLong_AsDouble(PyObject *pylong) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 248 | |
Mark Dickinson | b8dc3ab | 2012-06-23 12:12:52 +0100 | [diff] [blame] | 249 | Return a C :c:type:`double` representation of *pylong*. *pylong* must be |
| 250 | an instance of :c:type:`PyLongObject`. |
| 251 | |
| 252 | Raise :exc:`OverflowError` if the value of *pylong* is out of range for a |
| 253 | :c:type:`double`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 254 | |
| 255 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 256 | .. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 257 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 258 | Convert a Python integer *pylong* to a C :c:type:`void` pointer. |
Christian Heimes | c3f30c4 | 2008-02-22 16:37:40 +0000 | [diff] [blame] | 259 | If *pylong* cannot be converted, an :exc:`OverflowError` will be raised. This |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 260 | is only assured to produce a usable :c:type:`void` pointer for values created |
| 261 | with :c:func:`PyLong_FromVoidPtr`. |