Skip to content

Commit 3556e45

Browse files
committed
Allow real memory errors (from locked gc) to be reported with traceback.
1 parent 67f25df commit 3556e45

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

py/runtime.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "parsehelper.h"
5252
#include "compile.h"
5353
#include "stackctrl.h"
54+
#include "gc.h"
5455

5556
#if 0 // print debugging info
5657
#define DEBUG_PRINT (1)
@@ -1207,7 +1208,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
12071208

12081209
void *m_malloc_fail(size_t num_bytes) {
12091210
DEBUG_printf("memory allocation failed, allocating " UINT_FMT " bytes\n", num_bytes);
1210-
nlr_raise((mp_obj_t)&mp_const_MemoryError_obj);
1211+
if (gc_is_locked()) {
1212+
nlr_raise(mp_obj_new_exception_msg(& mp_type_MemoryError,
1213+
"memory allocation failed, heap is locked"));
1214+
} else {
1215+
nlr_raise(mp_obj_new_exception_msg_varg(& mp_type_MemoryError,
1216+
"memory allocation failed, allocating " UINT_FMT " bytes", num_bytes));
1217+
}
12111218
}
12121219

12131220
NORETURN void mp_not_implemented(const char *msg) {

stmhal/printf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ int vprintf(const char *fmt, va_list ap) {
6767
}
6868

6969
#if MICROPY_DEBUG_PRINTERS
70+
mp_uint_t mp_verbose_flag = 1;
71+
7072
int DEBUG_printf(const char *fmt, ...) {
71-
(void)stream;
7273
va_list ap;
7374
va_start(ap, fmt);
7475
int ret = pfenv_vprintf(&pfenv_stdout, fmt, ap);

unix/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#endif
7373

7474
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
75-
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (128)
75+
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
7676

7777
extern const struct _mp_obj_module_t mp_module_os;
7878
extern const struct _mp_obj_module_t mp_module_time;

0 commit comments

Comments
 (0)