From a22b6ebff1cee6e2d623a85d9aa8f93dff1512b4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 4 Jul 2016 21:34:40 +0300 Subject: [PATCH] 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. --- esp8266/esp_mphal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 9f090a0973..7d33f89cbf 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -161,16 +161,16 @@ static int call_dupterm_read(void) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { - mp_obj_t read_m[3]; - mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_read, read_m); - read_m[2] = MP_OBJ_NEW_SMALL_INT(1); - mp_obj_t res = mp_call_method_n_kw(1, 0, read_m); + mp_obj_t readinto_m[3]; + mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m); + readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj); + mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m); if (res == mp_const_none) { nlr_pop(); return -2; } mp_buffer_info_t bufinfo; - mp_get_buffer_raise(res, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ); if (bufinfo.len == 0) { mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL); nlr_pop();