PNG/JPEGDEC: Remove finalizer.

Remove the finalizer from PNGDEC and JPEGDEC, since it was both redundant
and actively harmful.

The finalizer was just calling "close" which is unecessary since the file
is closed automatically after opening/rendering and not left open.

If a file did not exist and "open_file" bailed with ENOENT then it would
be left in an unknown state, and the finalizer calling "close" would
cause a hardlock.
pull/1019/head
Phil Howard 2025-01-23 14:55:13 +00:00
rodzic f533177731
commit 1488a0b796
6 zmienionych plików z 2 dodań i 20 usunięć

Wyświetl plik

@ -1,6 +1,5 @@
#include "jpegdec.h"
static MP_DEFINE_CONST_FUN_OBJ_1(JPEG_del_obj, _JPEG_del);
static MP_DEFINE_CONST_FUN_OBJ_2(JPEG_openRAM_obj, _JPEG_openRAM);
static MP_DEFINE_CONST_FUN_OBJ_2(JPEG_openFILE_obj, _JPEG_openFILE);
static MP_DEFINE_CONST_FUN_OBJ_KW(JPEG_decode_obj, 1, _JPEG_decode);
@ -9,7 +8,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(JPEG_getHeight_obj, _JPEG_getHeight);
// class
static const mp_rom_map_elem_t JPEG_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&JPEG_del_obj) },
{ MP_ROM_QSTR(MP_QSTR_open_RAM), MP_ROM_PTR(&JPEG_openRAM_obj) },
{ MP_ROM_QSTR(MP_QSTR_open_file), MP_ROM_PTR(&JPEG_openFILE_obj) },
{ MP_ROM_QSTR(MP_QSTR_decode), MP_ROM_PTR(&JPEG_decode_obj) },

Wyświetl plik

@ -212,19 +212,13 @@ 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 = mp_obj_malloc_with_finaliser(_JPEG_obj_t, &JPEG_type);
_JPEG_obj_t *self = mp_obj_malloc(_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);
return self;
}
mp_obj_t _JPEG_del(mp_obj_t self_in) {
_JPEG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _JPEG_obj_t);
self->jpeg->close();
return mp_const_none;
}
// open_FILE
mp_obj_t _JPEG_openFILE(mp_obj_t self_in, mp_obj_t filename) {
_JPEG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _JPEG_obj_t);

Wyświetl plik

@ -4,7 +4,6 @@
extern const mp_obj_type_t JPEG_type;
extern mp_obj_t _JPEG_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
extern mp_obj_t _JPEG_del(mp_obj_t self_in);
extern mp_obj_t _JPEG_openRAM(mp_obj_t self_in, mp_obj_t buffer);
extern mp_obj_t _JPEG_openFILE(mp_obj_t self_in, mp_obj_t filename);
extern mp_obj_t _JPEG_decode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);

Wyświetl plik

@ -1,6 +1,5 @@
#include "pngdec.h"
static MP_DEFINE_CONST_FUN_OBJ_1(PNG_del_obj, _PNG_del);
static MP_DEFINE_CONST_FUN_OBJ_2(PNG_openRAM_obj, _PNG_openRAM);
static MP_DEFINE_CONST_FUN_OBJ_2(PNG_openFILE_obj, _PNG_openFILE);
static MP_DEFINE_CONST_FUN_OBJ_KW(PNG_decode_obj, 1, _PNG_decode);
@ -10,7 +9,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(PNG_getPalette_obj, _PNG_getPalette);
// class
static const mp_rom_map_elem_t PNG_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&PNG_del_obj) },
{ MP_ROM_QSTR(MP_QSTR_open_RAM), MP_ROM_PTR(&PNG_openRAM_obj) },
{ MP_ROM_QSTR(MP_QSTR_open_file), MP_ROM_PTR(&PNG_openFILE_obj) },
{ MP_ROM_QSTR(MP_QSTR_decode), MP_ROM_PTR(&PNG_decode_obj) },

Wyświetl plik

@ -326,7 +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 = mp_obj_malloc_with_finaliser(_PNG_obj_t, &PNG_type);
_PNG_obj_t *self = mp_obj_malloc(_PNG_obj_t, &PNG_type);
self->png = m_new_class(PNG);
//mp_printf(&mp_plat_print, "PNG RAM %fK\n", sizeof(PNG) / 1024.0f);
@ -341,12 +341,6 @@ mp_obj_t _PNG_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, co
return self;
}
mp_obj_t _PNG_del(mp_obj_t self_in) {
_PNG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _PNG_obj_t);
self->png->close();
return mp_const_none;
}
// open_FILE
mp_obj_t _PNG_openFILE(mp_obj_t self_in, mp_obj_t filename) {
_PNG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _PNG_obj_t);

Wyświetl plik

@ -4,7 +4,6 @@
extern const mp_obj_type_t PNG_type;
extern mp_obj_t _PNG_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
extern mp_obj_t _PNG_del(mp_obj_t self_in);
extern mp_obj_t _PNG_openRAM(mp_obj_t self_in, mp_obj_t buffer);
extern mp_obj_t _PNG_openFILE(mp_obj_t self_in, mp_obj_t filename);
extern mp_obj_t _PNG_decode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);