mirror of
https://github.com/python/cpython.git
synced 2025-11-12 07:02:33 +00:00
Use Py_ssize_t in slices
This commit is contained in:
parent
b902f4e401
commit
d08eaf4d1b
1 changed files with 5 additions and 5 deletions
|
|
@ -107,20 +107,20 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
|
||||||
*step = 1;
|
*step = 1;
|
||||||
} else {
|
} else {
|
||||||
if (!PyInt_Check(r->step)) return -1;
|
if (!PyInt_Check(r->step)) return -1;
|
||||||
*step = PyInt_AsLong(r->step);
|
*step = PyInt_AsSsize_t(r->step);
|
||||||
}
|
}
|
||||||
if (r->start == Py_None) {
|
if (r->start == Py_None) {
|
||||||
*start = *step < 0 ? length-1 : 0;
|
*start = *step < 0 ? length-1 : 0;
|
||||||
} else {
|
} else {
|
||||||
if (!PyInt_Check(r->start)) return -1;
|
if (!PyInt_Check(r->start)) return -1;
|
||||||
*start = PyInt_AsLong(r->start);
|
*start = PyInt_AsSsize_t(r->start);
|
||||||
if (*start < 0) *start += length;
|
if (*start < 0) *start += length;
|
||||||
}
|
}
|
||||||
if (r->stop == Py_None) {
|
if (r->stop == Py_None) {
|
||||||
*stop = *step < 0 ? -1 : length;
|
*stop = *step < 0 ? -1 : length;
|
||||||
} else {
|
} else {
|
||||||
if (!PyInt_Check(r->stop)) return -1;
|
if (!PyInt_Check(r->stop)) return -1;
|
||||||
*stop = PyInt_AsLong(r->stop);
|
*stop = PyInt_AsSsize_t(r->stop);
|
||||||
if (*stop < 0) *stop += length;
|
if (*stop < 0) *stop += length;
|
||||||
}
|
}
|
||||||
if (*stop > length) return -1;
|
if (*stop > length) return -1;
|
||||||
|
|
@ -252,7 +252,7 @@ slice_indices(PySliceObject* self, PyObject* len)
|
||||||
{
|
{
|
||||||
Py_ssize_t ilen, start, stop, step, slicelength;
|
Py_ssize_t ilen, start, stop, step, slicelength;
|
||||||
|
|
||||||
ilen = PyInt_AsLong(len);
|
ilen = PyInt_AsSsize_t(len);
|
||||||
|
|
||||||
if (ilen == -1 && PyErr_Occurred()) {
|
if (ilen == -1 && PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -263,7 +263,7 @@ slice_indices(PySliceObject* self, PyObject* len)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Py_BuildValue("(iii)", start, stop, step);
|
return Py_BuildValue("(nnn)", start, stop, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(slice_indices_doc,
|
PyDoc_STRVAR(slice_indices_doc,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue