py: Use m_{new,renew,del} consistently.
This is so all memory requests go through the same interface.
This commit is contained in:
parent
eb0a7129a5
commit
4d77e1a034
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue