Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb479e7

Browse files
committed
_PyEval_SliceIndex(): Repaired the comments, and added XXX comments
about its dubious treatment of NULL (also opened a bug report on that, but don't want to risk changing it this late in the 2.2 game).
1 parent 0c0b530 commit cb479e7

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Python/ceval.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,14 +3328,18 @@ loop_subscript(PyObject *v, PyObject *w)
33283328
return NULL;
33293329
}
33303330

3331-
/* Extract a slice index from a PyInt or PyLong, the index is bound to
3332-
the range [-INT_MAX+1, INTMAX]. Returns 0 and an exception if there is
3333-
and error. Returns 1 on success.*/
3334-
3331+
/* Extract a slice index from a PyInt or PyLong, and store in *pi.
3332+
Silently reduce values larger than INT_MAX to INT_MAX, and silently
3333+
boost values less than -INT_MAX to 0. Return 0 on error, 1 on success.
3334+
*/
3335+
/* XXX If v is NULL, this goes out of its way to indicate success(!), but
3336+
XXX doesn't store into *pi. Why isn't that an error, or at least v!=NULL
3337+
XXX an asserted precondition?
3338+
*/
33353339
int
33363340
_PyEval_SliceIndex(PyObject *v, int *pi)
33373341
{
3338-
if (v != NULL) {
3342+
if (v != NULL) { /* XXX why isn't this assert(v != NULL()? */
33393343
long x;
33403344
if (PyInt_Check(v)) {
33413345
x = PyInt_AsLong(v);
@@ -3362,7 +3366,8 @@ _PyEval_SliceIndex(PyObject *v, int *pi)
33623366

33633367
/* Create a long integer with a value of 0 */
33643368
long_zero = PyLong_FromLong(0L);
3365-
if (long_zero == NULL) return 0;
3369+
if (long_zero == NULL)
3370+
return 0;
33663371

33673372
/* Check sign */
33683373
cmp = PyObject_RichCompareBool(v, long_zero,

0 commit comments

Comments
 (0)