2016-11-21 01:39:23 -05:00
|
|
|
# test that we can generate a traceback without allocating
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
import sys
|
2017-03-09 04:26:31 -05:00
|
|
|
try:
|
|
|
|
import uio
|
|
|
|
except ImportError:
|
|
|
|
import sys
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
2016-11-21 01:39:23 -05:00
|
|
|
|
|
|
|
# preallocate exception instance with some room for a traceback
|
|
|
|
global_exc = StopIteration()
|
|
|
|
try:
|
|
|
|
raise global_exc
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test():
|
|
|
|
global global_exc
|
|
|
|
global_exc.__traceback__ = None
|
|
|
|
try:
|
|
|
|
raise global_exc
|
2016-12-14 19:11:57 -05:00
|
|
|
except StopIteration:
|
|
|
|
print('StopIteration')
|
2016-11-21 01:39:23 -05:00
|
|
|
|
|
|
|
# call test() with heap allocation disabled
|
|
|
|
micropython.heap_lock()
|
|
|
|
test()
|
|
|
|
micropython.heap_unlock()
|
2016-12-14 19:11:57 -05:00
|
|
|
|
|
|
|
# print the exception that was raised
|
|
|
|
buf = uio.StringIO()
|
|
|
|
sys.print_exception(global_exc, buf)
|
|
|
|
for l in buf.getvalue().split("\n"):
|
|
|
|
# uPy on pyboard prints <stdin> as file, so remove filename.
|
|
|
|
if l.startswith(" File "):
|
|
|
|
l = l.split('"')
|
|
|
|
print(l[0], l[2])
|
|
|
|
else:
|
|
|
|
print(l)
|