aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-03-23 06:03:08 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-03-23 06:03:08 +0000
commitbadc086543e13be82958b8162d3fc5e5b65f283a (patch)
tree7c65ec8f0a8dc2482b55952a8f79b6ef877b71dd /Objects/sliceobject.c
parentFix a ssize_t issue (diff)
downloadcpython-badc086543e13be82958b8162d3fc5e5b65f283a.tar.gz
cpython-badc086543e13be82958b8162d3fc5e5b65f283a.tar.bz2
cpython-badc086543e13be82958b8162d3fc5e5b65f283a.zip
Stop duplicating code and handle slice indices consistently and correctly
wrt to ssize_t.
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 3b37dbb40bb..ed00ce402e9 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -79,6 +79,25 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
return (PyObject *) obj;
}
+PyObject *
+_PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
+{
+ PyObject *start, *end, *slice;
+ start = PyInt_FromSsize_t(istart);
+ if (!start)
+ return NULL;
+ end = PyInt_FromSsize_t(istop);
+ if (!end) {
+ Py_DECREF(start);
+ return NULL;
+ }
+
+ slice = PySlice_New(start, end, NULL);
+ Py_DECREF(start);
+ Py_DECREF(end);
+ return slice;
+}
+
int
PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)