summaryrefslogtreecommitdiff
path: root/numpy/core/include
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2016-02-09 00:36:28 -0800
committerNathaniel J. Smith <njs@pobox.com>2016-02-09 16:31:29 -0800
commit925473229f9594046dc5e5a38d93103edd57f41b (patch)
tree5580a1f3d1fbfc2debc0253c3437a22d67d37bbf /numpy/core/include
parent553137119d219d21229ec407b32d85e590d2a0c1 (diff)
downloadnumpy-925473229f9594046dc5e5a38d93103edd57f41b.tar.gz
MAINT: Use PySlice_GetIndicesEx instead of custom reimplementation
This has the side effects of: - changing several IndexError exceptions into TypeErrors - allowing slices like `arr[False:True]` as equivalent to `arr[0:1]` (because now we're using Python's logic for interpreting slices, and Python is happy with treating bools as integers in integer contexts). It also deletes almost 100 lines of code :-). While I was at it I also cleaned up some buggy uses of PySlice_GetIndices (which is pretty broken -- e.g. the code was assuming that it sets an exception on error, but this is not true! the Python docs explicitly recommend that you never use it.)
Diffstat (limited to 'numpy/core/include')
-rw-r--r--numpy/core/include/numpy/npy_3kcompat.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/numpy/core/include/numpy/npy_3kcompat.h b/numpy/core/include/numpy/npy_3kcompat.h
index db60a312c..cdab1bbe8 100644
--- a/numpy/core/include/numpy/npy_3kcompat.h
+++ b/numpy/core/include/numpy/npy_3kcompat.h
@@ -53,6 +53,14 @@ static NPY_INLINE int PyInt_Check(PyObject *op) {
*/
#endif /* NPY_PY3K */
+/* Py3 changes PySlice_GetIndicesEx' first argument's type to PyObject* */
+#ifdef NPY_PY3K
+# define NpySlice_GetIndicesEx PySlice_GetIndicesEx
+#else
+# define NpySlice_GetIndicesEx(op, nop, start, end, step, slicelength) \
+ PySlice_GetIndicesEx((PySliceObject *)op, nop, start, end, step, slicelength)
+#endif
+
/*
* PyString -> PyBytes
*/