summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/try_finally2.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-27 12:46:50 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-27 12:46:50 +1000
commit3f0c1c24528d8ce818434d8b553136d315b0d548 (patch)
tree87f8e4342f1d5cbd94aa75cb5dca98c5c1455107 /tests/basics/try_finally2.py
parentf040685b0cbec18feb981fdad96389a3b28b676d (diff)
downloadmicropython-3f0c1c24528d8ce818434d8b553136d315b0d548.tar.gz
micropython-3f0c1c24528d8ce818434d8b553136d315b0d548.zip
tests/basics: Add test case for overflowing Py stack in try-finally.
Diffstat (limited to 'tests/basics/try_finally2.py')
-rw-r--r--tests/basics/try_finally2.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/basics/try_finally2.py b/tests/basics/try_finally2.py
new file mode 100644
index 0000000000..3c4171d91f
--- /dev/null
+++ b/tests/basics/try_finally2.py
@@ -0,0 +1,30 @@
+# check that the Python stack does not overflow when the finally
+# block itself uses more stack than the rest of the function
+def f1(a, b):
+ pass
+def test1():
+ val = 1
+ try:
+ raise ValueError()
+ finally:
+ f1(2, 2) # use some stack
+ print(val) # check that the local variable is the same
+try:
+ test1()
+except ValueError:
+ pass
+
+# same as above but with 3 args instead of 2, to use an extra stack entry
+def f2(a, b, c):
+ pass
+def test2():
+ val = 1
+ try:
+ raise ValueError()
+ finally:
+ f2(2, 2, 2) # use some stack
+ print(val) # check that the local variable is the same
+try:
+ test2()
+except ValueError:
+ pass