diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-09-21 15:24:57 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-09-21 15:24:57 +1000 |
| commit | 96fd80db1306ed67ee967b888c1c03c136bff4fb (patch) | |
| tree | 07f1e28afa31b595b361add91bda6257355713a5 /tests/run-tests | |
| parent | 347de3e218fe02bba6f7a4bccd1b90f8326c1efe (diff) | |
py/objexcept: Prevent infinite recursion when allocating exceptions.
The aim of this patch is to rewrite the functions that create exception
instances (mp_obj_exception_make_new and mp_obj_new_exception_msg_varg) so
that they do not call any functions that may raise an exception. Otherwise
it's possible to create infinite recursion with an exception being raised
while trying to create an exception object.
The two main things that are done to accomplish this are:
1. Change mp_obj_new_exception_msg_varg to just format the string, then
call mp_obj_exception_make_new to actually create the exception object.
2. In mp_obj_exception_make_new and mp_obj_new_exception_msg_varg try to
allocate all memory first using functions that don't raise exceptions
If any of the memory allocations fail (return NULL) then degrade
gracefully by trying other options for memory allocation, eg using the
emergency exception buffer.
3. Use a custom printer backend to conservatively format strings: if it
can't allocate memory then it just truncates the string.
As part of this rewrite, raising an exception without a message, like
KeyError(123), will now use the emergency buffer to store the arg and
traceback data if there is no heap memory available.
Memory use with this patch is unchanged. Code size is increased by:
bare-arm: +136
minimal x86: +124
unix x64: +72
unix nanbox: +96
stm32: +88
esp8266: +92
cc3200: +80
Diffstat (limited to 'tests/run-tests')
| -rwxr-xr-x | tests/run-tests | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/run-tests b/tests/run-tests index 866a9b7c3..568d99f8e 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -345,6 +345,7 @@ def run_tests(pyb, tests, args, base_path="."): skip_tests.add('misc/rge_sm.py') # requires yield skip_tests.add('misc/print_exception.py') # because native doesn't have proper traceback info skip_tests.add('misc/sys_exc_info.py') # sys.exc_info() is not supported for native + skip_tests.add('micropython/emg_exc.py') # because native doesn't have proper traceback info skip_tests.add('micropython/heapalloc_traceback.py') # because native doesn't have proper traceback info skip_tests.add('micropython/heapalloc_iter.py') # requires generators skip_tests.add('micropython/schedule.py') # native code doesn't check pending events |
