diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-01 14:28:40 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-01 14:28:40 +0100 |
commit | 5fc580475f5eba8248de86a4148090e63f777372 (patch) | |
tree | 5261ef47c946e0db2b619829513945889e7e4ab6 /py | |
parent | aa47f3968bdb46c67b6150eb7637d1cbd1e76767 (diff) | |
parent | f0b29729aa086892a2dc6640a9fe619bb723e5fa (diff) | |
download | micropython-5fc580475f5eba8248de86a4148090e63f777372.tar.gz micropython-5fc580475f5eba8248de86a4148090e63f777372.zip |
Merge branch 'dhylands-preserve-except'
Diffstat (limited to 'py')
-rw-r--r-- | py/gc.c | 4 | ||||
-rw-r--r-- | py/gc.h | 1 | ||||
-rw-r--r-- | py/objexcept.c | 8 |
3 files changed, 13 insertions, 0 deletions
@@ -172,6 +172,10 @@ void gc_unlock(void) { gc_lock_depth--; } +bool gc_is_locked(void) { + return gc_lock_depth != 0; +} + #define VERIFY_PTR(ptr) ( \ (ptr & (BYTES_PER_BLOCK - 1)) == 0 /* must be aligned on a block */ \ && ptr >= (machine_uint_t)gc_pool_start /* must be above start of pool */ \ @@ -30,6 +30,7 @@ void gc_init(void *start, void *end); // They can be used to prevent the GC from allocating/freeing. void gc_lock(void); void gc_unlock(void); +bool gc_is_locked(void); // A given port must implement gc_collect by using the other collect functions. void gc_collect(void); diff --git a/py/objexcept.c b/py/objexcept.c index 9f421373bb..ad66bb50fe 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -37,6 +37,7 @@ #include "objtype.h" #include "runtime.h" #include "runtime0.h" +#include "gc.h" typedef struct _mp_obj_exception_t { mp_obj_base_t base; @@ -335,6 +336,13 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) { } void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t line, qstr block) { + #if MICROPY_ENABLE_GC + if (gc_is_locked()) { + // We can't allocate memory, so don't bother to try + return; + } + #endif + GET_NATIVE_EXCEPTION(self, self_in); // for traceback, we are just using the list object for convenience, it's not really a list of Python objects |