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
@@ -80,8 +80,7 @@ STATIC mp_obj_t adc_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||
ADC_SetChannelConfig(adc_instance, 0UL, &channel_config); // NOTE: we always choose channel group '0' since we only perform software triggered conversion
|
||||
|
||||
// Create ADC Instance
|
||||
machine_adc_obj_t *o = m_new_obj(machine_adc_obj_t);
|
||||
o->base.type = &machine_adc_type;
|
||||
machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);
|
||||
o->adc = adc_instance;
|
||||
o->channel = (uint8_t)channel;
|
||||
o->channel_group = 0;
|
||||
|
||||
@@ -113,8 +113,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
}
|
||||
|
||||
// Get I2C Object.
|
||||
machine_i2c_obj_t *self = m_new_obj(machine_i2c_obj_t);
|
||||
self->base.type = &machine_i2c_type;
|
||||
machine_i2c_obj_t *self = mp_obj_malloc(machine_i2c_obj_t, &machine_i2c_type);
|
||||
self->i2c_id = i2c_id;
|
||||
self->i2c_hw_id = i2c_index_table[i2c_id]; // the hw i2c number 1..n
|
||||
self->i2c_inst = i2c_base_ptr_table[self->i2c_hw_id];
|
||||
|
||||
@@ -953,9 +953,8 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg
|
||||
|
||||
machine_i2s_obj_t *self;
|
||||
if (MP_STATE_PORT(machine_i2s_obj)[i2s_id_zero_base] == NULL) {
|
||||
self = m_new_obj(machine_i2s_obj_t);
|
||||
self = mp_obj_malloc(machine_i2s_obj_t, &machine_i2s_type);
|
||||
MP_STATE_PORT(machine_i2s_obj)[i2s_id_zero_base] = self;
|
||||
self->base.type = &machine_i2s_type;
|
||||
self->i2s_id = i2s_id;
|
||||
self->edmaTcd = &edmaTcd[i2s_id_zero_base];
|
||||
} else {
|
||||
|
||||
@@ -494,8 +494,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
}
|
||||
|
||||
// Create and populate the PWM object.
|
||||
machine_pwm_obj_t *self = m_new_obj(machine_pwm_obj_t);
|
||||
self->base.type = &machine_pwm_type;
|
||||
machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type);
|
||||
self->is_flexpwm = is_flexpwm;
|
||||
self->instance = af_obj1->instance;
|
||||
self->module = module;
|
||||
|
||||
@@ -153,8 +153,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
||||
|
||||
// Get peripheral object.
|
||||
uint8_t spi_hw_id = spi_index_table[spi_id]; // the hw spi number 1..n
|
||||
machine_spi_obj_t *self = m_new_obj(machine_spi_obj_t);
|
||||
self->base.type = &machine_spi_type;
|
||||
machine_spi_obj_t *self = mp_obj_malloc(machine_spi_obj_t, &machine_spi_type);
|
||||
self->spi_id = spi_id;
|
||||
self->spi_inst = spi_base_ptr_table[spi_hw_id];
|
||||
self->spi_hw_id = spi_hw_id;
|
||||
|
||||
@@ -277,8 +277,7 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
|
||||
// Create the UART object and fill it with defaults.
|
||||
uint8_t uart_hw_id = uart_index_table[uart_id]; // the hw uart number 1..n
|
||||
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->id = uart_id;
|
||||
self->lpuart = uart_base_ptr_table[uart_hw_id];
|
||||
self->invert = false;
|
||||
|
||||
Reference in New Issue
Block a user