Skip to content

Commit 8d48b43

Browse files
committed
Issue #12965: Fix some inaccurate comments in Objects/longobject.c. Thanks Stefan Krah.
1 parent 30970e9 commit 8d48b43

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

Objects/longobject.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

328335
long
329336
PyLong_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+
415425
long
416426
PyLong_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

928938
PyObject *
929939
PyLong_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

946956
void *
947957
PyLong_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

11361142
PY_LONG_LONG
11371143
PyLong_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

12981306
PY_LONG_LONG

0 commit comments

Comments
 (0)