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

ludal at codespeak.net ludal at codespeak.net
Wed Feb 28 17:19:47 CET 2007


Author: ludal
Date: Wed Feb 28 17:19:46 2007
New Revision: 39596

Modified:
   pypy/dist/pypy/module/_stackless/interp_clonable.py
   pypy/dist/pypy/module/_stackless/interp_coroutine.py
   pypy/dist/pypy/module/_stackless/test/test_clonable.py
Log:
fixes a segfault when cloning a clonable before starting it
_stackless/test pass with the compiled executable


Modified: pypy/dist/pypy/module/_stackless/interp_clonable.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/interp_clonable.py	(original)
+++ pypy/dist/pypy/module/_stackless/interp_clonable.py	Wed Feb 28 17:19:46 2007
@@ -1,11 +1,8 @@
-from pypy.module._stackless.interp_coroutine import AbstractThunk, BaseCoState, Coroutine
+from pypy.module._stackless.interp_coroutine import AbstractThunk, Coroutine
 from pypy.rlib.rgc import gc_swap_pool, gc_clone
 from pypy.rlib.objectmodel import we_are_translated
-
 from pypy.interpreter.error import OperationError
 
-from pypy.tool import stdlib_opcode as pythonopcode
-
 
 class InterpClonableMixin:
     local_pool = None
@@ -36,6 +33,7 @@
         # clone!
         data, copy.local_pool = gc_clone(data, self.local_pool)
         copy.frame, extradata = data
+        copy.thunk = self.thunk # in case we haven't switched to self yet
         return extradata
 
 

Modified: pypy/dist/pypy/module/_stackless/interp_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/interp_coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/interp_coroutine.py	Wed Feb 28 17:19:46 2007
@@ -207,7 +207,9 @@
         return chain
 
     def _bind(self):
+        state = self.costate
         incoming_frame = yield_current_frame_to_caller()
+        self = state.current
         return self._execute(incoming_frame)
 
     def _execute(self, incoming_frame):

Modified: pypy/dist/pypy/module/_stackless/test/test_clonable.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_clonable.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_clonable.py	Wed Feb 28 17:19:46 2007
@@ -165,3 +165,21 @@
         res = first_solution(example)
         assert res == [1, 1, 0, 1, 0]
 
+    def test_clone_before_start(self):
+        """Tests that a clonable coroutine can be
+        cloned before it is started
+        (this used to fail with a segmentation fault)
+        """
+        import _stackless
+
+        counter = [0]
+        def simple_coro():
+            print "hello"
+            counter[0] += 1
+
+        s = _stackless.clonable()
+        s.bind(simple_coro)
+        t = s.clone()
+        s.switch()
+        t.switch()
+        assert counter[0] == 2



More information about the Pypy-commit mailing list