Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _longobjects: |
| 4 | |
| 5 | Long Integer Objects |
| 6 | -------------------- |
| 7 | |
| 8 | .. index:: object: long integer |
| 9 | |
| 10 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 11 | .. c:type:: PyLongObject |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 12 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 13 | This subtype of :c:type:`PyObject` represents a Python long integer object. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 14 | |
| 15 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 16 | .. c:var:: PyTypeObject PyLong_Type |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 17 | |
| 18 | .. index:: single: LongType (in modules types) |
| 19 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 20 | This instance of :c:type:`PyTypeObject` represents the Python long integer type. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 21 | This is the same object as ``long`` and ``types.LongType``. |
| 22 | |
| 23 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 24 | .. c:function:: int PyLong_Check(PyObject *p) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 25 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 26 | Return true if its argument is a :c:type:`PyLongObject` or a subtype of |
| 27 | :c:type:`PyLongObject`. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 28 | |
| 29 | .. versionchanged:: 2.2 |
| 30 | Allowed subtypes to be accepted. |
| 31 | |
| 32 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 33 | .. c:function:: int PyLong_CheckExact(PyObject *p) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 34 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 35 | Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of |
| 36 | :c:type:`PyLongObject`. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 37 | |
| 38 | .. versionadded:: 2.2 |
| 39 | |
| 40 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 41 | .. c:function:: PyObject* PyLong_FromLong(long v) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 42 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 43 | Return a new :c:type:`PyLongObject` object from *v*, or *NULL* on failure. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 44 | |
| 45 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 46 | .. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 47 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 48 | Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long`, or |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 49 | *NULL* on failure. |
| 50 | |
| 51 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 52 | .. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v) |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 53 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 54 | Return a new :c:type:`PyLongObject` object from a C :c:type:`Py_ssize_t`, or |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 55 | *NULL* on failure. |
| 56 | |
Georg Brandl | 74c018a | 2009-03-31 15:46:30 +0000 | [diff] [blame] | 57 | .. versionadded:: 2.6 |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 58 | |
| 59 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 60 | .. c:function:: PyObject* PyLong_FromSize_t(size_t v) |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 61 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 62 | Return a new :c:type:`PyLongObject` object from a C :c:type:`size_t`, or |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 63 | *NULL* on failure. |
| 64 | |
Georg Brandl | 74c018a | 2009-03-31 15:46:30 +0000 | [diff] [blame] | 65 | .. versionadded:: 2.6 |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 66 | |
| 67 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 68 | .. c:function:: PyObject* PyLong_FromSsize_t(Py_ssize_t v) |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 69 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 70 | Return a new :c:type:`PyLongObject` object with a value of *v*, or *NULL* |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 71 | on failure. |
| 72 | |
| 73 | .. versionadded:: 2.6 |
| 74 | |
| 75 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 76 | .. c:function:: PyObject* PyLong_FromSize_t(size_t v) |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 77 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 78 | Return a new :c:type:`PyLongObject` object with a value of *v*, or *NULL* |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 79 | on failure. |
| 80 | |
| 81 | .. versionadded:: 2.6 |
| 82 | |
| 83 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 84 | .. c:function:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 85 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 86 | Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL* |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 87 | on failure. |
| 88 | |
| 89 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 90 | .. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 91 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 92 | Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`, |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 93 | or *NULL* on failure. |
| 94 | |
| 95 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 96 | .. c:function:: PyObject* PyLong_FromDouble(double v) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 97 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 98 | Return a new :c:type:`PyLongObject` object from the integer part of *v*, or |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 99 | *NULL* on failure. |
| 100 | |
| 101 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 102 | .. c:function:: PyObject* PyLong_FromString(char *str, char **pend, int base) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 103 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 104 | Return a new :c:type:`PyLongObject` based on the string value in *str*, which is |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 105 | interpreted according to the radix in *base*. If *pend* is non-*NULL*, |
Ezio Melotti | 91d26b4 | 2010-01-30 13:27:05 +0000 | [diff] [blame] | 106 | *\*pend* will point to the first character in *str* which follows the |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 107 | representation of the number. If *base* is ``0``, the radix will be determined |
| 108 | based on the leading characters of *str*: if *str* starts with ``'0x'`` or |
| 109 | ``'0X'``, radix 16 will be used; if *str* starts with ``'0'``, radix 8 will be |
| 110 | used; otherwise radix 10 will be used. If *base* is not ``0``, it must be |
| 111 | between ``2`` and ``36``, inclusive. Leading spaces are ignored. If there are |
| 112 | no digits, :exc:`ValueError` will be raised. |
| 113 | |
| 114 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 115 | .. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 116 | |
| 117 | Convert a sequence of Unicode digits to a Python long integer value. The first |
| 118 | parameter, *u*, points to the first character of the Unicode string, *length* |
| 119 | gives the number of characters, and *base* is the radix for the conversion. The |
| 120 | radix must be in the range [2, 36]; if it is out of range, :exc:`ValueError` |
| 121 | will be raised. |
| 122 | |
| 123 | .. versionadded:: 1.6 |
| 124 | |
Jeroen Ruigrok van der Werven | 089c5cd | 2009-04-25 17:59:03 +0000 | [diff] [blame] | 125 | .. versionchanged:: 2.5 |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 126 | This function used an :c:type:`int` for *length*. This might require |
Jeroen Ruigrok van der Werven | 089c5cd | 2009-04-25 17:59:03 +0000 | [diff] [blame] | 127 | changes in your code for properly supporting 64-bit systems. |
| 128 | |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 129 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 130 | .. c:function:: PyObject* PyLong_FromVoidPtr(void *p) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 131 | |
| 132 | Create a Python integer or long integer from the pointer *p*. The pointer value |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 133 | can be retrieved from the resulting value using :c:func:`PyLong_AsVoidPtr`. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 134 | |
| 135 | .. versionadded:: 1.5.2 |
| 136 | |
| 137 | .. versionchanged:: 2.5 |
| 138 | If the integer is larger than LONG_MAX, a positive long integer is returned. |
| 139 | |
| 140 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 141 | .. c:function:: long PyLong_AsLong(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 142 | |
| 143 | .. index:: |
| 144 | single: LONG_MAX |
| 145 | single: OverflowError (built-in exception) |
| 146 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 147 | Return a C :c:type:`long` representation of the contents of *pylong*. If |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 148 | *pylong* is greater than :const:`LONG_MAX`, an :exc:`OverflowError` is raised |
Georg Brandl | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 149 | and ``-1`` will be returned. |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 150 | |
| 151 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 152 | .. c:function:: long PyLong_AsLongAndOverflow(PyObject *pylong, int *overflow) |
Mark Dickinson | e31d300 | 2009-12-21 11:21:25 +0000 | [diff] [blame] | 153 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 154 | Return a C :c:type:`long` representation of the contents of |
Mark Dickinson | e31d300 | 2009-12-21 11:21:25 +0000 | [diff] [blame] | 155 | *pylong*. If *pylong* is greater than :const:`LONG_MAX` or less |
Ezio Melotti | 91d26b4 | 2010-01-30 13:27:05 +0000 | [diff] [blame] | 156 | than :const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, |
| 157 | respectively, and return ``-1``; otherwise, set *\*overflow* to |
Mark Dickinson | e31d300 | 2009-12-21 11:21:25 +0000 | [diff] [blame] | 158 | ``0``. If any other exception occurs (for example a TypeError or |
Ezio Melotti | 91d26b4 | 2010-01-30 13:27:05 +0000 | [diff] [blame] | 159 | MemoryError), then ``-1`` will be returned and *\*overflow* will |
Mark Dickinson | e31d300 | 2009-12-21 11:21:25 +0000 | [diff] [blame] | 160 | be ``0``. |
| 161 | |
| 162 | .. versionadded:: 2.7 |
| 163 | |
| 164 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 165 | .. c:function:: PY_LONG_LONG PyLong_AsLongLongAndOverflow(PyObject *pylong, int *overflow) |
Mark Dickinson | a36507c | 2010-01-30 10:08:33 +0000 | [diff] [blame] | 166 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 167 | Return a C :c:type:`long long` representation of the contents of |
Mark Dickinson | a36507c | 2010-01-30 10:08:33 +0000 | [diff] [blame] | 168 | *pylong*. If *pylong* is greater than :const:`PY_LLONG_MAX` or less |
Ezio Melotti | 91d26b4 | 2010-01-30 13:27:05 +0000 | [diff] [blame] | 169 | than :const:`PY_LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, |
| 170 | respectively, and return ``-1``; otherwise, set *\*overflow* to |
Mark Dickinson | a36507c | 2010-01-30 10:08:33 +0000 | [diff] [blame] | 171 | ``0``. If any other exception occurs (for example a TypeError or |
Ezio Melotti | 91d26b4 | 2010-01-30 13:27:05 +0000 | [diff] [blame] | 172 | MemoryError), then ``-1`` will be returned and *\*overflow* will |
Mark Dickinson | a36507c | 2010-01-30 10:08:33 +0000 | [diff] [blame] | 173 | be ``0``. |
| 174 | |
| 175 | .. versionadded:: 2.7 |
| 176 | |
| 177 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 178 | .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 179 | |
| 180 | .. index:: |
| 181 | single: PY_SSIZE_T_MAX |
| 182 | single: OverflowError (built-in exception) |
| 183 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 184 | Return a C :c:type:`Py_ssize_t` representation of the contents of *pylong*. If |
Georg Brandl | 78b3ee8 | 2008-04-26 18:31:07 +0000 | [diff] [blame] | 185 | *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is raised |
| 186 | and ``-1`` will be returned. |
| 187 | |
Georg Brandl | 74c018a | 2009-03-31 15:46:30 +0000 | [diff] [blame] | 188 | .. versionadded:: 2.6 |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 189 | |
| 190 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 191 | .. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 192 | |
| 193 | .. index:: |
| 194 | single: ULONG_MAX |
| 195 | single: OverflowError (built-in exception) |
| 196 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 197 | Return a C :c:type:`unsigned long` representation of the contents of *pylong*. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 198 | If *pylong* is greater than :const:`ULONG_MAX`, an :exc:`OverflowError` is |
| 199 | raised. |
| 200 | |
| 201 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 202 | .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 203 | |
| 204 | .. index:: |
| 205 | single: PY_SSIZE_T_MAX |
| 206 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 207 | Return a :c:type:`Py_ssize_t` representation of the contents of *pylong*. If |
Georg Brandl | 79cdff0 | 2010-10-17 10:54:57 +0000 | [diff] [blame] | 208 | *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is |
| 209 | raised. |
| 210 | |
| 211 | .. versionadded:: 2.6 |
| 212 | |
| 213 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 214 | .. c:function:: PY_LONG_LONG PyLong_AsLongLong(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 215 | |
Mark Dickinson | 4015f62 | 2009-02-10 15:46:50 +0000 | [diff] [blame] | 216 | .. index:: |
| 217 | single: OverflowError (built-in exception) |
| 218 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 219 | Return a C :c:type:`long long` from a Python long integer. If |
| 220 | *pylong* cannot be represented as a :c:type:`long long`, an |
Mark Dickinson | 4015f62 | 2009-02-10 15:46:50 +0000 | [diff] [blame] | 221 | :exc:`OverflowError` is raised and ``-1`` is returned. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 222 | |
| 223 | .. versionadded:: 2.2 |
| 224 | |
| 225 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 226 | .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 227 | |
Mark Dickinson | 4015f62 | 2009-02-10 15:46:50 +0000 | [diff] [blame] | 228 | .. index:: |
| 229 | single: OverflowError (built-in exception) |
| 230 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 231 | Return a C :c:type:`unsigned long long` from a Python long integer. If |
| 232 | *pylong* cannot be represented as an :c:type:`unsigned long long`, an |
Mark Dickinson | 4015f62 | 2009-02-10 15:46:50 +0000 | [diff] [blame] | 233 | :exc:`OverflowError` is raised and ``(unsigned long long)-1`` is |
| 234 | returned. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 235 | |
| 236 | .. versionadded:: 2.2 |
| 237 | |
Mark Dickinson | 4015f62 | 2009-02-10 15:46:50 +0000 | [diff] [blame] | 238 | .. versionchanged:: 2.7 |
| 239 | A negative *pylong* now raises :exc:`OverflowError`, not |
| 240 | :exc:`TypeError`. |
| 241 | |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 242 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 243 | .. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 244 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 245 | Return a C :c:type:`unsigned long` from a Python long integer, without checking |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 246 | for overflow. |
| 247 | |
| 248 | .. versionadded:: 2.3 |
| 249 | |
| 250 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 251 | .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 252 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 253 | Return a C :c:type:`unsigned long long` from a Python long integer, without |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 254 | checking for overflow. |
| 255 | |
| 256 | .. versionadded:: 2.3 |
| 257 | |
| 258 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 259 | .. c:function:: double PyLong_AsDouble(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 260 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 261 | Return a C :c:type:`double` representation of the contents of *pylong*. If |
| 262 | *pylong* cannot be approximately represented as a :c:type:`double`, an |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 263 | :exc:`OverflowError` exception is raised and ``-1.0`` will be returned. |
| 264 | |
| 265 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 266 | .. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong) |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 267 | |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 268 | Convert a Python integer or long integer *pylong* to a C :c:type:`void` pointer. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 269 | If *pylong* cannot be converted, an :exc:`OverflowError` will be raised. This |
Sandro Tosi | 98ed08f | 2012-01-14 16:42:02 +0100 | [diff] [blame] | 270 | is only assured to produce a usable :c:type:`void` pointer for values created |
| 271 | with :c:func:`PyLong_FromVoidPtr`. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 272 | |
| 273 | .. versionadded:: 1.5.2 |
| 274 | |
| 275 | .. versionchanged:: 2.5 |
Georg Brandl | 907a720 | 2008-02-22 12:31:45 +0000 | [diff] [blame] | 276 | For values outside 0..LONG_MAX, both signed and unsigned integers are accepted. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 277 | |
| 278 | |