Skip to content

Commit a22b6eb

Browse files
committed
esp8266/esp_mphal: call_dupterm_read: Use readinto() method.
It's memory fragmentation hazard to allocate 1-char string each time by calling read() method.
1 parent e07ef8f commit a22b6eb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

esp8266/esp_mphal.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ static int call_dupterm_read(void) {
161161

162162
nlr_buf_t nlr;
163163
if (nlr_push(&nlr) == 0) {
164-
mp_obj_t read_m[3];
165-
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_read, read_m);
166-
read_m[2] = MP_OBJ_NEW_SMALL_INT(1);
167-
mp_obj_t res = mp_call_method_n_kw(1, 0, read_m);
164+
mp_obj_t readinto_m[3];
165+
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m);
166+
readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj);
167+
mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
168168
if (res == mp_const_none) {
169169
nlr_pop();
170170
return -2;
171171
}
172172
mp_buffer_info_t bufinfo;
173-
mp_get_buffer_raise(res, &bufinfo, MP_BUFFER_READ);
173+
mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ);
174174
if (bufinfo.len == 0) {
175175
mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
176176
nlr_pop();

0 commit comments

Comments
 (0)