PulseIn, Counter: give finali(s/z)ers to these types too

for similar reasons, an interrupt handler might point at these
objects, and we can worry less about it if the object deinits when it
is GC'd.
This commit is contained in:
Jeff Epler 2023-03-23 09:57:32 -05:00
parent c45db1c1eb
commit 50ba218afb
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
2 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,7 @@ STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg
const countio_edge_t edge = validate_edge(args[ARG_edge].u_obj, MP_QSTR_edge);
const digitalio_pull_t pull = validate_pull(args[ARG_pull].u_obj, MP_QSTR_pull);
// Make long-lived because some implementations use a pointer to the object as interrupt-handler data.
countio_counter_obj_t *self = m_new_ll_obj(countio_counter_obj_t);
countio_counter_obj_t *self = m_new_ll_obj_with_finaliser(countio_counter_obj_t);
self->base.type = &countio_counter_type;
common_hal_countio_counter_construct(self, pin, edge, pull);
@ -134,6 +134,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_reset_obj, countio_counter_reset);
STATIC const mp_rom_map_elem_t countio_counter_locals_dict_table[] = {
// Methods
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&countio_counter_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&countio_counter_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&countio_counter___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&countio_counter_count_obj) },

View File

@ -89,7 +89,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin);
// Make object long-lived to avoid moving between imports
pulseio_pulsein_obj_t *self = m_new_ll_obj(pulseio_pulsein_obj_t);
pulseio_pulsein_obj_t *self = m_new_ll_obj_with_finaliser(pulseio_pulsein_obj_t);
self->base.type = &pulseio_pulsein_type;
common_hal_pulseio_pulsein_construct(self, pin, args[ARG_maxlen].u_int,
@ -277,6 +277,7 @@ STATIC mp_obj_t pulsein_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t va
STATIC const mp_rom_map_elem_t pulseio_pulsein_locals_dict_table[] = {
// Methods
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pulseio_pulsein_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&pulseio_pulsein_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&pulseio_pulsein___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR_pause), MP_ROM_PTR(&pulseio_pulsein_pause_obj) },