mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
all: Use mp_obj_malloc_with_finaliser everywhere it's applicable.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -831,8 +831,7 @@ STATIC void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
||||
STATIC mp_obj_t lwip_socket_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, 0, 4, false);
|
||||
|
||||
lwip_socket_obj_t *socket = m_new_obj_with_finaliser(lwip_socket_obj_t);
|
||||
socket->base.type = &lwip_socket_type;
|
||||
lwip_socket_obj_t *socket = mp_obj_malloc_with_finaliser(lwip_socket_obj_t, &lwip_socket_type);
|
||||
socket->timeout = -1;
|
||||
socket->recv_offset = 0;
|
||||
socket->domain = MOD_NETWORK_AF_INET;
|
||||
@@ -994,8 +993,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
||||
|
||||
// Create new socket object, do it here because we must not raise an out-of-memory
|
||||
// exception when the LWIP concurrency lock is held
|
||||
lwip_socket_obj_t *socket2 = m_new_obj_with_finaliser(lwip_socket_obj_t);
|
||||
socket2->base.type = &lwip_socket_type;
|
||||
lwip_socket_obj_t *socket2 = mp_obj_malloc_with_finaliser(lwip_socket_obj_t, &lwip_socket_type);
|
||||
|
||||
MICROPY_PY_LWIP_ENTER
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||
mp_arg_check_num(n_args, n_kw, 0, 3, false);
|
||||
|
||||
// create socket object (not bound to any NIC yet)
|
||||
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
|
||||
s->base.type = &socket_type;
|
||||
mod_network_socket_obj_t *s = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, &socket_type);
|
||||
s->nic = MP_OBJ_NULL;
|
||||
s->nic_protocol = NULL;
|
||||
s->domain = MOD_NETWORK_AF_INET;
|
||||
@@ -163,8 +162,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
|
||||
|
||||
// create new socket object
|
||||
// starts with empty NIC so that finaliser doesn't run close() method if accept() fails
|
||||
mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t);
|
||||
socket2->base.type = &socket_type;
|
||||
mod_network_socket_obj_t *socket2 = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, &socket_type);
|
||||
socket2->nic = MP_OBJ_NULL;
|
||||
socket2->nic_protocol = NULL;
|
||||
|
||||
|
||||
@@ -145,11 +145,10 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
|
||||
|
||||
// Create SSLContext object.
|
||||
#if MICROPY_PY_SSL_FINALISER
|
||||
mp_obj_ssl_context_t *self = m_new_obj_with_finaliser(mp_obj_ssl_context_t);
|
||||
mp_obj_ssl_context_t *self = mp_obj_malloc_with_finaliser(mp_obj_ssl_context_t, type_in);
|
||||
#else
|
||||
mp_obj_ssl_context_t *self = m_new_obj(mp_obj_ssl_context_t);
|
||||
mp_obj_ssl_context_t *self = mp_obj_malloc(mp_obj_ssl_context_t, type_in);
|
||||
#endif
|
||||
self->base.type = type_in;
|
||||
self->key = mp_const_none;
|
||||
self->cert = mp_const_none;
|
||||
|
||||
@@ -210,11 +209,10 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t
|
||||
bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname) {
|
||||
|
||||
#if MICROPY_PY_SSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
mp_obj_ssl_socket_t *o = mp_obj_malloc_with_finaliser(mp_obj_ssl_socket_t, &ssl_socket_type);
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
mp_obj_ssl_socket_t *o = mp_obj_malloc(mp_obj_ssl_socket_t, &ssl_socket_type);
|
||||
#endif
|
||||
o->base.type = &ssl_socket_type;
|
||||
o->buf = NULL;
|
||||
o->bytes_left = 0;
|
||||
o->sock = MP_OBJ_NULL;
|
||||
|
||||
@@ -210,11 +210,10 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
|
||||
|
||||
// Create SSLContext object.
|
||||
#if MICROPY_PY_SSL_FINALISER
|
||||
mp_obj_ssl_context_t *self = m_new_obj_with_finaliser(mp_obj_ssl_context_t);
|
||||
mp_obj_ssl_context_t *self = mp_obj_malloc_with_finaliser(mp_obj_ssl_context_t, type_in);
|
||||
#else
|
||||
mp_obj_ssl_context_t *self = m_new_obj(mp_obj_ssl_context_t);
|
||||
mp_obj_ssl_context_t *self = mp_obj_malloc(mp_obj_ssl_context_t, type_in);
|
||||
#endif
|
||||
self->base.type = type_in;
|
||||
|
||||
// Initialise mbedTLS state.
|
||||
mbedtls_ssl_config_init(&self->conf);
|
||||
@@ -488,11 +487,10 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t
|
||||
mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
|
||||
|
||||
#if MICROPY_PY_SSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
mp_obj_ssl_socket_t *o = mp_obj_malloc_with_finaliser(mp_obj_ssl_socket_t, &ssl_socket_type);
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
mp_obj_ssl_socket_t *o = mp_obj_malloc(mp_obj_ssl_socket_t, &ssl_socket_type);
|
||||
#endif
|
||||
o->base.type = &ssl_socket_type;
|
||||
o->ssl_context = ssl_context;
|
||||
o->sock = sock;
|
||||
o->poll_mask = 0;
|
||||
|
||||
@@ -188,8 +188,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
// Create a new iterator object to list the dir
|
||||
mp_vfs_fat_ilistdir_it_t *iter = m_new_obj_with_finaliser(mp_vfs_fat_ilistdir_it_t);
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser);
|
||||
iter->iternext = mp_vfs_fat_ilistdir_it_iternext;
|
||||
iter->finaliser = mp_vfs_fat_ilistdir_it_del;
|
||||
iter->is_str = is_str_type;
|
||||
|
||||
@@ -228,8 +228,7 @@ STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_i
|
||||
}
|
||||
}
|
||||
|
||||
pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t);
|
||||
o->base.type = type;
|
||||
pyb_file_obj_t *o = mp_obj_malloc_with_finaliser(pyb_file_obj_t, type);
|
||||
|
||||
const char *fname = mp_obj_str_get_str(path_in);
|
||||
FRESULT res = f_open(&self->fatfs, &o->fp, fname, mode);
|
||||
|
||||
@@ -224,8 +224,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args)
|
||||
path = vstr_null_terminated_str(&self->cur_dir);
|
||||
}
|
||||
|
||||
MP_VFS_LFSx(ilistdir_it_t) * iter = m_new_obj_with_finaliser(MP_VFS_LFSx(ilistdir_it_t));
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc_with_finaliser(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter_with_finaliser);
|
||||
|
||||
iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext);
|
||||
iter->finaliser = MP_VFS_LFSx(ilistdir_it_del);
|
||||
|
||||
@@ -90,11 +90,10 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod
|
||||
}
|
||||
|
||||
#if LFS_BUILD_VERSION == 1
|
||||
MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->prog_size);
|
||||
MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->prog_size, type);
|
||||
#else
|
||||
MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->cache_size);
|
||||
MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->cache_size, type);
|
||||
#endif
|
||||
o->base.type = type;
|
||||
o->vfs = self;
|
||||
#if !MICROPY_GC_CONSERVATIVE_CLEAR
|
||||
memset(&o->file, 0, sizeof(o->file));
|
||||
|
||||
@@ -278,8 +278,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) {
|
||||
|
||||
STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) {
|
||||
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vfs_posix_ilistdir_it_t *iter = m_new_obj_with_finaliser(vfs_posix_ilistdir_it_t);
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
vfs_posix_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser);
|
||||
iter->iternext = vfs_posix_ilistdir_it_iternext;
|
||||
iter->finaliser = vfs_posix_ilistdir_it_del;
|
||||
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;
|
||||
|
||||
@@ -63,7 +63,6 @@ STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
}
|
||||
|
||||
mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_obj_t mode_in) {
|
||||
mp_obj_vfs_posix_file_t *o = m_new_obj_with_finaliser(mp_obj_vfs_posix_file_t);
|
||||
const char *mode_s = mp_obj_str_get_str(mode_in);
|
||||
|
||||
int mode_rw = 0, mode_x = 0;
|
||||
@@ -92,7 +91,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
||||
}
|
||||
}
|
||||
|
||||
o->base.type = type;
|
||||
mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type);
|
||||
|
||||
mp_obj_t fid = file_in;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user