[pypy-svn] r72565 - pypy/trunk/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Mon Mar 22 16:16:40 CET 2010


Author: afa
Date: Mon Mar 22 16:16:39 2010
New Revision: 72565

Modified:
   pypy/trunk/pypy/module/cpyext/__init__.py
   pypy/trunk/pypy/module/cpyext/api.py
Log:
Rewrite load_extension_module to use libffi instead of ctypes
and expose it at app-level


Modified: pypy/trunk/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/__init__.py	(original)
+++ pypy/trunk/pypy/module/cpyext/__init__.py	Mon Mar 22 16:16:39 2010
@@ -6,6 +6,7 @@
 
 class Module(MixedModule):
     interpleveldefs = {
+        'load_module': 'api.load_extension_module',
     }
 
     appleveldefs = {

Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Mon Mar 22 16:16:39 2010
@@ -328,10 +328,14 @@
 
     return modulename.new(ext='')
 
+ at unwrap_spec(ObjSpace, str, str)
 def load_extension_module(space, path, name):
     state = space.fromcache(State)
-    import ctypes
-    initfunc = ctypes.CDLL(path)['init%s' % (name,)]
-    initfunc()
+    from pypy.rlib import libffi
+    dll = libffi.CDLL(path)
+    initfunc = dll.getpointer(
+        'init%s' % (name,), [], libffi.ffi_type_void)
+    dll.unload_on_finalization = False
+    initfunc.call(lltype.Void)
     state.check_and_raise_exception()
 



More information about the Pypy-commit mailing list