Skip to content

Commit a41ffd1

Browse files
committed
set_next_code_file(None) resets to the default search order.
1 parent f222a3f commit a41ffd1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,15 @@ bool cleanup_after_vm(supervisor_allocation* heap) {
259259
if (next_code_allocation) {
260260
free_memory(next_code_allocation);
261261
}
262-
// TODO do I need to increase CIRCUITPY_SUPERVISOR_ALLOC_COUNT for this?
263-
next_code_allocation = allocate_memory((next_code_len + 1 + 3) & ~3, false);
264-
if (next_code_allocation) {
265-
memcpy(next_code_allocation->ptr, next_code, next_code_len);
266-
((char*)next_code_allocation->ptr)[next_code_len] = '\0';
267-
return true;
262+
// empty filename and options 0 is equivalent to the default, no need to waste memory on that
263+
if (next_code_len > 1 || next_code->options != 0) {
264+
// TODO do I need to increase CIRCUITPY_SUPERVISOR_ALLOC_COUNT for this?
265+
next_code_allocation = allocate_memory((next_code_len + 1 + 3) & ~3, false);
266+
if (next_code_allocation) {
267+
memcpy(next_code_allocation->ptr, next_code, next_code_len);
268+
((char*)next_code_allocation->ptr)[next_code_len] = '\0';
269+
return true;
270+
}
268271
}
269272
}
270273
return false;

shared-bindings/supervisor/__init__.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ STATIC mp_obj_t supervisor_set_next_code_file(size_t n_args, const mp_obj_t *pos
120120
mp_arg_val_t reload_on_success;
121121
} args;
122122
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
123-
if (!MP_OBJ_IS_STR_OR_BYTES(args.filename.u_obj)) {
123+
if (!MP_OBJ_IS_STR_OR_BYTES(args.filename.u_obj) && args.filename.u_obj != mp_const_none) {
124124
mp_raise_TypeError(translate("argument has wrong type"));
125125
}
126+
if (args.filename.u_obj == mp_const_none) args.filename.u_obj = mp_const_empty_bytes;
126127
mp_obj_t items[] = {
127128
args.filename.u_obj,
128129
args.reload_on_success.u_bool ? MP_OBJ_NEW_SMALL_INT(SUPERVISOR_NEXT_CODE_OPT_RELOAD_ON_SUCCESS) : MP_OBJ_NEW_SMALL_INT(0)

0 commit comments

Comments
 (0)