@@ -108,26 +108,29 @@ All integers are implemented as "long" integer objects of arbitrary size.
108
108
109
109
110
110
.. XXX alias PyLong_AS_LONG (for now)
111
- .. c :function :: long PyLong_AsLong (PyObject *pylong )
111
+ .. c :function :: long PyLong_AsLong (PyObject *obj )
112
112
113
113
.. index ::
114
114
single: LONG_MAX
115
115
single: OverflowError (built-in exception)
116
116
117
- Return a C :c:type:`long` representation of the contents of *pylong*. If
118
- *pylong* is greater than :const :`LONG_MAX`, raise an :exc:`OverflowError`,
119
- and return -1. Convert non-long objects automatically to long first,
120
- and return -1 if that raises exceptions.
117
+ Return a C :c:type:`long` representation of *obj*. If *obj* is not an
118
+ instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method
119
+ (if present) to convert it to a :c:type:`PyLongObject`.
121
120
122
- .. c:function:: long PyLong_AsLongAndOverflow(PyObject *pylong, int *overflow)
121
+ Raise :exc:`OverflowError` if the value of *obj* is out of range for a
122
+ :c:type:`long`.
123
123
124
- Return a C :c:type: `long ` representation of the contents of
125
- *pylong *. If *pylong * is greater than :const: `LONG_MAX ` or less
126
- than :const: `LONG_MIN `, set *\* overflow * to ``1 `` or ``-1 ``,
127
- respectively, and return ``-1 ``; otherwise, set *\* overflow * to
128
- ``0 ``. If any other exception occurs (for example a TypeError or
129
- MemoryError), then ``-1`` will be returned and *\*overflow* will
130
- be ``0``.
124
+ .. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow)
125
+
126
+ Return a C :c:type: `long ` representation of *obj *. If *obj * is not an
127
+ instance of :c:type: `PyLongObject `, first call its :meth: `__int__ ` method
128
+ (if present) to convert it to a :c:type:`PyLongObject`.
129
+
130
+ If the value of *obj* is greater than :const :`LONG_MAX` or less than
131
+ :const :`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and
132
+ return ``-1``; otherwise, set *\*overflow* to ``0 ``. If any other exception
133
+ occurs set *\* overflow * to ``0 `` and return ``-1 `` as usual.
131
134
132
135
133
136
.. c :function :: PY_LONG_LONG PyLong_AsLongLongAndOverflow (PyObject *pylong, int *overflow)
0 commit comments