[pypy-svn] r73012 - pypy/branch/cpython-extension/pypy/module/cpyext

xoraxax at codespeak.net xoraxax at codespeak.net
Sun Mar 28 03:29:19 CEST 2010


Author: xoraxax
Date: Sun Mar 28 03:29:17 2010
New Revision: 73012

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
Log:
First steps towards a translated cpyext.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	Sun Mar 28 03:29:17 2010
@@ -1,8 +1,8 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.rlib.objectmodel import we_are_translated
-import pypy.module.cpyext.api
 from pypy.module.cpyext.state import State
 from pypy.module.cpyext.slotdefs import init_slotdefs
+from pypy.module.cpyext import api
 
 
 class Module(MixedModule):
@@ -17,10 +17,10 @@
         """NOT_RPYTHON"""
         state = self.space.fromcache(State)
         if not self.space.config.translating:
-            state.api_lib = str(pypy.module.cpyext.api.build_bridge(self.space))
+            state.api_lib = str(api.build_bridge(self.space))
             state.slotdefs = init_slotdefs(self.space)
         else:
-            XXX # build an import library when translating pypy.
+            api.setup_library(self.space)
 
     def startup(self, space):
         state = space.fromcache(State)

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py	Sun Mar 28 03:29:17 2010
@@ -18,6 +18,7 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import ObjSpace, unwrap_spec
 from pypy.objspace.std.stringobject import W_StringObject
+from pypy.rlib.entrypoint import entrypoint
 # CPython 2.4 compatibility
 from py.builtin import BaseException
 
@@ -99,6 +100,13 @@
             self._llhelper = llh
         return llh
 
+    def get_wrapper(self, space):
+        wrapper = getattr(self, '_wrapper', None)
+        if wrapper is None:
+            wrapper = make_wrapper(space, self.callable)
+            self._wrapper = wrapper
+        return wrapper
+
 def cpython_api(argtypes, restype, borrowed=False, error=_NOT_SPECIFIED, external=True):
     if error is _NOT_SPECIFIED:
         if restype is PyObject:
@@ -547,12 +555,17 @@
 
     return modulename.new(ext='')
 
+def setup_library(space):
+    for name, func in FUNCTIONS.iteritems():
+        deco = entrypoint("cpyext", func.argtypes, name)
+        deco(func.get_wrapper(space))
+
 @unwrap_spec(ObjSpace, str, str)
 def load_extension_module(space, path, name):
     state = space.fromcache(State)
     from pypy.rlib import libffi
     try:
-        dll = libffi.CDLL(path)
+        dll = libffi.CDLL(path, False)
     except libffi.DLOpenError, e:
         raise operationerrfmt(
             space.w_ImportError,
@@ -566,7 +579,6 @@
             space.w_ImportError,
             "function init%s not found in library %s",
             name, path)
-    dll.unload_on_finalization = False
     initfunc.call(lltype.Void)
     state.check_and_raise_exception()
 



More information about the Pypy-commit mailing list