summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-08 06:53:51 (GMT)
committerGitHub <noreply@github.com>2017-04-08 06:53:51 (GMT)
commitb879fe82e7e5c3f7673c9a7fa4aad42bd05445d8 (patch)
tree714c168e58166c2acb07b737ce3ca02db71fe2af /Objects
parent205e00c5cfd495a4dc6dae8e8fa0fb828fb3dca9 (diff)
downloadcpython-b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8.zip
cpython-b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8.tar.gz
cpython-b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8.tar.bz2
Expand the PySlice_GetIndicesEx macro. (#1023)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c12
-rw-r--r--Objects/bytesobject.c6
-rw-r--r--Objects/listobject.c10
-rw-r--r--Objects/memoryobject.c4
-rw-r--r--Objects/tupleobject.c6
-rw-r--r--Objects/unicodeobject.c5
6 files changed, 23 insertions, 20 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index fe322d2..22dd810 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -400,11 +400,11 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index)
}
else if (PySlice_Check(index)) {
Py_ssize_t start, stop, step, slicelength, cur, i;
- if (PySlice_GetIndicesEx(index,
- PyByteArray_GET_SIZE(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(index, &start, &stop, &step) < 0) {
return NULL;
}
+ slicelength = PySlice_AdjustIndices(PyByteArray_GET_SIZE(self),
+ &start, &stop, step);
if (slicelength <= 0)
return PyByteArray_FromStringAndSize("", 0);
@@ -630,11 +630,11 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
}
}
else if (PySlice_Check(index)) {
- if (PySlice_GetIndicesEx(index,
- PyByteArray_GET_SIZE(self),
- &start, &stop, &step, &slicelen) < 0) {
+ if (PySlice_Unpack(index, &start, &stop, &step) < 0) {
return -1;
}
+ slicelen = PySlice_AdjustIndices(PyByteArray_GET_SIZE(self), &start,
+ &stop, step);
}
else {
PyErr_Format(PyExc_TypeError,
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index bde7948..e95ab9c 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1683,11 +1683,11 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
char* result_buf;
PyObject* result;
- if (PySlice_GetIndicesEx(item,
- PyBytes_GET_SIZE(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return NULL;
}
+ slicelength = PySlice_AdjustIndices(PyBytes_GET_SIZE(self), &start,
+ &stop, step);
if (slicelength <= 0) {
return PyBytes_FromStringAndSize("", 0);
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 9b42106..314a13c 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2486,10 +2486,11 @@ list_subscript(PyListObject* self, PyObject* item)
PyObject* it;
PyObject **src, **dest;
- if (PySlice_GetIndicesEx(item, Py_SIZE(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return NULL;
}
+ slicelength = PySlice_AdjustIndices(Py_SIZE(self), &start, &stop,
+ step);
if (slicelength <= 0) {
return PyList_New(0);
@@ -2535,10 +2536,11 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, Py_SIZE(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return -1;
}
+ slicelength = PySlice_AdjustIndices(Py_SIZE(self), &start, &stop,
+ step);
if (step == 1)
return list_ass_slice(self, start, stop, value);
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index 8a23163..1b95af2 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -2285,10 +2285,10 @@ init_slice(Py_buffer *base, PyObject *key, int dim)
{
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(key, base->shape[dim],
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(key, &start, &stop, &step) < 0) {
return -1;
}
+ slicelength = PySlice_AdjustIndices(base->shape[dim], &start, &stop, step);
if (base->suboffsets == NULL || dim == 0) {
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 55da0e3..2a90490 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -758,11 +758,11 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
PyObject* it;
PyObject **src, **dest;
- if (PySlice_GetIndicesEx(item,
- PyTuple_GET_SIZE(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return NULL;
}
+ slicelength = PySlice_AdjustIndices(PyTuple_GET_SIZE(self), &start,
+ &stop, step);
if (slicelength <= 0) {
return PyTuple_New(0);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b414571..ef2215f 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13996,10 +13996,11 @@ unicode_subscript(PyObject* self, PyObject* item)
int src_kind, dest_kind;
Py_UCS4 ch, max_char, kind_limit;
- if (PySlice_GetIndicesEx(item, PyUnicode_GET_LENGTH(self),
- &start, &stop, &step, &slicelength) < 0) {
+ if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return NULL;
}
+ slicelength = PySlice_AdjustIndices(PyUnicode_GET_LENGTH(self),
+ &start, &stop, step);
if (slicelength <= 0) {
_Py_RETURN_UNICODE_EMPTY();