Skip to content

Commit

Permalink
all: Use mp_obj_malloc everywhere it's applicable.
Browse files Browse the repository at this point in the history
This replaces occurences of

    foo_t *foo = m_new_obj(foo_t);
    foo->base.type = &foo_type;

with

    foo_t *foo = mp_obj_malloc(foo_t, &foo_type);

Excludes any places where base is a sub-field or when new0/memset is used.

Signed-off-by: Jim Mussared <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed May 3, 2022
1 parent 6a3bc0e commit 0e7bfc8
Show file tree
Hide file tree
Showing 105 changed files with 145 additions and 294 deletions.
3 changes: 1 addition & 2 deletions extmod/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ STATIC void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, cons

STATIC mp_obj_t mp_machine_soft_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
// create new soft I2C object
machine_i2c_obj_t *self = m_new_obj(machine_i2c_obj_t);
self->base.type = &mp_machine_soft_i2c_type;
machine_i2c_obj_t *self = mp_obj_malloc(machine_i2c_obj_t, &mp_machine_soft_i2c_type);
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
mp_machine_soft_i2c_init(&self->base, n_args, args, &kw_args);
Expand Down
3 changes: 1 addition & 2 deletions extmod/machine_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
}

machine_signal_t *o = m_new_obj(machine_signal_t);
o->base.type = type;
machine_signal_t *o = mp_obj_malloc(machine_signal_t, type);
o->pin = pin;
o->invert = invert;
return MP_OBJ_FROM_PTR(o);
Expand Down
3 changes: 1 addition & 2 deletions extmod/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

// create new object
mp_machine_soft_spi_obj_t *self = m_new_obj(mp_machine_soft_spi_obj_t);
self->base.type = &mp_machine_soft_spi_type;
mp_machine_soft_spi_obj_t *self = mp_obj_malloc(mp_machine_soft_spi_obj_t, &mp_machine_soft_spi_type);

// set parameters
self->spi.delay_half = baudrate_to_delay_half(args[ARG_baudrate].u_int);
Expand Down
3 changes: 1 addition & 2 deletions extmod/modbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args

mp_arg_check_num(n_args, n_kw, 1, 1, false);

mp_obj_bluetooth_uuid_t *self = m_new_obj(mp_obj_bluetooth_uuid_t);
self->base.type = &mp_type_bluetooth_uuid;
mp_obj_bluetooth_uuid_t *self = mp_obj_malloc(mp_obj_bluetooth_uuid_t, &mp_type_bluetooth_uuid);

if (mp_obj_is_int(all_args[0])) {
self->type = MP_BLUETOOTH_UUID_TYPE_16;
Expand Down
3 changes: 1 addition & 2 deletions extmod/modbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void __dbpanic(DB *db) {
}

STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) {
mp_obj_btree_t *o = m_new_obj(mp_obj_btree_t);
o->base.type = &btree_type;
mp_obj_btree_t *o = mp_obj_malloc(mp_obj_btree_t, &btree_type);
o->stream = stream;
o->db = db;
o->start_key = mp_const_none;
Expand Down
6 changes: 2 additions & 4 deletions extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, u
STATIC mp_obj_t framebuf_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, 4, 5, false);

mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t);
o->base.type = type;
mp_obj_framebuf_t *o = mp_obj_malloc(mp_obj_framebuf_t, type);
o->buf_obj = args[0];

mp_buffer_info_t bufinfo;
Expand Down Expand Up @@ -628,8 +627,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {

// this factory function is provided for backwards compatibility with old FrameBuffer1 class
STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) {
mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t);
o->base.type = &mp_type_framebuf;
mp_obj_framebuf_t *o = mp_obj_malloc(mp_obj_framebuf_t, &mp_type_framebuf);

mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_WRITE);
Expand Down
3 changes: 1 addition & 2 deletions extmod/moduasyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
(void)args;
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_task_queue_t *self = m_new_obj(mp_obj_task_queue_t);
self->base.type = type;
mp_obj_task_queue_t *self = mp_obj_malloc(mp_obj_task_queue_t, type);
self->heap = (mp_obj_task_t *)mp_pairheap_new(task_lt);
return MP_OBJ_FROM_PTR(self);
}
Expand Down
3 changes: 1 addition & 2 deletions extmod/moducryptolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
mp_raise_ValueError(MP_ERROR_TEXT("mode"));
}

mp_obj_aes_t *o = m_new_obj_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode));
o->base.type = type;
mp_obj_aes_t *o = mp_obj_malloc_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode), type);

o->block_mode = block_mode;
o->key_type = AES_KEYTYPE_NONE;
Expand Down
15 changes: 5 additions & 10 deletions extmod/moductypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ STATIC NORETURN void syntax_error(void) {

STATIC mp_obj_t uctypes_struct_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, 3, false);
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = type;
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, type);
o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
o->desc = args[1];
o->flags = LAYOUT_NATIVE;
Expand Down Expand Up @@ -463,8 +462,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set

switch (agg_type) {
case STRUCT: {
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = &uctypes_struct_type;
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
o->desc = sub->items[1];
o->addr = self->addr + offset;
o->flags = self->flags;
Expand All @@ -479,8 +477,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
MP_FALLTHROUGH
}
case PTR: {
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = &uctypes_struct_type;
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
o->desc = MP_OBJ_FROM_PTR(sub);
o->addr = self->addr + offset;
o->flags = self->flags;
Expand Down Expand Up @@ -552,8 +549,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
} else if (value == MP_OBJ_SENTINEL) {
mp_uint_t dummy = 0;
mp_uint_t size = uctypes_struct_size(t->items[2], self->flags, &dummy);
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = &uctypes_struct_type;
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
o->desc = t->items[2];
o->addr = self->addr + size * index;
o->flags = self->flags;
Expand All @@ -570,8 +566,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
} else {
mp_uint_t dummy = 0;
mp_uint_t size = uctypes_struct_size(t->items[1], self->flags, &dummy);
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = &uctypes_struct_type;
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
o->desc = t->items[1];
o->addr = p + size * index;
o->flags = self->flags;
Expand Down
18 changes: 6 additions & 12 deletions extmod/moduhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);

STATIC mp_obj_t uhashlib_sha256_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type);
o->final = false;
mbedtls_sha256_init((mbedtls_sha256_context *)&o->state);
mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0);
Expand Down Expand Up @@ -119,8 +118,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {

STATIC mp_obj_t uhashlib_sha256_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type);
o->final = false;
sha256_init((CRYAL_SHA256_CTX *)o->state);
if (n_args == 1) {
Expand Down Expand Up @@ -173,8 +171,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
#if MICROPY_SSL_AXTLS
STATIC mp_obj_t uhashlib_sha1_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA1_CTX));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type);
o->final = false;
SHA1_Init((SHA1_CTX *)o->state);
if (n_args == 1) {
Expand Down Expand Up @@ -213,8 +210,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {

STATIC mp_obj_t uhashlib_sha1_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type);
o->final = false;
mbedtls_sha1_init((mbedtls_sha1_context *)o->state);
mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state);
Expand Down Expand Up @@ -268,8 +264,7 @@ STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg);
#if MICROPY_SSL_AXTLS
STATIC mp_obj_t uhashlib_md5_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(MD5_CTX));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type);
o->final = false;
MD5_Init((MD5_CTX *)o->state);
if (n_args == 1) {
Expand Down Expand Up @@ -308,8 +303,7 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {

STATIC mp_obj_t uhashlib_md5_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, 1, false);
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context));
o->base.type = type;
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type);
o->final = false;
mbedtls_md5_init((mbedtls_md5_context *)o->state);
mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state);
Expand Down
3 changes: 1 addition & 2 deletions extmod/modure.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
if (size == -1) {
goto error;
}
mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);
o->base.type = &re_type;
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, &re_type);
#if MICROPY_PY_URE_DEBUG
int flags = 0;
if (n_args > 1) {
Expand Down
3 changes: 1 addition & 2 deletions extmod/moduselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ STATIC const mp_obj_type_t mp_type_poll = {

// poll()
STATIC mp_obj_t select_poll(void) {
mp_obj_poll_t *poll = m_new_obj(mp_obj_poll_t);
poll->base.type = &mp_type_poll;
mp_obj_poll_t *poll = mp_obj_malloc(mp_obj_poll_t, &mp_type_poll);
mp_map_init(&poll->poll_map, 0);
poll->iter_cnt = 0;
poll->ret_tuple = MP_OBJ_NULL;
Expand Down
3 changes: 1 addition & 2 deletions extmod/modutimeq.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) {
STATIC mp_obj_t utimeq_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, 1, 1, false);
mp_uint_t alloc = mp_obj_get_int(args[0]);
mp_obj_utimeq_t *o = m_new_obj_var(mp_obj_utimeq_t, struct qentry, alloc);
o->base.type = type;
mp_obj_utimeq_t *o = mp_obj_malloc_var(mp_obj_utimeq_t, struct qentry, alloc, type);
memset(o->items, 0, sizeof(*o->items) * alloc);
o->alloc = alloc;
o->len = 0;
Expand Down
3 changes: 1 addition & 2 deletions extmod/moduwebsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si
STATIC mp_obj_t websocket_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, 1, 2, false);
mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
mp_obj_websocket_t *o = m_new_obj(mp_obj_websocket_t);
o->base.type = type;
mp_obj_websocket_t *o = mp_obj_malloc(mp_obj_websocket_t, type);
o->sock = args[0];
o->state = FRAME_HEADER;
o->to_recv = 2;
Expand Down
3 changes: 1 addition & 2 deletions extmod/moduzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ STATIC int read_src_stream(TINF_DATA *data) {
STATIC mp_obj_t decompio_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, 1, 2, false);
mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
mp_obj_decompio_t *o = m_new_obj(mp_obj_decompio_t);
o->base.type = type;
mp_obj_decompio_t *o = mp_obj_malloc(mp_obj_decompio_t, type);
memset(&o->decomp, 0, sizeof(o->decomp));
o->decomp.readSource = read_src_stream;
o->src_stream = args[0];
Expand Down
3 changes: 1 addition & 2 deletions extmod/modwebrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_arg_check_num(n_args, n_kw, 1, 2, false);
mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
DEBUG_printf("sizeof(struct webrepl_file) = %lu\n", sizeof(struct webrepl_file));
mp_obj_webrepl_t *o = m_new_obj(mp_obj_webrepl_t);
o->base.type = type;
mp_obj_webrepl_t *o = mp_obj_malloc(mp_obj_webrepl_t, type);
o->sock = args[0];
o->hdr_to_recv = sizeof(struct webrepl_file);
o->data_to_recv = 0;
Expand Down
3 changes: 1 addition & 2 deletions extmod/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ mp_obj_t mp_vfs_ilistdir(size_t n_args, const mp_obj_t *args) {

if (vfs == MP_VFS_ROOT) {
// list the root directory
mp_vfs_ilistdir_it_t *iter = m_new_obj(mp_vfs_ilistdir_it_t);
iter->base.type = &mp_type_polymorph_iter;
mp_vfs_ilistdir_it_t *iter = mp_obj_malloc(mp_vfs_ilistdir_it_t, &mp_type_polymorph_iter);
iter->iternext = mp_vfs_ilistdir_it_iternext;
iter->cur.vfs = MP_STATE_VM(vfs_mount_table);
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;
Expand Down
6 changes: 2 additions & 4 deletions extmod/vfs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_
mp_arg_check_num(n_args, n_kw, 1, 1, false);

// create new object
fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t);
vfs->base.type = type;
fs_user_mount_t *vfs = mp_obj_malloc(fs_user_mount_t, type);
vfs->fatfs.drv = vfs;

// Initialise underlying block device
Expand Down Expand Up @@ -177,8 +176,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(mp_vfs_fat_ilistdir_it_t);
iter->base.type = &mp_type_polymorph_iter;
mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter);
iter->iternext = mp_vfs_fat_ilistdir_it_iternext;
iter->is_str = is_str_type;
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);
Expand Down
3 changes: 1 addition & 2 deletions extmod/vfs_lfsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,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(MP_VFS_LFSx(ilistdir_it_t));
iter->base.type = &mp_type_polymorph_iter;
MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter);
iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext);
iter->is_str = is_str_type;
iter->vfs = self;
Expand Down
6 changes: 2 additions & 4 deletions extmod/vfs_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path
STATIC mp_obj_t vfs_posix_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, 1, false);

mp_obj_vfs_posix_t *vfs = m_new_obj(mp_obj_vfs_posix_t);
vfs->base.type = type;
mp_obj_vfs_posix_t *vfs = mp_obj_malloc(mp_obj_vfs_posix_t, type);
vstr_init(&vfs->root, 0);
if (n_args == 1) {
vstr_add_str(&vfs->root, mp_obj_str_get_str(args[0]));
Expand Down Expand Up @@ -229,8 +228,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(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(vfs_posix_ilistdir_it_t);
iter->base.type = &mp_type_polymorph_iter;
vfs_posix_ilistdir_it_t *iter = mp_obj_malloc(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter);
iter->iternext = vfs_posix_ilistdir_it_iternext;
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;
const char *path = vfs_posix_get_path_str(self, path_in);
Expand Down
3 changes: 1 addition & 2 deletions ports/cc3200/misc/mpirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ void mp_irq_init0 (void) {
}

mp_obj_t mp_irq_new (mp_obj_t parent, mp_obj_t handler, const mp_irq_methods_t *methods) {
mp_irq_obj_t *self = m_new_obj(mp_irq_obj_t);
self->base.type = &mp_irq_type;
mp_irq_obj_t *self = mp_obj_malloc(mp_irq_obj_t, &mp_irq_type);
self->handler = handler;
self->parent = parent;
self->methods = (mp_irq_methods_t *)methods;
Expand Down
3 changes: 1 addition & 2 deletions ports/cc3200/mods/pybsleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ void pyb_sleep_signal_soft_reset (void) {
}

void pyb_sleep_add (const mp_obj_t obj, WakeUpCB_t wakeup) {
pyb_sleep_obj_t *sleep_obj = m_new_obj(pyb_sleep_obj_t);
sleep_obj->base.type = &pyb_sleep_type;
pyb_sleep_obj_t *sleep_obj = mp_obj_malloc(pyb_sleep_obj_t, &pyb_sleep_type);
sleep_obj->obj = obj;
sleep_obj->wakeup = wakeup;
// remove it in case it was already registered
Expand Down
3 changes: 1 addition & 2 deletions ports/cc3200/mods/pybtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
}

// allocate a new timer channel
pyb_timer_channel_obj_t *ch = m_new_obj(pyb_timer_channel_obj_t);
ch->base.type = &pyb_timer_channel_type;
pyb_timer_channel_obj_t *ch = mp_obj_malloc(pyb_timer_channel_obj_t, &pyb_timer_channel_type);
ch->timer = tim;
ch->channel = channel_n;

Expand Down
3 changes: 1 addition & 2 deletions ports/esp32/esp32_nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ typedef struct _esp32_nvs_obj_t {

// *esp32_nvs_new allocates a python NVS object given a handle to an esp-idf namespace C obj.
STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) {
esp32_nvs_obj_t *self = m_new_obj(esp32_nvs_obj_t);
self->base.type = &esp32_nvs_type;
esp32_nvs_obj_t *self = mp_obj_malloc(esp32_nvs_obj_t, &esp32_nvs_type);
self->namespace = namespace;
return self;
}
Expand Down
3 changes: 1 addition & 2 deletions ports/esp32/esp32_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ STATIC esp32_partition_obj_t *esp32_partition_new(const esp_partition_t *part, u
if (part == NULL) {
mp_raise_OSError(MP_ENOENT);
}
esp32_partition_obj_t *self = m_new_obj(esp32_partition_obj_t);
self->base.type = &esp32_partition_type;
esp32_partition_obj_t *self = mp_obj_malloc(esp32_partition_obj_t, &esp32_partition_type);
self->part = part;
self->block_size = block_size;
if (self->block_size < NATIVE_BLOCK_SIZE_BYTES) {
Expand Down
3 changes: 1 addition & 2 deletions ports/esp32/machine_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,8 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg

machine_i2s_obj_t *self;
if (MP_STATE_PORT(machine_i2s_obj)[port] == NULL) {
self = m_new_obj(machine_i2s_obj_t);
self = mp_obj_malloc(machine_i2s_obj_t, &machine_i2s_type);
MP_STATE_PORT(machine_i2s_obj)[port] = self;
self->base.type = &machine_i2s_type;
self->port = port;
} else {
self = MP_STATE_PORT(machine_i2s_obj)[port];
Expand Down
3 changes: 1 addition & 2 deletions ports/esp32/machine_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type,
gpio_num_t pin_id = machine_pin_get_id(args[0]);

// create PWM object from the given pin
machine_pwm_obj_t *self = m_new_obj(machine_pwm_obj_t);
self->base.type = &machine_pwm_type;
machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type);
self->pin = pin_id;
self->active = false;
self->mode = -1;
Expand Down
Loading

0 comments on commit 0e7bfc8

Please sign in to comment.