Skip to content

Commit 426112c

Browse files
committed
extmod/moduos_dupterm: Reserve buffer bytearray object for dupterm.
Allocating it for each read/write operation is a memory fragmentation hazard.
1 parent d83177b commit 426112c

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

extmod/moduos_dupterm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ STATIC mp_obj_t mp_uos_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
6969
}
7070
} else {
7171
if (args[0] == mp_const_none) {
72-
MP_STATE_PORT(term_obj) = NULL;
72+
MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
7373
} else {
7474
MP_STATE_PORT(term_obj) = args[0];
75+
if (MP_STATE_PORT(dupterm_arr_obj) == MP_OBJ_NULL) {
76+
MP_STATE_PORT(dupterm_arr_obj) = mp_obj_new_bytearray(1, "");
77+
}
7578
}
7679
return mp_const_none;
7780
}

py/mpstate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ typedef struct _mp_state_vm_t {
143143

144144
#if MICROPY_PY_OS_DUPTERM
145145
mp_obj_t term_obj;
146+
mp_obj_t dupterm_arr_obj;
146147
#endif
147148

148149
#if MICROPY_PY_LWIP_SLIP

0 commit comments

Comments
 (0)