[pypy-commit] cffi verifier2: test_nonfull_enum

arigo noreply at buildbot.pypy.org
Fri Jul 27 15:35:51 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: verifier2
Changeset: r716:7ea9106ea5b9
Date: 2012-07-27 15:29 +0200
http://bitbucket.org/cffi/cffi/changeset/7ea9106ea5b9/

Log:	test_nonfull_enum

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -516,9 +516,8 @@
     _generate_cpy_constant_method = _generate_nothing
     _loading_cpy_constant = _loaded_noop
 
-    def _loaded_cpy_constant(self, tp, name, module, library):
+    def _load_constant(self, is_int, tp, name, module):
         funcname = '_cffi_const_%s' % name
-        is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type()
         if is_int:
             BFunc = self.ffi.typeof("int(*)(long long*)")
             function = module.load_function(BFunc, funcname)
@@ -534,6 +533,11 @@
             p = self.ffi.new(tppname)
             function(p)
             value = p[0]
+        return value
+
+    def _loaded_cpy_constant(self, tp, name, module, library):
+        is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type()
+        value = self._load_constant(is_int, tp, name, module)
         setattr(library, name, value)
 
     # ----------
@@ -542,7 +546,7 @@
     def _generate_cpy_enum_decl(self, tp, name):
         if tp.partial:
             for enumerator in tp.enumerators:
-                self._generate_cpy_const(True, enumerator, delayed=False)
+                self._generate_cpy_const(True, enumerator)
             return
         #
         funcname = '_cffi_enum_%s' % name
@@ -569,7 +573,7 @@
 
     def _loading_cpy_enum(self, tp, name, module):
         if tp.partial:
-            enumvalues = [getattr(module, enumerator)
+            enumvalues = [self._load_constant(True, tp, enumerator, module)
                           for enumerator in tp.enumerators]
             tp.enumvalues = tuple(enumvalues)
             tp.partial = False


More information about the pypy-commit mailing list