mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Stop duplicating code and handle slice indices consistently and correctly
wrt to ssize_t.
This commit is contained in:
parent
90768424f8
commit
badc086543
4 changed files with 25 additions and 44 deletions
|
@ -1127,27 +1127,6 @@ instance_item(PyInstanceObject *inst, Py_ssize_t i)
|
|||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
sliceobj_from_intint(Py_ssize_t i, Py_ssize_t j)
|
||||
{
|
||||
PyObject *start, *end, *res;
|
||||
|
||||
start = PyInt_FromLong((long)i);
|
||||
if (!start)
|
||||
return NULL;
|
||||
|
||||
end = PyInt_FromLong((long)j);
|
||||
if (!end) {
|
||||
Py_DECREF(start);
|
||||
return NULL;
|
||||
}
|
||||
res = PySlice_New(start, end, NULL);
|
||||
Py_DECREF(start);
|
||||
Py_DECREF(end);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
instance_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j)
|
||||
{
|
||||
|
@ -1168,7 +1147,7 @@ instance_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j)
|
|||
func = instance_getattr(inst, getitemstr);
|
||||
if (func == NULL)
|
||||
return NULL;
|
||||
arg = Py_BuildValue("(N)", sliceobj_from_intint(i, j));
|
||||
arg = Py_BuildValue("(N)", _PySlice_FromIndices(i, j));
|
||||
} else
|
||||
arg = Py_BuildValue("(nn)", i, j);
|
||||
|
||||
|
@ -1239,7 +1218,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
|
|||
return -1;
|
||||
|
||||
arg = Py_BuildValue("(N)",
|
||||
sliceobj_from_intint(i, j));
|
||||
_PySlice_FromIndices(i, j));
|
||||
} else
|
||||
arg = Py_BuildValue("(nn)", i, j);
|
||||
}
|
||||
|
@ -1260,7 +1239,7 @@ instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject
|
|||
return -1;
|
||||
|
||||
arg = Py_BuildValue("(NO)",
|
||||
sliceobj_from_intint(i, j), value);
|
||||
_PySlice_FromIndices(i, j), value);
|
||||
} else
|
||||
arg = Py_BuildValue("(nnO)", i, j, value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue