Skip to content

Commit e53b3fd

Browse files
committed
py/obj: allow disabling traceback allocation
Since the existing code handles `NULL` `traceback_data` correctly, it would avoid heap allocation in builds that don't access traceback data.
1 parent c718974 commit e53b3fd

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

py/obj.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,11 @@ bool mp_obj_is_exception_type(mp_obj_t self_in);
856856
bool mp_obj_is_exception_instance(mp_obj_t self_in);
857857
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
858858
void mp_obj_exception_clear_traceback(mp_obj_t self_in);
859+
#if MICROPY_PY_SYS_TRACEBACK_DISABLE
860+
static inline void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {}
861+
#else
859862
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
863+
#endif
860864
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
861865
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
862866
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);

py/objexcept.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in) {
569569
self->traceback_data = NULL;
570570
}
571571

572+
#if !MICROPY_PY_SYS_TRACEBACK_DISABLE
572573
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) {
573574
mp_obj_exception_t *self = get_native_exception(self_in);
574575

@@ -631,6 +632,7 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs
631632
tb_data[1] = line;
632633
tb_data[2] = block;
633634
}
635+
#endif // !MICROPY_PY_SYS_TRACEBACK_DISABLE
634636

635637
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values) {
636638
mp_obj_exception_t *self = get_native_exception(self_in);

0 commit comments

Comments
 (0)