[pypy-svn] r28758 - in pypy/dist/pypy/module/_stackless: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jun 13 22:27:42 CEST 2006


Author: cfbolz
Date: Tue Jun 13 22:27:41 2006
New Revision: 28758

Modified:
   pypy/dist/pypy/module/_stackless/interp_greenlet.py
   pypy/dist/pypy/module/_stackless/test/test_greenlet.py
Log:
add safety check (which incidentally also helps the annotator)


Modified: pypy/dist/pypy/module/_stackless/interp_greenlet.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/interp_greenlet.py	(original)
+++ pypy/dist/pypy/module/_stackless/interp_greenlet.py	Tue Jun 13 22:27:41 2006
@@ -59,7 +59,9 @@
         if is_main:
             self.w_parent = space.w_None
         else:
-            self.w_parent = state.current
+            w_parent = state.current
+            assert isinstance(w_parent, AppGreenlet)
+            self.w_parent = w_parent
         Coroutine.__init__(self, state)
         if not is_main:
             space.getexecutioncontext().subcontext_new(self)
@@ -124,7 +126,8 @@
 def w_get_parent(space, self):
     return self.w_parent
 
-def w_set_parent(space, self, newparent):
+def w_set_parent(space, self, w_parent):
+    newparent = space.interp_w(AppGreenlet, w_parent)
     curr = newparent
     while 1:
         if space.is_true(space.is_(self, curr)):

Modified: pypy/dist/pypy/module/_stackless/test/test_greenlet.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_greenlet.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_greenlet.py	Tue Jun 13 22:27:41 2006
@@ -87,6 +87,7 @@
         g2 = greenlet(fmain)
         g1.switch(seen)
         g2.switch(seen)
+        raises(TypeError, "g2.parent = 1")
         g2.parent = g1
         assert seen == []
         raises(ValueError, g2.switch)



More information about the Pypy-commit mailing list