diff -r a206f952668e Objects/sliceobject.c --- a/Objects/sliceobject.c Thu Aug 08 18:28:53 2013 +0100 +++ b/Objects/sliceobject.c Thu Aug 22 23:04:23 2013 +0200 @@ -180,20 +180,23 @@ int PySlice_GetIndicesEx(PyObject *_r, Py_ssize_t length, - Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, - Py_ssize_t *slicelength) + Py_ssize_t *_start, Py_ssize_t *_stop, Py_ssize_t *_step, + Py_ssize_t *_slicelength) { PySliceObject *r = (PySliceObject*)_r; /* this is harder to get right than you might think */ Py_ssize_t defstart, defstop; + /* work with locals so that optimization isn't hindered by aliasing concerns */ + Py_ssize_t start, stop, step, astep, slicelength; + if (r->step == Py_None) { - *step = 1; + step = 1; } else { - if (!_PyEval_SliceIndex(r->step, step)) return -1; - if (*step == 0) { + if (!_PyEval_SliceIndex(r->step, &step)) return -1; + if (step == 0) { PyErr_SetString(PyExc_ValueError, "slice step cannot be zero"); return -1; @@ -203,46 +206,51 @@ * guards against later undefined behaviour resulting from code that * does "step = -step" as part of a slice reversal. */ - if (*step < -PY_SSIZE_T_MAX) - *step = -PY_SSIZE_T_MAX; + if (step < -PY_SSIZE_T_MAX) + step = -PY_SSIZE_T_MAX; } - defstart = *step < 0 ? length-1 : 0; - defstop = *step < 0 ? -1 : length; + defstart = step < 0 ? length-1 : 0; + defstop = step < 0 ? -1 : length; if (r->start == Py_None) { - *start = defstart; + start = defstart; } else { - if (!_PyEval_SliceIndex(r->start, start)) return -1; - if (*start < 0) *start += length; - if (*start < 0) *start = (*step < 0) ? -1 : 0; - if (*start >= length) - *start = (*step < 0) ? length - 1 : length; + if (!_PyEval_SliceIndex(r->start, &start)) return -1; + if (start < 0) start += length; + if (start < 0) start = (step < 0) ? -1 : 0; + if (start >= length) + start = (step < 0) ? length - 1 : length; } if (r->stop == Py_None) { - *stop = defstop; + stop = defstop; } else { - if (!_PyEval_SliceIndex(r->stop, stop)) return -1; - if (*stop < 0) *stop += length; - if (*stop < 0) *stop = (*step < 0) ? -1 : 0; - if (*stop >= length) - *stop = (*step < 0) ? length - 1 : length; + if (!_PyEval_SliceIndex(r->stop, &stop)) return -1; + if (stop < 0) stop += length; + if (stop < 0) stop = (step < 0) ? -1 : 0; + if (stop >= length) + stop = (step < 0) ? length - 1 : length; } - if ((*step < 0 && *stop >= *start) - || (*step > 0 && *start >= *stop)) { - *slicelength = 0; + if ((step < 0 && stop >= start) + || (step > 0 && start >= stop)) { + slicelength = 0; } - else if (*step < 0) { - *slicelength = (*stop-*start+1)/(*step)+1; + else if (step < 0) { + slicelength = (stop-start+1)/step+1; } else { - *slicelength = (*stop-*start-1)/(*step)+1; + slicelength = (stop-start-1)/step+1; } + *_start = start; + *_stop = stop; + *_step = step; + *_slicelength = slicelength; + return 0; }