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.
This commit is contained in:
parent
e07ef8f1a2
commit
a22b6ebff1
@ -161,16 +161,16 @@ static int call_dupterm_read(void) {
|
|||||||
|
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
mp_obj_t read_m[3];
|
mp_obj_t readinto_m[3];
|
||||||
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_read, read_m);
|
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m);
|
||||||
read_m[2] = MP_OBJ_NEW_SMALL_INT(1);
|
readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj);
|
||||||
mp_obj_t res = mp_call_method_n_kw(1, 0, read_m);
|
mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
|
||||||
if (res == mp_const_none) {
|
if (res == mp_const_none) {
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
mp_buffer_info_t bufinfo;
|
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) {
|
if (bufinfo.len == 0) {
|
||||||
mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
|
mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
|
Loading…
Reference in New Issue
Block a user