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

xoraxax at codespeak.net xoraxax at codespeak.net
Wed Mar 31 23:44:21 CEST 2010


Author: xoraxax
Date: Wed Mar 31 23:44:19 2010
New Revision: 73235

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
   pypy/branch/cpython-extension/pypy/module/cpyext/state.py
Log:
Correctly init r2w mapping at runtime.

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	Wed Mar 31 23:44:19 2010
@@ -26,6 +26,8 @@
             space.setattr(space.wrap(self),
                           space.wrap('api_lib'),
                           space.wrap(state.api_lib))
+        else:
+            state.init_r2w_from_w2r()
 
 # import these modules to register api functions by side-effect
 import pypy.module.cpyext.pyobject

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/state.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/state.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/state.py	Wed Mar 31 23:44:19 2010
@@ -20,6 +20,17 @@
         self.exc_type = None
         self.exc_value = None
 
+    def _freeze_(self):
+        assert not self.borrowed_objects and not self.borrow_mapping
+        self.py_objects_r2w.clear() # is not valid anymore after translation
+        return False
+
+    def init_r2w_from_w2r(self):
+        from pypy.module.cpyext.api import ADDR
+        for w_obj, obj in self.py_objects_w2r.items():
+            ptr = rffi.cast(ADDR, obj)
+            self.py_objects_r2w[ptr] = w_obj
+
     def set_exception(self, w_type, w_value):
         self.clear_exception()
         self.exc_type = w_type



More information about the Pypy-commit mailing list