From 4d77e1a0344aa22964b4db5a71181183431e9a53 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Feb 2015 09:34:51 +0000 Subject: [PATCH] py: Use m_{new,renew,del} consistently. This is so all memory requests go through the same interface. --- py/lexerstr.c | 2 +- py/objarray.c | 6 +++--- py/objexcept.c | 4 ++-- py/objint.c | 2 +- py/objtuple.c | 2 +- py/pfenv.c | 2 +- stmhal/sdcard.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/py/lexerstr.c b/py/lexerstr.c index cab3ed3612..5481b1032d 100644 --- a/py/lexerstr.c +++ b/py/lexerstr.c @@ -43,7 +43,7 @@ STATIC mp_uint_t str_buf_next_byte(mp_lexer_str_buf_t *sb) { STATIC void str_buf_free(mp_lexer_str_buf_t *sb) { if (sb->free_len > 0) { - m_free((char*)sb->src_beg, sb->free_len); + m_del(char, (char*)sb->src_beg, sb->free_len); } m_del_obj(mp_lexer_str_buf_t, sb); } diff --git a/py/objarray.c b/py/objarray.c index 25d9daea97..e2fee1f2ed 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -116,7 +116,7 @@ STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) { o->typecode = typecode; o->free = 0; o->len = n; - o->items = m_malloc(typecode_size * o->len); + o->items = m_new(byte, typecode_size * o->len); return o; } #endif @@ -298,7 +298,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { int item_sz = mp_binary_get_size('@', self->typecode, NULL); // TODO: alloc policy self->free = 8; - self->items = m_realloc(self->items, item_sz * self->len, item_sz * (self->len + self->free)); + self->items = m_renew(byte, self->items, item_sz * self->len, item_sz * (self->len + self->free)); mp_seq_clear(self->items, self->len + 1, self->len + self->free, item_sz); } mp_binary_set_val_array(self->typecode, self->items, self->len++, arg); @@ -324,7 +324,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { // make sure we have enough room to extend // TODO: alloc policy; at the moment we go conservative if (self->free < len) { - self->items = m_realloc(self->items, (self->len + self->free) * sz, (self->len + len) * sz); + self->items = m_renew(byte, self->items, (self->len + self->free) * sz, (self->len + len) * sz); self->free = 0; } else { self->free -= len; diff --git a/py/objexcept.c b/py/objexcept.c index 8bd802e94f..987a54fda7 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -64,7 +64,7 @@ mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in) { mp_int_t size = mp_obj_get_int(size_in); void *buf = NULL; if (size > 0) { - buf = m_malloc(size); + buf = m_new(byte, size); } int old_size = mp_emergency_exception_buf_size; @@ -78,7 +78,7 @@ mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in) { MICROPY_END_ATOMIC_SECTION(atomic_state); if (old_buf != NULL) { - m_free(old_buf, old_size); + m_del(byte, old_buf, old_size); } return mp_const_none; } diff --git a/py/objint.c b/py/objint.c index 4a4a21aaf3..0fb2a38262 100644 --- a/py/objint.c +++ b/py/objint.c @@ -137,7 +137,7 @@ void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, print(env, "%s", str); if (buf != stack_buf) { - m_free(buf, buf_size); + m_del(char, buf, buf_size); } } diff --git a/py/objtuple.c b/py/objtuple.c index 55358a66a0..d575decfd4 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -95,7 +95,7 @@ STATIC mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uin } mp_obj_t tuple = mp_obj_new_tuple(len, items); - m_free(items, alloc); + m_del(mp_obj_t, items, alloc); return tuple; } diff --git a/py/pfenv.c b/py/pfenv.c index 09ca0ef80e..8bc42dcdf9 100644 --- a/py/pfenv.c +++ b/py/pfenv.c @@ -308,7 +308,7 @@ int pfenv_print_mp_int(const pfenv_t *pfenv, mp_obj_t x, int sgn, int base, int } if (buf != stack_buf) { - m_free(buf, buf_size); + m_del(char, buf, buf_size); } return len; } diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index 8c9febd9aa..5686f949a3 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -282,7 +282,7 @@ STATIC mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) { mp_uint_t ret = sdcard_read_blocks(dest, mp_obj_get_int(block_num), 1); if (ret != 0) { - m_free(dest, SDCARD_BLOCK_SIZE); + m_del(uint8_t, dest, SDCARD_BLOCK_SIZE); nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "sdcard_read_blocks failed [%u]", ret)); }