[pypy-svn] r28997 - in pypy/dist/pypy: interpreter module/_stackless/test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jun 20 15:50:45 CEST 2006


Author: pedronis
Date: Tue Jun 20 15:50:31 2006
New Revision: 28997

Modified:
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/module/_stackless/test/test_pickle.py
Log:
(arre, pedronis)

fix pickling and unpickling of the valuestack, now test_loop and the new test_valstack pass



Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Tue Jun 20 15:50:31 2006
@@ -88,7 +88,9 @@
         else:
             f_lineno = self.f_lineno
 
-        w_valuestack = maker.slp_into_tuple_with_nulls(space, self.valuestack.items)
+        values_w = self.valuestack.items[0:self.valuestack.ptr]
+        w_valuestack = maker.slp_into_tuple_with_nulls(space, values_w)
+        
         w_blockstack = nt([block._get_state_(space) for block in self.blockstack.items])
         w_fastlocals = maker.slp_into_tuple_with_nulls(space, self.fastlocals_w)
         tup_base = [
@@ -141,7 +143,10 @@
         new_frame.builtin = space.interp_w(Module, w_builtin)
         new_frame.blockstack.items = [unpickle_block(space, w_blk)
                                       for w_blk in space.unpackiterable(w_blockstack)]
-        new_frame.valuestack.items = maker.slp_from_tuple_with_nulls(space, w_valuestack)
+        values_w = maker.slp_from_tuple_with_nulls(space, w_valuestack)
+        valstack = new_frame.valuestack
+        for w_value in values_w:
+            valstack.push(w_value)
         new_frame.last_exception = None#XXX (w_last_exception)
         new_frame.last_instr = space.int_w(w_last_instr)
         new_frame.next_instr = space.int_w(w_next_instr)

Modified: pypy/dist/pypy/module/_stackless/test/test_pickle.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_pickle.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_pickle.py	Tue Jun 20 15:50:31 2006
@@ -117,7 +117,7 @@
             del sys.modules['mod']
 
     def test_loop(self):
-        skip("happily segfaulting")
+        #skip("happily segfaulting")
         import new, sys
 
         mod = new.module('mod')
@@ -143,7 +143,8 @@
     new_coro = pickle.loads(pckl)
 
     new_coro.switch()
-    new_coro.switch()    
+    new_coro.switch()
+    new_coro.switch()
 
 example()
 assert output == [1, 2, 3]
@@ -151,6 +152,44 @@
         finally:
             del sys.modules['mod']
 
+    def test_valstack(self):
+        import new, sys
+
+        mod = new.module('mod')
+        sys.modules['mod'] = mod
+        try:
+            exec '''
+output = []
+import _stackless
+def f(coro):
+    r = 1+g(coro)+3
+    output.append(r)
+
+def g(coro):
+    coro.switch()
+    return 2
+
+def example():
+    main_coro = _stackless.coroutine.getcurrent()
+    sub_coro = _stackless.coroutine()
+
+    sub_coro.bind(f, main_coro)
+    sub_coro.switch()
+
+    import pickle
+    pckl = pickle.dumps(sub_coro)
+    new_coro = pickle.loads(pckl)
+
+    new_coro.switch()
+
+
+example()
+assert output == [6]
+''' in mod.__dict__
+        finally:
+            del sys.modules['mod']
+
+
     def test_exec_and_locals(self):
         import new, sys
 



More information about the Pypy-commit mailing list