[pypy-svn] r36122 - in pypy/dist/pypy/rlib/rctypes: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jan 3 16:48:05 CET 2007


Author: arigo
Date: Wed Jan  3 16:48:03 2007
New Revision: 36122

Modified:
   pypy/dist/pypy/rlib/rctypes/implementation.py
   pypy/dist/pypy/rlib/rctypes/rpointer.py
   pypy/dist/pypy/rlib/rctypes/test/test_rstruct.py
Log:
Recursive structures seem to work now.


Modified: pypy/dist/pypy/rlib/rctypes/implementation.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/implementation.py	(original)
+++ pypy/dist/pypy/rlib/rctypes/implementation.py	Wed Jan  3 16:48:03 2007
@@ -1,5 +1,6 @@
 import py
 from pypy.annotation import model as annmodel
+from pypy.tool.tls import tlsobject
 from pypy.rlib.rctypes import rctypesobject
 from pypy.rpython import extregistry, controllerentry
 from pypy.rpython.error import TyperError
@@ -24,6 +25,9 @@
         self.ctype = ctype
         self.instance_cache = {}
 
+    def setup(self):
+        pass
+
     def register_for_type(cls, ctype):
         class Entry(CTypesCallEntry):
             _about_ = ctype
@@ -109,12 +113,29 @@
 class CTypesCallEntry(ControllerEntry):
     def getcontroller(self, *args_s):
         ctype = self.instance
-        return self._controller_(ctype)
+        return _build_controller(self._controller_, ctype)
 
 class CTypesObjEntry(ControllerEntryForPrebuilt):
     def getcontroller(self):
         ctype = self.type
-        return self._controller_(ctype)
+        return _build_controller(self._controller_, ctype)
+
+TLS = tlsobject()
+def _build_controller(cls, ctype):
+    if hasattr(TLS, 'pending'):
+        # recursive case
+        controller = cls(ctype)
+        TLS.pending.append(controller)
+    else:
+        # non-recursive case
+        TLS.pending = []
+        controller = cls(ctype)
+        pending = TLS.pending
+        del TLS.pending
+        pending.append(controller)
+        for c1 in pending:
+            c1.setup()
+    return controller
 
 def getcontroller(ctype):
     """Return the CTypeController instance corresponding to the given ctype."""

Modified: pypy/dist/pypy/rlib/rctypes/rpointer.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/rpointer.py	(original)
+++ pypy/dist/pypy/rlib/rctypes/rpointer.py	Wed Jan  3 16:48:03 2007
@@ -13,9 +13,12 @@
 
     def __init__(self, ctype):
         CTypeController.__init__(self, ctype)
-        self.contentscontroller = getcontroller(ctype._type_)
-        self.knowntype = rctypesobject.RPointer(
-            self.contentscontroller.knowntype)
+        self.knowntype = rctypesobject.RPointer(None)
+
+    def setup(self):
+        if not hasattr(self, 'contentscontroller'):
+            self.contentscontroller = getcontroller(self.ctype._type_)
+            self.knowntype.setpointertype(self.contentscontroller.knowntype)
 
     def new(self, ptrto=None):
         obj = self.knowntype.allocate()

Modified: pypy/dist/pypy/rlib/rctypes/test/test_rstruct.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/test/test_rstruct.py	(original)
+++ pypy/dist/pypy/rlib/rctypes/test/test_rstruct.py	Wed Jan  3 16:48:03 2007
@@ -144,7 +144,6 @@
         assert res == 121
 
     def test_struct_with_pointer_to_self(self):
-        py.test.skip("in-progress")
         PS = POINTER('S')
         class S(Structure):
             _fields_ = [('l', PS), ('r', PS)]



More information about the Pypy-commit mailing list