e02cb9ec31
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.
24 lines
669 B
Python
24 lines
669 B
Python
# Test that we can raise and catch (preallocated) exception
|
|
# without memory allocation.
|
|
import micropython
|
|
|
|
e = ValueError("error")
|
|
|
|
def func():
|
|
micropython.heap_lock()
|
|
try:
|
|
# This works as is because traceback is not allocated
|
|
# if not possible (heap is locked, no memory). If heap
|
|
# is not locked, this would allocate a traceback entry.
|
|
# To avoid that, traceback should be warmed up (by raising
|
|
# it once after creation) and then cleared before each
|
|
# raise with:
|
|
# e.__traceback__ = None
|
|
raise e
|
|
except Exception as e2:
|
|
print(e2)
|
|
micropython.heap_unlock()
|
|
|
|
func()
|
|
print("ok")
|