Skip to content

Commit e02cb9e

Browse files
committed
tests/heapalloc_*: Refactor some tests to work in strict stackless mode.
In strict stackless mode, it's not possible to make a function call with heap locked (because function activation record aka frame is allocated on heap). So, if the only purpose of function is to introduce local variable scope, move heap lock/unlock calls inside the function.
1 parent 30fd848 commit e02cb9e

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

tests/micropython/heapalloc_exc_raise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
e = ValueError("error")
66

77
def func():
8+
micropython.heap_lock()
89
try:
910
# This works as is because traceback is not allocated
1011
# if not possible (heap is locked, no memory). If heap
@@ -16,8 +17,7 @@ def func():
1617
raise e
1718
except Exception as e2:
1819
print(e2)
20+
micropython.heap_unlock()
1921

20-
micropython.heap_lock()
2122
func()
2223
print("ok")
23-
micropython.heap_unlock()

tests/micropython/heapalloc_iter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
heap_lock = heap_unlock = lambda:0
1212

1313
def do_iter(l):
14+
heap_lock()
1415
for i in l:
1516
print(i)
17+
heap_unlock()
1618

1719
def gen_func():
1820
yield 1
@@ -55,7 +57,6 @@ def gen_func():
5557
heap_unlock()
5658

5759
# test iterating over collections with the heap locked
58-
heap_lock()
5960
do_iter(b'123')
6061
do_iter(ba)
6162
do_iter(ar)
@@ -66,4 +67,3 @@ def gen_func():
6667
do_iter(fs)
6768
do_iter(g1)
6869
do_iter(g2)
69-
heap_unlock()

tests/micropython/heapalloc_traceback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
pass
1717

1818
def test():
19+
micropython.heap_lock()
1920
global global_exc
2021
global_exc.__traceback__ = None
2122
try:
2223
raise global_exc
2324
except StopIteration:
2425
print('StopIteration')
26+
micropython.heap_unlock()
2527

2628
# call test() with heap allocation disabled
27-
micropython.heap_lock()
2829
test()
29-
micropython.heap_unlock()
3030

3131
# print the exception that was raised
3232
buf = uio.StringIO()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
StopIteration
22
Traceback (most recent call last):
3-
File , line 22, in test
3+
File , line 23, in test
44
StopIteration:
55

0 commit comments

Comments
 (0)