[pypy-commit] cffi default: Test and fix: don't crash if there is a partial enum in the cdef()

arigo noreply at buildbot.pypy.org
Sat Sep 26 09:00:13 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2277:8228937d2afe
Date: 2015-09-26 09:01 +0200
http://bitbucket.org/cffi/cffi/changeset/8228937d2afe/

Log:	Test and fix: don't crash if there is a partial enum in the cdef()
	but we try to access an enum constant from a different enum.

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -631,13 +631,23 @@
         #
         if not copied_enums:
             from . import model
+            error = None
             for key, tp in ffi._parser._declarations.items():
                 if not isinstance(tp, model.EnumType):
                     continue
-                tp.check_not_partial()
+                try:
+                    tp.check_not_partial()
+                except Exception as e:
+                    error = e
+                    continue
                 for enumname, enumval in zip(tp.enumerators, tp.enumvalues):
                     if enumname not in library.__dict__:
                         library.__dict__[enumname] = enumval
+            if error is not None:
+                if name in library.__dict__:
+                    return     # ignore error, about a different enum
+                raise error
+
             for key, val in ffi._parser._int_constants.items():
                 if key not in library.__dict__:
                     library.__dict__[key] = val
diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py
--- a/testing/cffi0/backend_tests.py
+++ b/testing/cffi0/backend_tests.py
@@ -930,8 +930,8 @@
         ffi = FFI(backend=self.Backend())
         ffi.cdef(r"enum foo {A, ...}; enum bar { B, C };")
         lib = ffi.dlopen(None)
+        assert lib.B == 0
         py.test.raises(VerificationMissing, getattr, lib, "A")
-        assert lib.B == 0
         assert lib.C == 1
 
     def test_array_of_struct(self):


More information about the pypy-commit mailing list