[pypy-commit] cffi cffi-1.0: Fix for a crash found by running test_open_array_in_struct in a debug

arigo noreply at buildbot.pypy.org
Sat Apr 18 13:57:37 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1756:c880c45d083e
Date: 2015-04-18 13:58 +0200
http://bitbucket.org/cffi/cffi/changeset/c880c45d083e/

Log:	Fix for a crash found by running test_open_array_in_struct in a
	debug version of python. Then fix another test to account for the
	fix.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2844,6 +2844,10 @@
         if (ctitem->ct_flags & CT_PRIMITIVE_CHAR)
             datasize *= 2;   /* forcefully add another character: a null */
 
+        if (ctitem->ct_flags & (CT_STRUCT | CT_UNION)) {
+            if (force_lazy_struct(ctitem) < 0)   /* for CT_WITH_VAR_ARRAY */
+                return NULL;
+        }
         if ((ctitem->ct_flags & CT_WITH_VAR_ARRAY) && init != Py_None) {
             Py_ssize_t optvarsize = datasize;
             if (convert_struct_from_object(NULL,ctitem, init, &optvarsize) < 0)
diff --git a/new/test_recompiler.py b/new/test_recompiler.py
--- a/new/test_recompiler.py
+++ b/new/test_recompiler.py
@@ -258,8 +258,8 @@
     verify(ffi, 'test_misdeclared_field_1',
            "struct foo_s { int a[6]; };")
     assert ffi.sizeof("struct foo_s") == 24  # found by the actual C code
-    p = ffi.new("struct foo_s *")
-    e = py.test.raises(ffi.error, "p.a")     # lazily build the fields and boom
+    # lazily build the fields and boom:
+    e = py.test.raises(ffi.error, ffi.new, "struct foo_s *")
     assert str(e.value) == ("struct foo_s field 'a' was declared in the "
                             "cdef to be 20 bytes, but is actually 24 bytes")
 


More information about the pypy-commit mailing list