modules: Switch to the new mp_obj_malloc_with_finaliser.

This commit is contained in:
iabdalkader 2024-07-01 11:20:57 +02:00
parent f57c2f5e56
commit 3a8f1bb540
10 changed files with 22 additions and 28 deletions

View File

@ -16,7 +16,6 @@
#include "py/obj.h"
#include "py/objstr.h"
#include "py/runtime.h"
#include "pendsv.h"
#include "imlib.h"
#if MICROPY_PY_SENSOR
@ -111,18 +110,17 @@ static void usbdbg_interrupt_vm(bool ready) {
// Disable IDE IRQ (re-enabled by pyexec or main).
usbdbg_set_irq_enabled(false);
// Clear interrupt traceback
mp_obj_exception_clear_traceback(&ide_exception);
#if (__ARM_ARCH >= 7)
// Remove the BASEPRI masking (if any)
__set_BASEPRI(0);
#endif
// Interrupt running REPL
// Note: setting pendsv explicitly here because the VM is probably
// waiting in REPL and the soft interrupt flag will not be checked.
pendsv_nlr_jump(&ide_exception);
// Clear interrupt traceback
mp_obj_exception_clear_traceback(&ide_exception);
mp_sched_exception(&ide_exception);
// Abort the VM.
mp_sched_vm_abort();
}
bool usbdbg_get_irq_enabled() {

View File

@ -189,8 +189,7 @@ mp_obj_t py_display_data_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);
py_display_data_obj_t *self = m_new_obj_with_finaliser(py_display_data_obj_t);
self->base.type = &py_display_data_type;
py_display_data_obj_t *self = mp_obj_malloc_with_finaliser(py_display_data_obj_t, &py_display_data_type);
#if OMV_DISPLAY_CEC_ENABLE
self->cec_enabled = args[ARG_cec].u_bool;

View File

@ -219,8 +219,7 @@ mp_obj_t py_ft5x06_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);
py_ft5x06_obj_t *self = m_new_obj_with_finaliser(py_ft5x06_obj_t);
self->base.type = &py_ft5x06_type;
py_ft5x06_obj_t *self = mp_obj_malloc_with_finaliser(py_ft5x06_obj_t, &py_ft5x06_type);
self->i2c_addr = args[ARG_i2c_addr].u_int;
self->i2c_bus = MP_OBJ_TYPE_GET_SLOT(
&mp_machine_soft_i2c_type, make_new) (&mp_machine_soft_i2c_type, 2, 0, (const mp_obj_t []) {

View File

@ -114,8 +114,7 @@ static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
py_gif_obj_t *gif = m_new_obj_with_finaliser(py_gif_obj_t);
gif->base.type = &py_gif_type;
py_gif_obj_t *gif = mp_obj_malloc_with_finaliser(py_gif_obj_t, &py_gif_type);
gif->width = (args[ARG_width].u_int == -1) ? framebuffer_get_width() : args[ARG_width].u_int;
gif->height = (args[ARG_height].u_int == -1) ? framebuffer_get_height() : args[ARG_height].u_int;
gif->color = (args[ARG_color].u_int == -1) ? (framebuffer_get_depth() >= 2) : args[ARG_color].u_bool;

View File

@ -476,8 +476,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_imageio_close_obj, py_imageio_close);
static mp_obj_t py_imageio_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);
py_imageio_obj_t *stream = m_new_obj_with_finaliser(py_imageio_obj_t);
stream->base.type = &py_imageio_type;
py_imageio_obj_t *stream = mp_obj_malloc_with_finaliser(py_imageio_obj_t, &py_imageio_type);
stream->closed = false;
if (0) {

View File

@ -173,9 +173,12 @@ static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *pos_args, mp_map_t *k
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
py_mjpeg_obj_t *mjpeg = m_new_obj_with_finaliser(py_mjpeg_obj_t);
memset(mjpeg, 0, sizeof(py_mjpeg_obj_t));
mjpeg->base.type = &py_mjpeg_type;
py_mjpeg_obj_t *mjpeg = mp_obj_malloc_with_finaliser(py_mjpeg_obj_t, &py_mjpeg_type);
mjpeg->frames = 0;
mjpeg->bytes = 0;
mjpeg->us_old = 0;
mjpeg->us_avg = 0;
mjpeg->closed = 0;
mjpeg->width = (args[ARG_width].u_int == -1) ? framebuffer_get_width() : args[ARG_width].u_int;
mjpeg->height = (args[ARG_height].u_int == -1) ? framebuffer_get_height() : args[ARG_height].u_int;

View File

@ -399,8 +399,7 @@ mp_obj_t py_ml_model_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
const char *path = mp_obj_str_get_str(args[ARG_path].u_obj);
py_ml_model_obj_t *model = m_new_obj_with_finaliser(py_ml_model_obj_t);
model->base.type = &py_ml_model_type;
py_ml_model_obj_t *model = mp_obj_malloc_with_finaliser(py_ml_model_obj_t, &py_ml_model_type);
model->data = NULL;
model->fb_alloc = args[ARG_load_to_fb].u_int;
mp_obj_list_t *labels = NULL;

View File

@ -342,8 +342,7 @@ mp_obj_t spi_display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!"));
}
py_display_obj_t *self = m_new_obj_with_finaliser(py_display_obj_t);
self->base.type = &py_spi_display_type;
py_display_obj_t *self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_spi_display_type);
self->framebuffer_tail = 0;
self->framebuffer_head = 0;
self->width = args[ARG_width].u_int;

View File

@ -99,8 +99,7 @@ mp_obj_t py_tfp410_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);
py_tfp410_obj_t *self = m_new_obj_with_finaliser(py_tfp410_obj_t);
self->base.type = &py_tfp410_type;
py_tfp410_obj_t *self = mp_obj_malloc_with_finaliser(py_tfp410_obj_t, &py_tfp410_type);
self->hotplug_callback = mp_const_none;
self->i2c_addr = args[ARG_i2c_addr].u_int;
self->i2c_bus = MP_OBJ_TYPE_GET_SLOT(

View File

@ -577,11 +577,11 @@ mp_obj_t display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!"));
}
py_display_obj_t *self = (py_display_obj_t *) m_new_obj_with_finaliser(py_display_obj_t);
py_display_obj_t *self;
#ifdef OMV_DSI_DISPLAY_CONTROLLER
self->base.type = &py_dsi_display_type;
self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_dsi_display_type);
#else
self->base.type = &py_rgb_display_type;
self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_rgb_display_type);
#endif
self->vcid = args[ARG_channel].u_int;
self->refresh = args[ARG_refresh].u_int;