Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r77180:6aacf72649c4
Date: 2015-05-07 17:21 +0200
http://bitbucket.org/pypy/pypy/changeset/6aacf72649c4/

Log:    fight fight

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,37 @@
+from rpython.rlib import rdynload
+from rpython.rtyper.lltypesystem import lltype, rffi
 
-def load_cffi1_module(space, name, dll, initptr):
-    xxxx
+from pypy.interpreter.error import oefmt
+from pypy.interpreter.module import Module
+from pypy.module._cffi_backend import parse_c_type
+from pypy.module._cffi_backend.ffi_obj import W_FFIObject
 
+
+EXPECTED_VERSION = 0x10000f0
+
+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 version != EXPECTED_VERSION:
+                raise oefmt(space.w_ImportError,
+                    "the 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
+
+    ffi = W_FFIObject(space, src_ctx)
+
+    w_name = space.wrap(name)
+    module = Module(space, w_name)
+    module.setdictvalue(space, '__file__', space.wrap(path))
+    module.setdictvalue(space, 'ffi', space.wrap(ffi))
+    module.setdictvalue(space, 'lib', space.w_None)
+    space.setitem(space.sys.get('modules'), w_name, space.wrap(module))
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
@@ -1110,7 +1110,6 @@
     trunk_include = pypydir.dirpath() / 'include'
     copy_header_files(trunk_include)
 
-initfunctype = lltype.Ptr(lltype.FuncType([], lltype.Void))
 @unwrap_spec(path=str, name=str)
 def load_extension_module(space, path, name):
     # note: this is used both to load CPython-API-style C extension
@@ -1143,7 +1142,8 @@
             pass
         else:
             from pypy.module._cffi_backend.cffi1_module import 
load_cffi1_module
-            return load_cffi1_module(space, name, dll, initptr)
+            load_cffi1_module(space, name, path, dll, initptr)
+            return
     #
     if space.config.objspace.usemodules.cpyext:
         also_look_for = 'init%s' % (basename,)
@@ -1152,7 +1152,8 @@
         except KeyError:
             pass
         else:
-            return load_cpyext_module(space, name, dll, initptr)
+            load_cpyext_module(space, name, path, dll, initptr)
+            return
         if look_for is not None:
             look_for += ' or ' + also_look_for
         else:
@@ -1161,8 +1162,9 @@
     raise oefmt(space.w_ImportError,
                 "function %s not found in library %s", look_for, path)
 
+initfunctype = lltype.Ptr(lltype.FuncType([], lltype.Void))
 
-def load_cpyext_module(space, name, dll, initptr):
+def load_cpyext_module(space, name, path, dll, initptr):
     from rpython.rlib import rdynload
 
     space.getbuiltinmodule("cpyext")    # mandatory to init cpyext
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to