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
@@ -84,9 +84,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("explicit choice of timeout is not implemented"));
|
||||
}
|
||||
|
||||
machine_hard_i2c_obj_t *self = m_new_obj(machine_hard_i2c_obj_t);
|
||||
|
||||
self->base.type = &machine_hard_i2c_type;
|
||||
machine_hard_i2c_obj_t *self = mp_obj_malloc(machine_hard_i2c_obj_t, &machine_hard_i2c_type);
|
||||
self->dev = dev;
|
||||
self->restart = false;
|
||||
|
||||
|
||||
@@ -106,9 +106,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
||||
.cs = NULL
|
||||
};
|
||||
|
||||
machine_hard_spi_obj_t *self = m_new_obj(machine_hard_spi_obj_t);
|
||||
|
||||
self->base.type = &machine_hard_spi_type;
|
||||
machine_hard_spi_obj_t *self = mp_obj_malloc(machine_hard_spi_obj_t, &machine_hard_spi_type);
|
||||
self->dev = dev;
|
||||
self->config = cfg;
|
||||
|
||||
|
||||
@@ -77,8 +77,7 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
GET_STR_DATA_LEN(args[0], name, name_len);
|
||||
|
||||
machine_uart_obj_t *self = m_new_obj(machine_uart_obj_t);
|
||||
self->base.type = &machine_uart_type;
|
||||
machine_uart_obj_t *self = mp_obj_malloc(machine_uart_obj_t, &machine_uart_type);
|
||||
self->dev = device_get_binding(name);
|
||||
if (!self->dev) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("Bad device name"));
|
||||
|
||||
@@ -40,8 +40,7 @@ typedef struct _mp_obj_sensor_t {
|
||||
|
||||
STATIC mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
mp_obj_sensor_t *o = m_new_obj(mp_obj_sensor_t);
|
||||
o->base.type = type;
|
||||
mp_obj_sensor_t *o = mp_obj_malloc(mp_obj_sensor_t, type);
|
||||
o->dev = device_get_binding(mp_obj_str_get_str(args[0]));
|
||||
if (o->dev == NULL) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("dev not found"));
|
||||
|
||||
@@ -54,8 +54,7 @@ STATIC void zephyr_disk_access_print(const mp_print_t *print, mp_obj_t self_in,
|
||||
|
||||
STATIC mp_obj_t zephyr_disk_access_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
zephyr_disk_access_obj_t *self = m_new_obj(zephyr_disk_access_obj_t);
|
||||
self->base.type = type;
|
||||
zephyr_disk_access_obj_t *self = mp_obj_malloc(zephyr_disk_access_obj_t, type);
|
||||
self->pdrv = mp_obj_str_get_str(args[0]);
|
||||
|
||||
if (disk_access_init(self->pdrv) != 0) {
|
||||
@@ -156,8 +155,7 @@ STATIC void zephyr_flash_area_print(const mp_print_t *print, mp_obj_t self_in, m
|
||||
|
||||
STATIC mp_obj_t zephyr_flash_area_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 2, false);
|
||||
zephyr_flash_area_obj_t *self = m_new_obj(zephyr_flash_area_obj_t);
|
||||
self->base.type = type;
|
||||
zephyr_flash_area_obj_t *self = mp_obj_malloc(zephyr_flash_area_obj_t, type);
|
||||
self->id = mp_obj_get_int(args[0]);
|
||||
self->block_size = mp_obj_get_int(args[1]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user