all: Use mp_obj_malloc everywhere it's applicable.
This replaces occurences of
foo_t *foo = m_new_obj(foo_t);
foo->base.type = &foo_type;
with
foo_t *foo = mp_obj_malloc(foo_t, &foo_type);
Excludes any places where base is a sub-field or when new0/memset is used.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
6a3bc0e1a1
commit
0e7bfc88c6
@@ -60,8 +60,7 @@ const mp_obj_type_t microbit_repeat_iterator_type = {
|
||||
};
|
||||
|
||||
mp_obj_t microbit_repeat_iterator(mp_obj_t iterable) {
|
||||
repeat_iterator_t *result = m_new_obj(repeat_iterator_t);
|
||||
result->base.type = µbit_repeat_iterator_type;
|
||||
repeat_iterator_t *result = mp_obj_malloc(repeat_iterator_t, µbit_repeat_iterator_type);
|
||||
result->iterable = iterable;
|
||||
result->index = -1;
|
||||
return result;
|
||||
|
||||
@@ -113,8 +113,7 @@ mp_int_t imageHeight(microbit_image_obj_t * p_image) {
|
||||
}
|
||||
|
||||
STATIC greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) {
|
||||
greyscale_t *result = m_new_obj_var(greyscale_t, uint8_t, (w*h+1)>>1);
|
||||
result->base.type = µbit_image_type;
|
||||
greyscale_t *result = mp_obj_malloc_var(greyscale_t, uint8_t, (w*h+1)>>1, µbit_image_type);
|
||||
result->five = 0;
|
||||
result->width = w;
|
||||
result->height = h;
|
||||
@@ -722,8 +721,7 @@ extern const mp_obj_type_t microbit_scrolling_string_type;
|
||||
extern const mp_obj_type_t microbit_scrolling_string_iterator_type;
|
||||
|
||||
mp_obj_t scrolling_string_image_iterable(const char* str, mp_uint_t len, mp_obj_t ref, bool monospace, bool repeat) {
|
||||
scrolling_string_t *result = m_new_obj(scrolling_string_t);
|
||||
result->base.type = µbit_scrolling_string_type;
|
||||
scrolling_string_t *result = mp_obj_malloc(scrolling_string_t, µbit_scrolling_string_type);
|
||||
result->str = str;
|
||||
result->len = len;
|
||||
result->ref = ref;
|
||||
@@ -771,8 +769,7 @@ static void restart(scrolling_string_iterator_t *iter) {
|
||||
STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
(void)iter_buf;
|
||||
scrolling_string_t *str = (scrolling_string_t *)o_in;
|
||||
scrolling_string_iterator_t *result = m_new_obj(scrolling_string_iterator_t);
|
||||
result->base.type = µbit_scrolling_string_iterator_type;
|
||||
scrolling_string_iterator_t *result = mp_obj_malloc(scrolling_string_iterator_t, µbit_scrolling_string_iterator_type);
|
||||
result->img = greyscale_new(5,5);
|
||||
result->start = str->str;
|
||||
result->ref = str->ref;
|
||||
@@ -923,8 +920,7 @@ typedef struct _facade_iterator_t {
|
||||
} facade_iterator_t;
|
||||
|
||||
mp_obj_t microbit_string_facade(mp_obj_t string) {
|
||||
string_image_facade_t *result = m_new_obj(string_image_facade_t);
|
||||
result->base.type = &string_image_facade_type;
|
||||
string_image_facade_t *result = mp_obj_malloc(string_image_facade_t, &string_image_facade_type);
|
||||
result->string = string;
|
||||
result->image = greyscale_new(5,5);
|
||||
return result;
|
||||
|
||||
@@ -70,9 +70,7 @@ STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
machine_temp_obj_t *self = m_new_obj(machine_temp_obj_t);
|
||||
|
||||
self->base.type = &machine_temp_type;
|
||||
machine_temp_obj_t *self = mp_obj_malloc(machine_temp_obj_t, &machine_temp_type);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
@@ -165,8 +165,7 @@ STATIC mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
return MP_OBJ_FROM_PTR(&nrf_flash_obj);
|
||||
}
|
||||
|
||||
nrf_flash_obj_t *self = m_new_obj(nrf_flash_obj_t);
|
||||
self->base.type = &nrf_flashbdev_type;
|
||||
nrf_flash_obj_t *self = mp_obj_malloc(nrf_flash_obj_t, &nrf_flashbdev_type);
|
||||
|
||||
mp_int_t start = args[ARG_start].u_int;
|
||||
mp_int_t len = args[ARG_len].u_int;
|
||||
|
||||
@@ -50,8 +50,7 @@ STATIC mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_characteristic_obj_t *s = m_new_obj(ubluepy_characteristic_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_characteristic_obj_t *s = mp_obj_malloc(ubluepy_characteristic_obj_t, type);
|
||||
|
||||
mp_obj_t uuid_obj = args[0].u_obj;
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ STATIC void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
ubluepy_delegate_obj_t *s = m_new_obj(ubluepy_delegate_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_delegate_obj_t *s = mp_obj_malloc(ubluepy_delegate_obj_t, type);
|
||||
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ STATIC mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_descriptor_obj_t * s = m_new_obj(ubluepy_descriptor_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_descriptor_obj_t * s = mp_obj_malloc(ubluepy_descriptor_obj_t, type);
|
||||
|
||||
mp_obj_t uuid_obj = args[ARG_NEW_UUID].u_obj;
|
||||
|
||||
|
||||
@@ -114,8 +114,7 @@ STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_peripheral_obj_t *s = m_new_obj(ubluepy_peripheral_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_peripheral_obj_t *s = mp_obj_malloc(ubluepy_peripheral_obj_t, type);
|
||||
|
||||
s->delegate = mp_const_none;
|
||||
s->conn_handler = mp_const_none;
|
||||
@@ -291,11 +290,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral
|
||||
#if MICROPY_PY_UBLUEPY_CENTRAL
|
||||
|
||||
void static disc_add_service(mp_obj_t self, ble_drv_service_data_t * p_service_data) {
|
||||
ubluepy_service_obj_t * p_service = m_new_obj(ubluepy_service_obj_t);
|
||||
p_service->base.type = &ubluepy_service_type;
|
||||
ubluepy_service_obj_t * p_service = mp_obj_malloc(ubluepy_service_obj_t, &ubluepy_service_type);
|
||||
|
||||
ubluepy_uuid_obj_t * p_uuid = m_new_obj(ubluepy_uuid_obj_t);
|
||||
p_uuid->base.type = &ubluepy_uuid_type;
|
||||
ubluepy_uuid_obj_t * p_uuid = mp_obj_malloc(ubluepy_uuid_obj_t, &ubluepy_uuid_type);
|
||||
|
||||
p_service->p_uuid = p_uuid;
|
||||
|
||||
@@ -314,11 +311,9 @@ void static disc_add_service(mp_obj_t self, ble_drv_service_data_t * p_service_d
|
||||
|
||||
void static disc_add_char(mp_obj_t service_in, ble_drv_char_data_t * p_desc_data) {
|
||||
ubluepy_service_obj_t * p_service = MP_OBJ_TO_PTR(service_in);
|
||||
ubluepy_characteristic_obj_t * p_char = m_new_obj(ubluepy_characteristic_obj_t);
|
||||
p_char->base.type = &ubluepy_characteristic_type;
|
||||
ubluepy_characteristic_obj_t * p_char = mp_obj_malloc(ubluepy_characteristic_obj_t, &ubluepy_characteristic_type);
|
||||
|
||||
ubluepy_uuid_obj_t * p_uuid = m_new_obj(ubluepy_uuid_obj_t);
|
||||
p_uuid->base.type = &ubluepy_uuid_type;
|
||||
ubluepy_uuid_obj_t * p_uuid = mp_obj_malloc(ubluepy_uuid_obj_t, &ubluepy_uuid_type);
|
||||
|
||||
p_char->p_uuid = p_uuid;
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) {
|
||||
ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
ubluepy_scan_entry_obj_t * item = m_new_obj(ubluepy_scan_entry_obj_t);
|
||||
item->base.type = &ubluepy_scan_entry_type;
|
||||
ubluepy_scan_entry_obj_t * item = mp_obj_malloc(ubluepy_scan_entry_obj_t, &ubluepy_scan_entry_type);
|
||||
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, 17);
|
||||
@@ -78,8 +77,7 @@ STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_scanner_obj_t * s = m_new_obj(ubluepy_scanner_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_scanner_obj_t * s = mp_obj_malloc(ubluepy_scanner_obj_t, type);
|
||||
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_service_obj_t *s = m_new_obj(ubluepy_service_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_service_obj_t *s = mp_obj_malloc(ubluepy_service_obj_t, type);
|
||||
|
||||
mp_obj_t uuid_obj = args[ARG_NEW_UUID].u_obj;
|
||||
|
||||
|
||||
@@ -57,8 +57,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
ubluepy_uuid_obj_t *s = m_new_obj(ubluepy_uuid_obj_t);
|
||||
s->base.type = type;
|
||||
ubluepy_uuid_obj_t *s = mp_obj_malloc(ubluepy_uuid_obj_t, type);
|
||||
|
||||
mp_obj_t uuid_obj = args[ARG_NEW_UUID].u_obj;
|
||||
|
||||
|
||||
@@ -360,12 +360,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len
|
||||
}
|
||||
|
||||
STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) {
|
||||
file_descriptor_obj *res = m_new_obj(file_descriptor_obj);
|
||||
if (binary) {
|
||||
res->base.type = &uos_mbfs_fileio_type;
|
||||
} else {
|
||||
res->base.type = &uos_mbfs_textio_type;
|
||||
}
|
||||
file_descriptor_obj *res = m_new_obj(file_descriptor_obj, binary ? &uos_mbfs_fileio_type : &uos_mbfs_textio_type);
|
||||
res->start_chunk = start_chunk;
|
||||
res->seek_chunk = start_chunk;
|
||||
res->seek_offset = file_system_chunks[start_chunk].header.name_len+2;
|
||||
@@ -595,8 +590,7 @@ STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_ilistdir(void) {
|
||||
uos_mbfs_ilistdir_it_t *iter = m_new_obj(uos_mbfs_ilistdir_it_t);
|
||||
iter->base.type = &mp_type_polymorph_iter;
|
||||
uos_mbfs_ilistdir_it_t *iter = mp_obj_malloc(uos_mbfs_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
iter->iternext = uos_mbfs_ilistdir_it_iternext;
|
||||
iter->index = 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user