[pypy-commit] cffi cffi-1.0: test and fix

arigo noreply at buildbot.pypy.org
Tue May 12 16:14:40 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1994:42b3895b68e8
Date: 2015-05-12 16:10 +0200
http://bitbucket.org/cffi/cffi/changeset/42b3895b68e8/

Log:	test and fix

diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -4,7 +4,7 @@
 
 
 class GlobalExpr:
-    def __init__(self, name, address, type_op, size=0, check_value=0):
+    def __init__(self, name, address, type_op, size=0, check_value=None):
         self.name = name
         self.address = address
         self.type_op = type_op
@@ -16,6 +16,11 @@
             self.name, self.address, self.type_op.as_c_expr(), self.size)
 
     def as_python_expr(self):
+        if self.check_value is None:
+            raise ffiplatform.VerificationError(
+                "ffi.dlopen() will not be able to figure out the value of "
+                "constant %r (only integer constants are supported, and only "
+                "if their value are specified in the cdef)" % (self.name,))
         return "b'%s%s',%d" % (self.type_op.as_bytes(), self.name,
                                self.check_value)
 
@@ -592,7 +597,7 @@
             meth_kind = OP_CPYTHON_BLTN_V   # 'METH_VARARGS'
         self._lsts["global"].append(
             GlobalExpr(name, '_cffi_f_%s' % name,
-                       CffiOp(meth_kind, type_index)))
+                       CffiOp(meth_kind, type_index), check_value=0))
 
     # ----------
     # named structs or unions
diff --git a/testing/cffi1/test_dlopen.py b/testing/cffi1/test_dlopen.py
--- a/testing/cffi1/test_dlopen.py
+++ b/testing/cffi1/test_dlopen.py
@@ -1,5 +1,5 @@
 import py
-from cffi import FFI
+from cffi import FFI, VerificationError
 from cffi.recompiler import make_py_source
 from testing.udir import udir
 
@@ -17,3 +17,14 @@
     _globals = (b'\xFF\xFF\xFF\x1FBB',42,b'\x00\x00\x00\x23close',0),
 )
 """
+
+def test_invalid_global_constant():
+    ffi = FFI()
+    ffi.cdef("static const int BB;")
+    target = udir.join('test_invalid_global_constants.py')
+    e = py.test.raises(VerificationError, make_py_source, ffi,
+                       'test_invalid_global_constants', str(target))
+    assert str(e.value) == (
+        "ffi.dlopen() will not be able to figure out "
+        "the value of constant 'BB' (only integer constants are "
+        "supported, and only if their value are specified in the cdef)")


More information about the pypy-commit mailing list