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

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Mar 29 02:31:18 CEST 2010


Author: xoraxax
Date: Mon Mar 29 02:31:17 2010
New Revision: 73066

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
   pypy/branch/cpython-extension/pypy/module/cpyext/slotdefs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
Inline unwrapper instead of the function, rework slotdefs and rpythonify them.

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	Mon Mar 29 02:31:17 2010
@@ -1,7 +1,6 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.module.cpyext.state import State
-from pypy.module.cpyext.slotdefs import init_slotdefs
 from pypy.module.cpyext import api
 
 
@@ -18,7 +17,6 @@
         state = self.space.fromcache(State)
         if not self.space.config.translating:
             state.api_lib = str(api.build_bridge(self.space))
-            state.slotdefs = init_slotdefs(self.space)
         else:
             api.setup_library(self.space)
 

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	Mon Mar 29 02:31:17 2010
@@ -125,8 +125,6 @@
     def decorate(func):
         api_function = ApiFunction(argtypes, restype, func, borrowed, error)
         func.api_func = api_function
-        # the function is always wrapped so lets inline it into the wrapper
-        func._always_inline_ = True
 
         if error is _NOT_SPECIFIED:
             raise ValueError("function %s has no return value for exceptions"
@@ -174,6 +172,7 @@
                         Py_DECREF(space, arg)
             unwrapper.func = func
             unwrapper.api_func = api_function
+            unwrapper._always_inline_ = True
             return unwrapper
 
         unwrapper_True = make_unwrapper(True)

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/slotdefs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/slotdefs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/slotdefs.py	Mon Mar 29 02:31:17 2010
@@ -7,6 +7,7 @@
         ternaryfunc
 from pypy.module.cpyext.state import State
 from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.rlib.unroll import unrolling_iterable
 
 space = None
 
@@ -100,7 +101,7 @@
 # Copy new slotdefs from typeobject.c
 # Remove comments
 # Done.
-slotdefs = """
+slotdefs_str = """
 static slotdef slotdefs[] = {
 	SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc,
 	       "x.__len__() <==> len(x)"),
@@ -293,14 +294,9 @@
 };
 """
 for regex, repl in slotdef_replacements:
-    slotdefs = re.sub(regex, repl, slotdefs)
-def init_slotdefs(space_):
-    global space
-    space = space_
-    try:
-        return eval(slotdefs)
-    finally:
-        space = None
+    slotdefs_str = re.sub(regex, repl, slotdefs_str)
+
+slotdefs = unrolling_iterable(eval(slotdefs_str))
 
 if __name__ == "__main__":
-    print slotdefs
+    print slotdefs_str

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	Mon Mar 29 02:31:17 2010
@@ -62,7 +62,7 @@
 def add_operators(space, dict_w, pto):
     # XXX support PyObject_HashNotImplemented
     state = space.fromcache(State)
-    for method_name, slot_name, _, wrapper_func, wrapper_func_kwds, doc in state.slotdefs: # XXX use UI
+    for method_name, slot_name, _, wrapper_func, wrapper_func_kwds, doc in slotdefs:
         if method_name in dict_w:
             continue
         # XXX is this rpython?



More information about the Pypy-commit mailing list