MicroPython: Switch to mp_obj_malloc_with_finaliser.

feature/usb
Phil Howard 2024-02-27 10:59:29 +00:00 zatwierdzone przez Phil Howard
rodzic fd4eb165f8
commit bd117adf3f
20 zmienionych plików z 33 dodań i 66 usunięć

Wyświetl plik

@ -21,8 +21,7 @@ mp_obj_t adcfft_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
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);
adcfft_obj_t *self = m_new_obj_with_finaliser(adcfft_obj_t);
self->base.type = &adcfft_type;
adcfft_obj_t *self = mp_obj_malloc_with_finaliser(adcfft_obj_t, &adcfft_type);
unsigned int adc_channel = args[ARG_adc_channel].u_int;
unsigned int adc_gpio = args[ARG_adc_gpio].u_int;

Wyświetl plik

@ -98,8 +98,7 @@ mp_obj_t Badger2040_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
buffer = m_new(uint8_t, width * height / 8);
}
badger2040_obj = m_new_obj_with_finaliser(_Badger2040_obj_t);
badger2040_obj->base.type = &Badger2040_type;
badger2040_obj = mp_obj_malloc_with_finaliser(_Badger2040_obj_t, &Badger2040_type);
badger2040_obj->buf = buffer;
badger2040_obj->badger2040 = m_new_class(pimoroni::Badger2040, buffer);
badger2040_obj->badger2040->init();

Wyświetl plik

@ -51,8 +51,7 @@ mp_obj_t MLX90640_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw
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);
_ModMLX90640_obj_t *self = m_new_obj_with_finaliser(_ModMLX90640_obj_t);
self->base.type = &MLX90640_type;
_ModMLX90640_obj_t *self = mp_obj_malloc_with_finaliser(_ModMLX90640_obj_t, &MLX90640_type);
self->i2c = PimoroniI2C_from_machine_i2c_or_native(args[ARG_i2c].u_obj);
self->address = args[ARG_address].u_int;

Wyświetl plik

@ -74,8 +74,7 @@ mp_obj_t make_new(enum ChipType chip, const mp_obj_type_t *type, size_t n_args,
int slot = args[ARG_slot].u_int;
if(slot == BG_SPI_FRONT || slot == BG_SPI_BACK) {
self = m_new_obj_with_finaliser(breakout_pmw3901_BreakoutPMW3901_obj_t);
self->base.type = &breakout_pmw3901_BreakoutPMW3901_type;
self = mp_obj_malloc_with_finaliser(breakout_pmw3901_BreakoutPMW3901_obj_t, &breakout_pmw3901_BreakoutPMW3901_type);
if(chip == ChipType::PMW3901) {
BreakoutPMW3901 *breakout = m_new_class(BreakoutPMW3901, (BG_SPI_SLOT)slot);
@ -137,8 +136,7 @@ mp_obj_t make_new(enum ChipType chip, const mp_obj_type_t *type, size_t n_args,
mp_raise_ValueError(MP_ERROR_TEXT("bad MISO pin"));
}
self = m_new_obj_with_finaliser(breakout_pmw3901_BreakoutPMW3901_obj_t);
self->base.type = &breakout_pmw3901_BreakoutPMW3901_type;
self = mp_obj_malloc_with_finaliser(breakout_pmw3901_BreakoutPMW3901_obj_t, &breakout_pmw3901_BreakoutPMW3901_type);
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
if(chip == ChipType::PMW3901) {

Wyświetl plik

@ -60,8 +60,7 @@ mp_obj_t VL53L5CX_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw
int addr = args[ARG_addr].u_int;
self = m_new_obj_with_finaliser(_VL53L5CX_obj_t);
self->base.type = &VL53L5CX_type;
self = mp_obj_malloc_with_finaliser(_VL53L5CX_obj_t, &VL53L5CX_type);
self->i2c = PimoroniI2C_from_machine_i2c_or_native(args[ARG_i2c].u_obj);

Wyświetl plik

@ -391,8 +391,7 @@ mp_obj_t CosmicUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size_t
CosmicUnicorn *cosmic = m_new_class(CosmicUnicorn);
cosmic->init();
self = m_new_obj_with_finaliser(_CosmicUnicorn_obj_t);
self->base.type = &CosmicUnicorn_type;
self = mp_obj_malloc_with_finaliser(_CosmicUnicorn_obj_t, &CosmicUnicorn_type);
self->cosmic = cosmic;
return MP_OBJ_FROM_PTR(self);
@ -507,8 +506,7 @@ extern mp_obj_t CosmicUnicorn_synth_channel(mp_obj_t self_in, mp_obj_t channel_i
// NOTE This seems to work, in that it give MP access to the calibration object
// Could very easily mess up in weird ways once object deletion is considered?
_Channel_obj_t *channel_obj = m_new_obj_with_finaliser(_Channel_obj_t);
channel_obj->base.type = &Channel_type;
_Channel_obj_t *channel_obj = mp_obj_malloc_with_finaliser(_Channel_obj_t, &Channel_type);
channel_obj->channel = &self->cosmic->synth_channel(channel);
return MP_OBJ_FROM_PTR(channel_obj);

Wyświetl plik

@ -144,8 +144,7 @@ mp_obj_t Encoder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
mp_raise_msg(&mp_type_RuntimeError, "unable to allocate the hardware resources needed to initialise this Encoder. Try running `import gc` followed by `gc.collect()` before creating it");
}
self = m_new_obj_with_finaliser(_Encoder_obj_t);
self->base.type = &Encoder_type;
self = mp_obj_malloc_with_finaliser(_Encoder_obj_t, &Encoder_type);
self->encoder = encoder;
return MP_OBJ_FROM_PTR(self);

Wyświetl plik

@ -391,8 +391,7 @@ mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size
GalacticUnicorn *galactic = m_new_class(GalacticUnicorn);
galactic->init();
self = m_new_obj_with_finaliser(_GalacticUnicorn_obj_t);
self->base.type = &GalacticUnicorn_type;
self = mp_obj_malloc_with_finaliser(_GalacticUnicorn_obj_t, &GalacticUnicorn_type);
self->galactic = galactic;
return MP_OBJ_FROM_PTR(self);
@ -507,8 +506,7 @@ extern mp_obj_t GalacticUnicorn_synth_channel(mp_obj_t self_in, mp_obj_t channel
// NOTE This seems to work, in that it give MP access to the calibration object
// Could very easily mess up in weird ways once object deletion is considered?
_Channel_obj_t *channel_obj = m_new_obj_with_finaliser(_Channel_obj_t);
channel_obj->base.type = &Channel_type;
_Channel_obj_t *channel_obj = mp_obj_malloc_with_finaliser(_Channel_obj_t, &Channel_type);
channel_obj->channel = &self->galactic->synth_channel(channel);
return MP_OBJ_FROM_PTR(channel_obj);

Wyświetl plik

@ -120,8 +120,7 @@ mp_obj_t Hub75_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
buffer = m_new(Pixel, width * height);
}
hub75_obj = m_new_obj_with_finaliser(_Hub75_obj_t);
hub75_obj->base.type = &Hub75_type;
hub75_obj = mp_obj_malloc_with_finaliser(_Hub75_obj_t, &Hub75_type);
hub75_obj->buf = buffer;
hub75_obj->hub75 = m_new_class(Hub75, width, height, buffer, paneltype, stb_invert, color_order);

Wyświetl plik

@ -212,8 +212,7 @@ mp_obj_t _JPEG_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
if(!MP_OBJ_IS_TYPE(args[ARG_picographics].u_obj, &ModPicoGraphics_type)) mp_raise_ValueError(MP_ERROR_TEXT("PicoGraphics Object Required"));
_JPEG_obj_t *self = m_new_obj_with_finaliser(_JPEG_obj_t);
self->base.type = &JPEG_type;
_JPEG_obj_t *self = mp_obj_malloc_with_finaliser(_JPEG_obj_t, &JPEG_type);
self->jpeg = m_new_class(JPEGDEC);
self->graphics = (ModPicoGraphics_obj_t *)MP_OBJ_TO_PTR(args[ARG_picographics].u_obj);

Wyświetl plik

@ -189,8 +189,7 @@ mp_obj_t Motor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
mp_raise_ValueError("mode out of range. Expected FAST_DECAY (0) or SLOW_DECAY (1)");
}
self = m_new_obj_with_finaliser(_Motor_obj_t);
self->base.type = &Motor_type;
self = mp_obj_malloc_with_finaliser(_Motor_obj_t, &Motor_type);
self->motor = m_new_class(Motor, pins, (Direction)direction, speed_scale, zeropoint, deadzone, freq, (DecayMode)mode, args[ARG_ph_en_driver].u_bool);
self->motor->init();
@ -741,8 +740,7 @@ mp_obj_t MotorCluster_make_new(const mp_obj_type_t *type, size_t n_args, size_t
mp_raise_msg(&mp_type_RuntimeError, "unable to allocate the hardware resources needed to initialise this MotorCluster. Try running `import gc` followed by `gc.collect()` before creating it");
}
self = m_new_obj_with_finaliser(_MotorCluster_obj_t);
self->base.type = &MotorCluster_type;
self = mp_obj_malloc_with_finaliser(_MotorCluster_obj_t, &MotorCluster_type);
self->cluster = cluster;
return MP_OBJ_FROM_PTR(self);

Wyświetl plik

@ -18,8 +18,7 @@ typedef struct _PicoKeypad_obj_t {
mp_obj_t picokeypad_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
_PicoKeypad_obj_t *self = nullptr;
self = m_new_obj_with_finaliser(PicoKeypad_obj_t);
self->base.type = &PicoKeypad_type;
self = mp_obj_malloc_with_finaliser(PicoKeypad_obj_t, &PicoKeypad_type);
self->keypad = m_new_class(PicoRGBKeypad);
self->keypad->init();

Wyświetl plik

@ -40,8 +40,7 @@ typedef struct _ModPicoGraphics_obj_t {
mp_obj_t picoscroll_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
_PicoScroll_obj_t *self = nullptr;
self = m_new_obj_with_finaliser(PicoScroll_obj_t);
self->base.type = &PicoScroll_type;
self = mp_obj_malloc_with_finaliser(PicoScroll_obj_t, &PicoScroll_type);
self->scroll = m_new_class(PicoScroll);
self->scroll->init();

Wyświetl plik

@ -31,8 +31,7 @@ typedef struct _ModPicoGraphics_obj_t {
} ModPicoGraphics_obj_t;
mp_obj_t picounicorn_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
picounicorn_obj_t *self = m_new_obj_with_finaliser(picounicorn_obj_t);
self->base.type = &picounicorn_type;
picounicorn_obj_t *self = mp_obj_malloc_with_finaliser(picounicorn_obj_t, &picounicorn_type);
self->unicorn = m_new_class(PicoUnicorn);
return MP_OBJ_FROM_PTR(self);
}

Wyświetl plik

@ -280,8 +280,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, 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);
self = m_new_obj_with_finaliser(ModPicoGraphics_obj_t);
self->base.type = &ModPicoGraphics_type;
self = mp_obj_malloc_with_finaliser(ModPicoGraphics_obj_t, &ModPicoGraphics_type);
PicoGraphicsDisplay display = (PicoGraphicsDisplay)args[ARG_display].u_int;

Wyświetl plik

@ -122,8 +122,7 @@ mp_obj_t RECTANGLE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_k
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);
_POLYGON_obj_t *self = m_new_obj_with_finaliser(_POLYGON_obj_t);
self->base.type = &POLYGON_type;
_POLYGON_obj_t *self = mp_obj_malloc_with_finaliser(_POLYGON_obj_t, &POLYGON_type);
int x = args[ARG_x].u_int;
int y = args[ARG_y].u_int;
@ -154,8 +153,7 @@ mp_obj_t REGULAR_POLYGON_make_new(const mp_obj_type_t *type, size_t n_args, 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);
_POLYGON_obj_t *self = m_new_obj_with_finaliser(_POLYGON_obj_t);
self->base.type = &POLYGON_type;
_POLYGON_obj_t *self = mp_obj_malloc_with_finaliser(_POLYGON_obj_t, &POLYGON_type);
Point origin(args[ARG_x].u_int, args[ARG_y].u_int);
unsigned int sides = args[ARG_sides].u_int;
@ -185,8 +183,7 @@ mp_obj_t REGULAR_POLYGON_make_new(const mp_obj_type_t *type, size_t n_args, size
}
mp_obj_t POLYGON_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
_POLYGON_obj_t *self = m_new_obj_with_finaliser(_POLYGON_obj_t);
self->base.type = &POLYGON_type;
_POLYGON_obj_t *self = mp_obj_malloc_with_finaliser(_POLYGON_obj_t, &POLYGON_type);
size_t num_points = n_args;
const mp_obj_t *points = all_args;

Wyświetl plik

@ -96,8 +96,7 @@ mp_obj_t PlasmaWS2812_make_new(const mp_obj_type_t *type, size_t n_args, size_t
buffer = m_new(WS2812::RGB, num_leds);
}
self = m_new_obj_with_finaliser(_PlasmaWS2812_obj_t);
self->base.type = &PlasmaWS2812_type;
self = mp_obj_malloc_with_finaliser(_PlasmaWS2812_obj_t, &PlasmaWS2812_type);
self->buf = buffer;
self->ws2812 = m_new_class(WS2812, num_leds, pio, sm, dat, freq, rgbw, color_order, (WS2812::RGB *)buffer);
@ -307,8 +306,7 @@ mp_obj_t PlasmaAPA102_make_new(const mp_obj_type_t *type, size_t n_args, size_t
buffer[i].brightness(15);
}
self = m_new_obj_with_finaliser(_PlasmaAPA102_obj_t);
self->base.type = &PlasmaAPA102_type;
self = mp_obj_malloc_with_finaliser(_PlasmaAPA102_obj_t, &PlasmaAPA102_type);
self->buf = buffer;
self->apa102 = m_new_class(APA102, num_leds, pio, sm, dat, clk, freq, buffer);

Wyświetl plik

@ -326,8 +326,7 @@ mp_obj_t _PNG_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, co
if(!MP_OBJ_IS_TYPE(args[ARG_picographics].u_obj, &ModPicoGraphics_type)) mp_raise_ValueError(MP_ERROR_TEXT("PicoGraphics Object Required"));
_PNG_obj_t *self = m_new_obj_with_finaliser(_PNG_obj_t);
self->base.type = &PNG_type;
_PNG_obj_t *self = mp_obj_malloc_with_finaliser(_PNG_obj_t, &PNG_type);
self->png = m_new_class(PNG);
//mp_printf(&mp_plat_print, "PNG RAM %fK\n", sizeof(PNG) / 1024.0f);

Wyświetl plik

@ -73,8 +73,7 @@ mp_obj_t Calibration_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
}
servo::CalibrationType calibration_type = (servo::CalibrationType)type;
self = m_new_obj_with_finaliser(_Calibtration_obj_t);
self->base.type = &Calibration_type;
self = mp_obj_malloc_with_finaliser(_Calibtration_obj_t, &Calibration_type);
self->calibration = m_new_class(Calibration, calibration_type);
}
else {
@ -82,8 +81,7 @@ mp_obj_t Calibration_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
}
}
else {
self = m_new_obj_with_finaliser(_Calibtration_obj_t);
self->base.type = &Calibration_type;
self = mp_obj_malloc_with_finaliser(_Calibtration_obj_t, &Calibration_type);
self->calibration = m_new_class(Calibration);
}
@ -892,8 +890,7 @@ mp_obj_t Servo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, c
freq = mp_obj_get_float(args[ARG_freq].u_obj);
}
self = m_new_obj_with_finaliser(_Servo_obj_t);
self->base.type = &Servo_type;
self = mp_obj_malloc_with_finaliser(_Servo_obj_t, &Servo_type);
void *servo_target = m_new(Servo, 1);
@ -1161,8 +1158,7 @@ extern mp_obj_t Servo_calibration(size_t n_args, const mp_obj_t *pos_args, mp_ma
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
// Create a new MP Calibration instance and assign a copy of the servo's calibration to it
_Calibration_obj_t *calib = m_new_obj_with_finaliser(_Calibration_obj_t);
calib->base.type = &Calibration_type;
_Calibration_obj_t *calib = mp_obj_malloc_with_finaliser(_Calibration_obj_t, &Calibration_type);
calib->calibration = m_new_class(Calibration, self->servo->calibration());
return MP_OBJ_FROM_PTR(calib);
@ -1355,8 +1351,7 @@ mp_obj_t ServoCluster_make_new(const mp_obj_type_t *type, size_t n_args, size_t
mp_raise_msg(&mp_type_RuntimeError, "unable to allocate the hardware resources needed to initialise this ServoCluster. Try running `import gc` followed by `gc.collect()` before creating it");
}
self = m_new_obj_with_finaliser(_ServoCluster_obj_t);
self->base.type = &ServoCluster_type;
self = mp_obj_malloc_with_finaliser(_ServoCluster_obj_t, &ServoCluster_type);
self->cluster = cluster;
return MP_OBJ_FROM_PTR(self);
@ -2655,8 +2650,7 @@ extern mp_obj_t ServoCluster_calibration(size_t n_args, const mp_obj_t *pos_args
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
else {
// Create a new MP Calibration instance and assign a copy of the servo's calibration to it
_Calibration_obj_t *calib = m_new_obj_with_finaliser(_Calibration_obj_t);
calib->base.type = &Calibration_type;
_Calibration_obj_t *calib = mp_obj_malloc_with_finaliser(_Calibration_obj_t, &Calibration_type);
calib->calibration = m_new_class(Calibration, self->cluster->calibration((uint)servo));
return MP_OBJ_FROM_PTR(calib);

Wyświetl plik

@ -391,8 +391,7 @@ mp_obj_t StellarUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size_
StellarUnicorn *stellar = m_new_class(StellarUnicorn);
stellar->init();
self = m_new_obj_with_finaliser(_StellarUnicorn_obj_t);
self->base.type = &StellarUnicorn_type;
self = mp_obj_malloc_with_finaliser(_StellarUnicorn_obj_t, &StellarUnicorn_type);
self->stellar = stellar;
return MP_OBJ_FROM_PTR(self);
@ -507,8 +506,7 @@ extern mp_obj_t StellarUnicorn_synth_channel(mp_obj_t self_in, mp_obj_t channel_
// NOTE This seems to work, in that it give MP access to the calibration object
// Could very easily mess up in weird ways once object deletion is considered?
_Channel_obj_t *channel_obj = m_new_obj_with_finaliser(_Channel_obj_t);
channel_obj->base.type = &Channel_type;
_Channel_obj_t *channel_obj = mp_obj_malloc_with_finaliser(_Channel_obj_t, &Channel_type);
channel_obj->channel = &self->stellar->synth_channel(channel);
return MP_OBJ_FROM_PTR(channel_obj);