Author: Antonio Cuni <[email protected]>
Branch: continulet-no-frame-loop
Changeset: r93032:d5212118820d
Date: 2017-11-15 02:11 +0100
http://bitbucket.org/pypy/pypy/changeset/d5212118820d/
Log: introduce the concept of running/paused continulet, depending on
bottomframe.f_backref; fix the post_switch() logic to build the
f_back chain correctly; finally fix test_f_back to check that we do
NOT build cycles of frames
diff --git a/pypy/module/_continuation/interp_continuation.py
b/pypy/module/_continuation/interp_continuation.py
--- a/pypy/module/_continuation/interp_continuation.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -17,6 +17,8 @@
# states:
# - not init'ed: self.sthread == None
# - normal: self.sthread != None, not is_empty_handle(self.h)
+ # * running: self.bottomframe.f_backref is not vref_None
+ # * paused: self.bottomframe.f_backref is vref_None
# - finished: self.sthread != None, is_empty_handle(self.h)
def check_sthread(self):
@@ -275,8 +277,7 @@
self.h, origin.h = origin.h, h
#
current = sthread.ec.topframeref
- lo
- g('==== SWITCH ====')
+ log('==== SWITCH ====')
pstack(sthread.ec.topframeref, 'sthread.ec.topframeref')
pstack(self, 'self')
@@ -285,15 +286,20 @@
self.bottomframe.f_backref = origin.bottomframe.f_backref
origin.bottomframe.f_backref = current
else:
- # antocuni
sthread.ec.topframeref = self.topframeref
self.topframeref = origin.topframeref
+ self.bottomframe.f_backref = origin.bottomframe.f_backref
origin.topframeref = current
+ if origin.bottomframe.f_backref is jit.vref_None:
+ # paused ==> running: build the f_back link
+ origin.bottomframe.f_backref = current
+ else:
+ # running ==> paused: break the f_back link
+ origin.bottomframe.f_backref = jit.vref_None
#
log('swap')
pstack(sthread.ec.topframeref, 'sthread.ec.topframeref')
- pstack(self
- , 'self')
+ pstack(self, 'self')
log('==== END SWITCH ====')
log()
return get_result()
diff --git a/pypy/module/_continuation/test/test_stacklet.py
b/pypy/module/_continuation/test/test_stacklet.py
--- a/pypy/module/_continuation/test/test_stacklet.py
+++ b/pypy/module/_continuation/test/test_stacklet.py
@@ -406,27 +406,27 @@
f = main(c)
assert seen == [1, 2, 3, 4, 5, 6]
- def test_f_back(self):
+ def test_f_back_complex(self):
import sys
from _continuation import continulet
stack = self.stack
#
def bar(c):
- assert stack() == ['bar', 'foo', 'test_f_back']
+ assert stack() == ['bar', 'foo', 'test_f_back_complex']
c.switch(sys._getframe(0))
c.switch(sys._getframe(0).f_back)
c.switch(sys._getframe(1))
#
- assert stack() == ['bar', 'foo', 'main', 'test_f_back']
+ assert stack() == ['bar', 'foo', 'main', 'test_f_back_complex']
c.switch(sys._getframe(1).f_back)
#
- assert stack() == ['bar', 'foo', 'main2', 'test_f_back']
+ assert stack() == ['bar', 'foo', 'main2', 'test_f_back_complex']
assert sys._getframe(2) is f3_foo.f_back
c.switch(sys._getframe(2))
def foo(c):
bar(c)
#
- assert stack() == ['test_f_back']
+ assert stack() == ['test_f_back_complex']
c = continulet(foo)
f1_bar = c.switch()
assert f1_bar.f_code.co_name == 'bar'
@@ -439,16 +439,16 @@
def main():
f4_main = c.switch()
assert f4_main.f_code.co_name == 'main'
- assert f3_foo.f_back is f1_bar # not running, so a loop
- assert stack() == ['main', 'test_f_back']
- assert stack(f1_bar) == ['bar', 'foo', '...']
+ assert f3_foo.f_back is None # not running
+ assert stack() == ['main', 'test_f_back_complex']
+ assert stack(f1_bar) == ['bar', 'foo']
#
def main2():
f5_main2 = c.switch()
assert f5_main2.f_code.co_name == 'main2'
- assert f3_foo.f_back is f1_bar # not running, so a loop
- assert stack() == ['main2', 'test_f_back']
- assert stack(f1_bar) == ['bar', 'foo', '...']
+ assert f3_foo.f_back is None # not running
+ assert stack() == ['main2', 'test_f_back_complex']
+ assert stack(f1_bar) == ['bar', 'foo']
#
main()
main2()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit