@@ -322,8 +322,15 @@ PyLong_FromDouble(double dval)
322322#define PY_ABS_LONG_MIN (0-(unsigned long)LONG_MIN)
323323#define PY_ABS_SSIZE_T_MIN (0-(size_t)PY_SSIZE_T_MIN)
324324
325- /* Get a C long int from a long int object.
326- Returns -1 and sets an error condition if overflow occurs. */
325+ /* Get a C long int from a long int object or any object that has an __int__
326+ method.
327+
328+ On overflow, return -1 and set *overflow to 1 or -1 depending on the sign of
329+ the result. Otherwise *overflow is 0.
330+
331+ For other errors (e.g., TypeError), return -1 and set an error condition.
332+ In this case *overflow will be 0.
333+ */
327334
328335long
329336PyLong_AsLongAndOverflow (PyObject * vv , int * overflow )
@@ -412,6 +419,9 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
412419 return res ;
413420}
414421
422+ /* Get a C long int from a long int object or any object that has an __int__
423+ method. Return -1 and set an error if overflow occurs. */
424+
415425long
416426PyLong_AsLong (PyObject * obj )
417427{
@@ -923,7 +933,7 @@ _PyLong_AsByteArray(PyLongObject* v,
923933
924934}
925935
926- /* Create a new long (or int) object from a C pointer */
936+ /* Create a new long int object from a C pointer */
927937
928938PyObject *
929939PyLong_FromVoidPtr (void * p )
@@ -941,15 +951,11 @@ PyLong_FromVoidPtr(void *p)
941951
942952}
943953
944- /* Get a C pointer from a long object (or an int object in some cases) */
954+ /* Get a C pointer from a long int object. */
945955
946956void *
947957PyLong_AsVoidPtr (PyObject * vv )
948958{
949- /* This function will allow int or long objects. If vv is neither,
950- then the PyLong_AsLong*() functions will raise the exception:
951- PyExc_SystemError, "bad argument to internal function"
952- */
953959#if SIZEOF_VOID_P <= SIZEOF_LONG
954960 long x ;
955961
@@ -1130,8 +1136,8 @@ PyLong_FromSize_t(size_t ival)
11301136 return (PyObject * )v ;
11311137}
11321138
1133- /* Get a C PY_LONG_LONG int from a long int object.
1134- Return -1 and set an error if overflow occurs. */
1139+ /* Get a C long long int from a long int object or any object that has an
1140+ __int__ method. Return -1 and set an error if overflow occurs. */
11351141
11361142PY_LONG_LONG
11371143PyLong_AsLongLong (PyObject * vv )
@@ -1287,12 +1293,14 @@ PyLong_AsUnsignedLongLongMask(register PyObject *op)
12871293}
12881294#undef IS_LITTLE_ENDIAN
12891295
1290- /* Get a C long long int from a Python long or Python int object.
1291- On overflow, returns -1 and sets *overflow to 1 or -1 depending
1292- on the sign of the result. Otherwise *overflow is 0.
1296+ /* Get a C long long int from a long int object or any object that has an
1297+ __int__ method.
1298+
1299+ On overflow, return -1 and set *overflow to 1 or -1 depending on the sign of
1300+ the result. Otherwise *overflow is 0.
12931301
1294- For other errors (e.g., type error ), returns -1 and sets an error
1295- condition .
1302+ For other errors (e.g., TypeError ), return -1 and set an error condition.
1303+ In this case *overflow will be 0 .
12961304*/
12971305
12981306PY_LONG_LONG
0 commit comments