[pypy-commit] pypy ffi-backend: Port the test from CFFI.

arigo noreply at buildbot.pypy.org
Sun Aug 5 09:47:06 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56579:ef071901718f
Date: 2012-08-05 09:46 +0200
http://bitbucket.org/pypy/pypy/changeset/ef071901718f/

Log:	Port the test from CFFI.

diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -69,7 +69,7 @@
         if i < 0:
             raise OperationError(space.w_IndexError,
                                  space.wrap("negative index not supported"))
-        if i >= w_cdata.get_array_length():
+        if self.length != 0 and i >= w_cdata.get_array_length():
             raise operationerrfmt(space.w_IndexError,
                 "index too large for cdata '%s' (expected %d < %d)",
                 self.name, i, w_cdata.get_array_length())
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1827,3 +1827,16 @@
         if not py_py:
             assert repr(x).endswith("E+902>")
             assert float(x) == float("inf")
+
+def test_array_of_length_zero():
+    p = new_pointer_type(new_primitive_type("int"))
+    p0 = new_array_type(p, 0)
+    p3 = new_array_type(p, 3)
+    a1 = newp(p3, [61, 62, 63])
+    a2 = cast(p0, a1)
+    assert a2[0] == 61
+    assert a2[1] == 62
+    assert a2[2] == 63
+    a2[2] = 64
+    assert list(a1) == [61, 62, 64]
+    assert list(a2) == []


More information about the pypy-commit mailing list