Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r77259:ac4814a8286b
Date: 2015-05-09 19:34 +0200
http://bitbucket.org/pypy/pypy/changeset/ac4814a8286b/

Log:    Fixes

diff --git a/pypy/module/_cffi_backend/cffi1_module.py 
b/pypy/module/_cffi_backend/cffi1_module.py
--- a/pypy/module/_cffi_backend/cffi1_module.py
+++ b/pypy/module/_cffi_backend/cffi1_module.py
@@ -1,4 +1,3 @@
-from rpython.rlib import rdynload
 from rpython.rtyper.lltypesystem import lltype, rffi
 
 from pypy.interpreter.error import oefmt
@@ -14,20 +13,17 @@
 initfunctype = lltype.Ptr(lltype.FuncType([rffi.VOIDPP], lltype.Void))
 
 
-def load_cffi1_module(space, name, path, dll, initptr):
-    try:
-        initfunc = rffi.cast(initfunctype, initptr)
-        with lltype.scoped_alloc(rffi.VOIDPP.TO, 2, zero=True) as p:
-            initfunc(p)
-            version = rffi.cast(lltype.Signed, p[0])
-            if not (VERSION_MIN <= version <= VERSION_MAX):
-                raise oefmt(space.w_ImportError,
-                    "cffi extension module '%s' has unknown version %s",
-                    name, hex(version))
-            src_ctx = rffi.cast(parse_c_type.PCTX, p[1])
-    except:
-        rdynload.dlclose(dll)
-        raise
+def load_cffi1_module(space, name, path, initptr):
+    # This is called from pypy.module.cpyext.api.load_extension_module()
+    initfunc = rffi.cast(initfunctype, initptr)
+    with lltype.scoped_alloc(rffi.VOIDPP.TO, 2, zero=True) as p:
+        initfunc(p)
+        version = rffi.cast(lltype.Signed, p[0])
+        if not (VERSION_MIN <= version <= VERSION_MAX):
+            raise oefmt(space.w_ImportError,
+                "cffi extension module '%s' has unknown version %s",
+                name, hex(version))
+        src_ctx = rffi.cast(parse_c_type.PCTX, p[1])
 
     ffi = W_FFIObject(space, src_ctx)
     lib = W_LibObject(ffi, name)
diff --git a/pypy/module/_cffi_backend/ffi_obj.py 
b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -413,7 +413,7 @@
 @jit.dont_look_inside
 def W_FFIObject___new__(space, w_subtype, __args__):
     r = space.allocate_instance(W_FFIObject, w_subtype)
-    # get in 'src_ctx' a NULL which transaction doesn't consider a constant
+    # get in 'src_ctx' a NULL which translation doesn't consider to be constant
     src_ctx = rffi.cast(parse_c_type.PCTX, 0)
     r.__init__(space, src_ctx)
     return space.wrap(r)
diff --git a/pypy/module/_cffi_backend/test/test_ztranslation.py 
b/pypy/module/_cffi_backend/test/test_ztranslation.py
--- a/pypy/module/_cffi_backend/test/test_ztranslation.py
+++ b/pypy/module/_cffi_backend/test/test_ztranslation.py
@@ -4,12 +4,15 @@
 
 # side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
 from pypy.module._cffi_backend import misc
+from pypy.module._cffi_backend import cffi1_module
 
 
 def test_checkmodule():
     # prepare_file_argument() is not working without translating the _file
     # module too
     def dummy_prepare_file_argument(space, fileobj):
+        # call load_cffi1_module() too, from a random place like here
+        cffi1_module.load_cffi1_module(space, "foo", "foo", 42)
         return lltype.nullptr(rffi.CCHARP.TO)
     old = ctypeptr.prepare_file_argument
     try:
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1141,8 +1141,12 @@
         except KeyError:
             pass
         else:
-            from pypy.module._cffi_backend.cffi1_module import 
load_cffi1_module
-            load_cffi1_module(space, name, path, dll, initptr)
+            try:
+                from pypy.module._cffi_backend import cffi1_module
+                cffi1_module.load_cffi1_module(space, name, path, initptr)
+            except:
+                rdynload.dlclose(dll)
+                raise
             return
     #
     if space.config.objspace.usemodules.cpyext:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to