diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-04-08 11:48:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-08 11:48:57 +0300 |
commit | e41390aca51e4e3eb455cf3b70f5d656a2814db9 (patch) | |
tree | e90f8b0b47ec38d5dc7871b4e5b0f944c46473a4 /Objects | |
parent | 7f85947106aff5b1f166a57f644f987db4d38bf0 (diff) | |
download | cpython-git-e41390aca51e4e3eb455cf3b70f5d656a2814db9.tar.gz |
bpo-27867: Expand the PySlice_GetIndicesEx macro. (#1023) (#1046)
(cherry picked from commit b879fe8)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytearrayobject.c | 12 | ||||
-rw-r--r-- | Objects/listobject.c | 10 | ||||
-rw-r--r-- | Objects/memoryobject.c | 9 | ||||
-rw-r--r-- | Objects/sliceobject.c | 4 | ||||
-rw-r--r-- | Objects/stringobject.c | 6 | ||||
-rw-r--r-- | Objects/structseq.c | 6 | ||||
-rw-r--r-- | Objects/tupleobject.c | 6 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 5 |
8 files changed, 31 insertions, 27 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index c74ff0600c..8c17245266 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -435,11 +435,11 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index) } else if (PySlice_Check(index)) { Py_ssize_t start, stop, step, slicelength, cur, i; - if (PySlice_GetIndicesEx((PySliceObject *)index, - PyByteArray_GET_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)index, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(PyByteArray_GET_SIZE(self), + &start, &stop, step); if (slicelength <= 0) return PyByteArray_FromStringAndSize("", 0); @@ -619,11 +619,11 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu } } else if (PySlice_Check(index)) { - if (PySlice_GetIndicesEx((PySliceObject *)index, - PyByteArray_GET_SIZE(self), - &start, &stop, &step, &slicelen) < 0) { + if (_PySlice_Unpack((PySliceObject *)index, &start, &stop, &step) < 0) { return -1; } + slicelen = _PySlice_AdjustIndices(PyByteArray_GET_SIZE(self), &start, + &stop, step); } else { PyErr_SetString(PyExc_TypeError, "bytearray indices must be integer"); diff --git a/Objects/listobject.c b/Objects/listobject.c index a71df7bd2a..24bb5bbd14 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2562,10 +2562,11 @@ list_subscript(PyListObject* self, PyObject* item) PyObject* it; PyObject **src, **dest; - if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)item, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(Py_SIZE(self), &start, &stop, + step); if (slicelength <= 0) { return PyList_New(0); @@ -2611,10 +2612,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((PySliceObject*)item, Py_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)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 2bac266ea7..12be12b00a 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -584,10 +584,11 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key) else if (PySlice_Check(key)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx((PySliceObject*)key, get_shape0(view), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)key, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(get_shape0(view), &start, &stop, + step); if (step == 1 && view->ndim == 1) { Py_buffer newview; @@ -662,10 +663,10 @@ memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value) else if (PySlice_Check(key)) { Py_ssize_t stop, step; - if (PySlice_GetIndicesEx((PySliceObject*)key, get_shape0(view), - &start, &stop, &step, &len) < 0) { + if (_PySlice_Unpack((PySliceObject *)key, &start, &stop, &step) < 0) { return -1; } + len = _PySlice_AdjustIndices(get_shape0(view), &start, &stop, step); if (step != 1) { PyErr_SetNone(PyExc_NotImplementedError); return -1; diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index ff9479e55b..3ac3811853 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -294,10 +294,10 @@ slice_indices(PySliceObject* self, PyObject* len) return NULL; } - if (PySlice_GetIndicesEx(self, ilen, &start, &stop, - &step, &slicelength) < 0) { + if (_PySlice_Unpack(self, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(ilen, &start, &stop, step); return Py_BuildValue("(nnn)", start, stop, step); } diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 9b93898c1c..ef4f8c1e19 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1310,11 +1310,11 @@ string_subscript(PyStringObject* self, PyObject* item) char* result_buf; PyObject* result; - if (PySlice_GetIndicesEx((PySliceObject*)item, - PyString_GET_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)item, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(PyString_GET_SIZE(self), &start, + &stop, step); if (slicelength <= 0) { return PyString_FromStringAndSize("", 0); diff --git a/Objects/structseq.c b/Objects/structseq.c index 75c1ffb0fa..9b3ba48a88 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -114,11 +114,11 @@ structseq_subscript(PyStructSequence *self, PyObject *item) Py_ssize_t start, stop, step, slicelen, cur, i; PyObject *result; - if (PySlice_GetIndicesEx((PySliceObject *)item, - VISIBLE_SIZE(self), &start, &stop, - &step, &slicelen) < 0) { + if (_PySlice_Unpack((PySliceObject *)item, &start, &stop, &step) < 0) { return NULL; } + slicelen = _PySlice_AdjustIndices(VISIBLE_SIZE(self), &start, &stop, + step); if (slicelen <= 0) return PyTuple_New(0); result = PyTuple_New(slicelen); diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 2495e95e37..808156f714 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -715,11 +715,11 @@ tuplesubscript(PyTupleObject* self, PyObject* item) PyObject* it; PyObject **src, **dest; - if (PySlice_GetIndicesEx((PySliceObject*)item, - PyTuple_GET_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)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 7986d70f67..689529ad8b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8008,10 +8008,11 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item) Py_UNICODE* result_buf; PyObject* result; - if (PySlice_GetIndicesEx((PySliceObject*)item, PyUnicode_GET_SIZE(self), - &start, &stop, &step, &slicelength) < 0) { + if (_PySlice_Unpack((PySliceObject *)item, &start, &stop, &step) < 0) { return NULL; } + slicelength = _PySlice_AdjustIndices(PyUnicode_GET_SIZE(self), &start, + &stop, step); if (slicelength <= 0) { return PyUnicode_FromUnicode(NULL, 0); |