summaryrefslogtreecommitdiff
path: root/py/objexcept.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-07-27 00:41:27 +1000
committerDamien George <damien@micropython.org>2022-03-10 10:43:21 +1100
commitcac939ddc3625da7e6cf1cf0309daba25fc1cedb (patch)
tree8e0417aab0ea5c9e22d6679edefb6a265cd31ab5 /py/objexcept.c
parentbc181550a4790f4dcfaf10e7e61ecfcdf346d5a8 (diff)
py/modsys: Add optional sys.tracebacklimit attribute.
With behaviour as per CPython. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/objexcept.c')
-rw-r--r--py/objexcept.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index 7a86c3647..dca287bb6 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -575,6 +575,16 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs
// append this traceback info to traceback data
// if memory allocation fails (eg because gc is locked), just return
+ #if MICROPY_PY_SYS_TRACEBACKLIMIT
+ mp_int_t max_traceback = MP_OBJ_SMALL_INT_VALUE(MP_STATE_VM(sys_mutable[MP_SYS_MUTABLE_TRACEBACKLIMIT]));
+ if (max_traceback <= 0) {
+ return;
+ } else if (self->traceback_data != NULL && self->traceback_len >= max_traceback * TRACEBACK_ENTRY_LEN) {
+ self->traceback_len -= TRACEBACK_ENTRY_LEN;
+ memmove(self->traceback_data, self->traceback_data + TRACEBACK_ENTRY_LEN, self->traceback_len * sizeof(self->traceback_data[0]));
+ }
+ #endif
+
if (self->traceback_data == NULL) {
self->traceback_data = m_new_maybe(size_t, TRACEBACK_ENTRY_LEN);
if (self->traceback_data == NULL) {