[pypy-commit] cffi slicing: Check error paths

arigo noreply at buildbot.pypy.org
Sun Feb 10 15:27:40 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: slicing
Changeset: r1136:8e01f5212871
Date: 2013-02-10 14:57 +0100
http://bitbucket.org/cffi/cffi/changeset/8e01f5212871/

Log:	Check error paths

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1760,8 +1760,7 @@
         }
         if (stop >= get_array_length(cd)) {
             PyErr_Format(PyExc_IndexError,
-                         "index too large for cdata '%s' (expected %zd < %zd)",
-                         cd->c_type->ct_name,
+                         "index too large (expected %zd < %zd)",
                          stop, get_array_length(cd));
             return NULL;
         }
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2609,3 +2609,20 @@
     py.test.raises(IndexError, "c[-1:1]")
     cp = c + 0
     cp[-1:1]
+
+def test_nonstandard_slice():
+    BIntP = new_pointer_type(new_primitive_type("int"))
+    BIntArray = new_array_type(BIntP, None)
+    c = newp(BIntArray, 5)
+    e = py.test.raises(IndexError, "c[:5]")
+    assert str(e.value) == "slice start must be specified"
+    e = py.test.raises(IndexError, "c[4:]")
+    assert str(e.value) == "slice stop must be specified"
+    e = py.test.raises(IndexError, "c[1:2:3]")
+    assert str(e.value) == "slice with step not supported"
+    e = py.test.raises(IndexError, "c[1:2:1]")
+    assert str(e.value) == "slice with step not supported"
+    e = py.test.raises(IndexError, "c[4:2]")
+    assert str(e.value) == "slice start > stop"
+    e = py.test.raises(IndexError, "c[6:6]")
+    assert str(e.value) == "index too large (expected 6 < 5)"


More information about the pypy-commit mailing list