[pypy-commit] cffi default: Better compatibility: detect if we have an old cffi running a new ABI

arigo noreply at buildbot.pypy.org
Thu May 28 21:00:24 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2127:4d3306c3afcc
Date: 2015-05-28 21:01 +0200
http://bitbucket.org/cffi/cffi/changeset/4d3306c3afcc/

Log:	Better compatibility: detect if we have an old cffi running a new
	ABI mode script that makes use of the new OP_CONSTANT feature ---
	now renamed to OP_DLOPEN_CONST.

diff --git a/c/lib_obj.c b/c/lib_obj.c
--- a/c/lib_obj.c
+++ b/c/lib_obj.c
@@ -250,6 +250,7 @@
     }
 
     case _CFFI_OP_CONSTANT:
+    case _CFFI_OP_DLOPEN_CONST:
     {
         /* a constant which is not of integer type */
         char *data;
@@ -264,6 +265,7 @@
         }
         if (g->address == NULL) {
             /* for dlopen() style */
+            assert(_CFFI_GETOP(g->type_op) == _CFFI_OP_DLOPEN_CONST);
             data = cdlopen_fetch(lib->l_libname, lib->l_libhandle, s);
             if (data == NULL)
                 return NULL;
@@ -275,6 +277,7 @@
                in a CFFI C extension module.  CPython never unloads its C
                extension modules anyway.  Note that we used to do alloca(),
                but see issue #198. */
+            assert(_CFFI_GETOP(g->type_op) == _CFFI_OP_CONSTANT);
             data = PyMem_Malloc(ct->ct_size);
             if (data == NULL) {
                 PyErr_NoMemory();
diff --git a/cffi/cffi_opcode.py b/cffi/cffi_opcode.py
--- a/cffi/cffi_opcode.py
+++ b/cffi/cffi_opcode.py
@@ -52,6 +52,7 @@
 OP_CONSTANT_INT    = 31
 OP_GLOBAL_VAR      = 33
 OP_DLOPEN_FUNC     = 35
+OP_DLOPEN_CONST    = 37
 
 PRIM_VOID          = 0
 PRIM_BOOL          = 1
diff --git a/cffi/parse_c_type.h b/cffi/parse_c_type.h
--- a/cffi/parse_c_type.h
+++ b/cffi/parse_c_type.h
@@ -25,6 +25,7 @@
 #define _CFFI_OP_CONSTANT_INT   31
 #define _CFFI_OP_GLOBAL_VAR     33
 #define _CFFI_OP_DLOPEN_FUNC    35
+#define _CFFI_OP_DLOPEN_CONST   37
 
 #define _CFFI_PRIM_VOID          0
 #define _CFFI_PRIM_BOOL          1
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -982,8 +982,12 @@
                 raise ffiplatform.VerificationError(
                     "constant '%s' is of type '%s', whose size is not known"
                     % (name, tp._get_c_name()))
+            if self.target_is_python:
+                const_kind = OP_DLOPEN_CONST
+            else:
+                const_kind = OP_CONSTANT
             type_index = self._typesdict[tp]
-            type_op = CffiOp(OP_CONSTANT, type_index)
+            type_op = CffiOp(const_kind, type_index)
         self._lsts["global"].append(
             GlobalExpr(name, '_cffi_const_%s' % name, type_op))
 
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
@@ -30,7 +30,7 @@
 ffi = _cffi_backend.FFI('test_valid_global_constant',
     _version = 0x2601,
     _types = b'\x00\x00\x0D\x01\x00\x00\x09\x01',
-    _globals = (b'\x00\x00\x01\x1DBB',0,b'\x00\x00\x00\x1DBF',0),
+    _globals = (b'\x00\x00\x01\x25BB',0,b'\x00\x00\x00\x25BF',0),
 )
 """
 


More information about the pypy-commit mailing list