8000 all: Use mp_obj_malloc everywhere it's applicable. · micropython/micropython@0e7bfc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e7bfc8

Browse files
jimmodpgeorge
authored andcommitted
all: Use mp_obj_malloc everywhere it's applicable.
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 <jim.mussared@gmail.com>
1 parent 6a3bc0e commit 0e7bfc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+145
-294
lines changed

extmod/machine_i2c.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ STATIC void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, cons
668668

669669
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) {
670670
// create new soft I2C object
671-
machine_i2c_obj_t *self = m_new_obj(machine_i2c_obj_t);
672-
self->base.type = &mp_machine_soft_i2c_type;
671+
machine_i2c_obj_t *self = mp_obj_malloc(machine_i2c_obj_t, &mp_machine_soft_i2c_type);
673672
mp_map_t kw_args;
674673
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
675674
mp_machine_soft_i2c_init(&self->base, n_args, args, &kw_args);

extmod/machine_signal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
108108
}
109109
}
110110

111-
machine_signal_t *o = m_new_obj(machine_signal_t);
112-
o->base.type = type;
111+
machine_signal_t *o = mp_obj_malloc(machine_signal_t, type);
113112
o->pin = pin;
114113
o->invert = invert;
115114
return MP_OBJ_FROM_PTR(o);

extmod/machine_spi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n
175175
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
176176

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

181180
// set parameters
182181
self->spi.delay_half = baudrate_to_delay_half(args[ARG_baudrate].u_int);

extmod/modbluetooth.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args
9797

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

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

103102
if (mp_obj_is_int(all_args[0])) {
104103
self->type = MP_BLUETOOTH_UUID_TYPE_16;

extmod/modbtree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ void __dbpanic(DB *db) {
6767
}
6868

6969
STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) {
70-
mp_obj_btree_t *o = m_new_obj(mp_obj_btree_t);
71-
o->base.type = &btree_type;
70+
mp_obj_btree_t *o = mp_obj_malloc(mp_obj_btree_t, &btree_type);
7271
o->stream = stream;
7372
o->db = db;
7473
o->start_key = mp_const_none;

extmod/modframebuf.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, u
266266
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) {
267267
mp_arg_check_num(n_args, n_kw, 4, 5, false);
268268

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

273272
mp_buffer_info_t bufinfo;
@@ -628,8 +627,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
628627

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

634632
mp_buffer_info_t bufinfo;
635633
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_WRITE);

extmod/moduasyncio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
8787
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) {
8888
(void)args;
8989
mp_arg_check_num(n_args, n_kw, 0, 0, false);
90-
mp_obj_task_queue_t *self = m_new_obj(mp_obj_task_queue_t);
91-
self->base.type = type;
90+
mp_obj_task_queue_t *self = mp_obj_malloc(mp_obj_task_queue_t, type);
9291
self->heap = (mp_obj_task_t *)mp_pairheap_new(task_lt);
9392
return MP_OBJ_FROM_PTR(self);
9493
}

extmod/moducryptolib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
228228
mp_raise_ValueError(MP_ERROR_TEXT("mode"));
229229
}
230230

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

234233
o->block_mode = block_mode;
235234
o->key_type = AES_KEYTYPE_NONE;

extmod/moductypes.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ STATIC NORETURN void syntax_error(void) {
9595

9696
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) {
9797
mp_arg_check_num(n_args, n_kw, 2, 3, false);
98-
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
99-
o->base.type = type;
98+
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, type);
10099
o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
101100
o->desc = args[1];
102101
o->flags = LAYOUT_NATIVE;
@@ -463,8 +462,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
463462

464463
switch (agg_type) {
465464
case STRUCT: {
466-
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
467-
o->base.type = &uctypes_struct_type;
465+
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
468466
o->desc = sub->items[1];
469467
o->addr = self->addr + offset;
470468
o->flags = self->flags;
@@ -479,8 +477,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
479477
MP_FALLTHROUGH
480478
}
481479
case PTR: {
482-
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
483-
o->base.type = &uctypes_struct_type;
480+
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
484481
o->desc = MP_OBJ_FROM_PTR(sub);
485482
o->addr = self->addr + offset;
486483
o->flags = self->flags;
@@ -552,8 +549,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
552549
} else if (value == MP_OBJ_SENTINEL) {
553550
mp_uint_t dummy = 0;
554551
mp_uint_t size = uctypes_struct_size(t->items[2], self->flags, &dummy);
555-
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
556-
o->base.type = &uctypes_struct_type;
552+
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
557553
o->desc = t->items[2];
558554
o->addr = self->addr + size * index;
559555
o->flags = self->flags;
@@ -570,8 +566,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
570566
} else {
571567
mp_uint_t dummy = 0;
572568
mp_uint_t size = uctypes_struct_size(t->items[1], self->flags, &dummy);
573-
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
574-
o->base.type = &uctypes_struct_type;
569+
mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type);
575570
o->desc = t->items[1];
576571
o->addr = p + size * index;
577572
o->flags = self->flags;

extmod/moduhashlib.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
8383

8484
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) {
8585
mp_arg_check_num(n_args, n_kw, 0, 1, false);
86-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context));
87-
o->base.type = type;
86+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type);
8887
o->final = false;
8988
mbedtls_sha256_init((mbedtls_sha256_context *)&o->state);
9089
mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0);
@@ -119,8 +118,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
119118

120119
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) {
121120
mp_arg_check_num(n_args, n_kw, 0, 1, false);
122-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
123-
o->base.type = type;
121+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type);
124122
o->final = false;
125123
sha256_init((CRYAL_SHA256_CTX *)o->state);
126124
if (n_args == 1) {
@@ -173,8 +171,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
173171
#if MICROPY_SSL_AXTLS
174172
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) {
175173
mp_arg_check_num(n_args, n_kw, 0, 1, false);
176-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(SHA1_CTX));
177-
o->base.type = type;
174+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type);
178175
o->final = false;
179176
SHA1_Init((SHA1_CTX *)o->state);
180177
if (n_args == 1) {
@@ -213,8 +210,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
213210

214211
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) {
215212
mp_arg_check_num(n_args, n_kw, 0, 1, false);
216-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context));
217-
o->base.type = type;
213+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type);
218214
o->final = false;
219215
mbedtls_sha1_init((mbedtls_sha1_context *)o->state);
220216
mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state);
@@ -268,8 +264,7 @@ STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg);
268264
#if MICROPY_SSL_AXTLS
269265
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) {
270266
mp_arg_check_num(n_args, n_kw, 0, 1, false);
271-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(MD5_CTX));
272-
o->base.type = type;
267+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type);
273268
o->final = false;
274269
MD5_Init((MD5_CTX *)o->state);
275270
if (n_args == 1) {
@@ -308,8 +303,7 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
308303

309304
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) {
310305
mp_arg_check_num(n_args, n_kw, 0, 1, false);
311-
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context));
312-
o->base.type = type;
306+
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type);
313307
o->final = false;
314308
mbedtls_md5_init((mbedtls_md5_context *)o->state);
315309
mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state);

extmod/modure.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
406406
if (size == -1) {
407407
goto error;
408408
}
409-
mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);
410-
o->base.type = &re_type;
409+
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, &re_type);
411410
#if MICROPY_PY_URE_DEBUG
412411
int flags = 0;
413412
if (n_args > 1) {

extmod/moduselect.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ STATIC const mp_obj_type_t mp_type_poll = {
346346

347347
// poll()
348348
STATIC mp_obj_t select_poll(void) {
349-
mp_obj_poll_t *poll = m_new_obj(mp_obj_poll_t);
350-
poll->base.type = &mp_type_poll;
349+
mp_obj_poll_t *poll = mp_obj_malloc(mp_obj_poll_t, &mp_type_poll);
351350
mp_map_init(&poll->poll_map, 0);
352351
poll->iter_cnt = 0;
353352
poll->ret_tuple = MP_OBJ_NULL;

extmod/modutimeq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) {
7777
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) {
7878
mp_arg_check_num(n_args, n_kw, 1, 1, false);
7979
mp_uint_t alloc = mp_obj_get_int(args[0]);
80-
mp_obj_utimeq_t *o = m_new_obj_var(mp_obj_utimeq_t, struct qentry, alloc);
81-
o->base.type = type;
80+
mp_obj_utimeq_t *o = mp_obj_malloc_var(mp_obj_utimeq_t, struct qentry, alloc, type);
8281
memset(o->items, 0, sizeof(*o->items) * alloc);
8382
o->alloc = alloc;
8483
o->len = 0;

extmod/moduwebsocket.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si
6060
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) {
6161
mp_arg_check_num(n_args, n_kw, 1, 2, false);
6262
mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
63-
mp_obj_websocket_t *o = m_new_obj(mp_obj_websocket_t);
64-
o->base.type = type;
63+
mp_obj_websocket_t *o = mp_obj_malloc(mp_obj_websocket_t, type);
6564
o->sock = args[0];
6665
o->state = FRAME_HEADER;
6766
o->to_recv = 2;

extmod/moduzlib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ STATIC int read_src_stream(TINF_DATA *data) {
6969
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) {
7070
mp_arg_check_num(n_args, n_kw, 1, 2, false);
7171
mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
72-
mp_obj_decompio_t *o = m_new_obj(mp_obj_decompio_t);
73-
o->base.type = type;
72+
mp_obj_decompio_t *o = mp_obj_malloc(mp_obj_decompio_t, type);
7473
memset(&o->decomp, 0, sizeof(o->decomp));
7574
o->decomp.readSource = read_src_stream;
7675
o->src_stream = args[0];

extmod/modwebrepl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
9797
mp_arg_check_num(n_args, n_kw, 1, 2, false);
9898
mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
9999
DEBUG_printf("sizeof(struct webrepl_file) = %lu\n", sizeof(struct webrepl_file));
100-
mp_obj_webrepl_t *o = m_new_obj(mp_obj_webrepl_t);
101-
o->base.type = type;
100+
mp_obj_webrepl_t *o = mp_obj_malloc(mp_obj_webrepl_t, type);
102101
o->sock = args[0];
103102
o->hdr_to_recv = sizeof(struct webrepl_file);
104103
o->data_to_recv = 0;

extmod/vfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,7 @@ mp_obj_t mp_vfs_ilistdir(size_t n_args, const mp_obj_t *args) {
417417

418418
if (vfs == MP_VFS_ROOT) {
419419
// list the root directory
420-
mp_vfs_ilistdir_it_t *iter = m_new_obj(mp_vfs_ilistdir_it_t);
421-
iter->base.type = &mp_type_polymorph_iter;
420+
mp_vfs_ilistdir_it_t *iter = mp_obj_malloc(mp_vfs_ilistdir_it_t, &mp_type_polymorph_iter);
422421
iter->iternext = mp_vfs_ilistdir_it_iternext;
423422
iter->cur.vfs = MP_STATE_VM(vfs_mount_table);
424423
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;

extmod/vfs_fat.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_
6666
mp_arg_check_num(n_args, n_kw, 1, 1, false);
6767

6868
// create new object
69-
fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t);
70-
vfs->base.type = type;
69+
fs_user_mount_t *vfs = mp_obj_malloc(fs_user_mount_t, type);
7170
vfs->fatfs.drv = vfs;
7271

7372
// Initialise underlying block device
@@ -177,8 +176,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
177176
}
178177

179178
// Create a new iterator object to list the dir
180-
mp_vfs_fat_ilistdir_it_t *iter = m_new_obj(mp_vfs_fat_ilistdir_it_t);
181-
iter->base.type = &mp_type_polymorph_iter;
179+
mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter);
182180
iter->iternext = mp_vfs_fat_ilistdir_it_iternext;
183181
iter->is_str = is_str_type;
184182
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);

extmod/vfs_lfsx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args)
203203
path = vstr_null_terminated_str(&self->cur_dir);
204204
}
205205

206-
MP_VFS_LFSx(ilistdir_it_t) * iter = m_new_obj(MP_VFS_LFSx(ilistdir_it_t));
207-
iter->base.type = &mp_type_polymorph_iter;
206+
MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter);
208207
iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext);
209208
iter->is_str = is_str_type;
210209
iter->vfs = self;

extmod/vfs_posix.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path
9898
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) {
9999
mp_arg_check_num(n_args, n_kw, 0, 1, false);
100100

101-
mp_obj_vfs_posix_t *vfs = m_new_obj(mp_obj_vfs_posix_t);
102-
vfs->base.type = type;
101+
mp_obj_vfs_posix_t *vfs = mp_obj_malloc(mp_obj_vfs_posix_t, type);
103102
vstr_init(&vfs->root, 0);
104103
if (n_args == 1) {
105104
vstr_add_str(&vfs->root, mp_obj_str_get_str(args[0]));
@@ -229,8 +228,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
229228

230229
STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) {
231230
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
232-
vfs_posix_ilistdir_it_t *iter = m_new_obj(vfs_posix_ilistdir_it_t);
233-
iter->base.type = &mp_type_polymorph_iter;
231+
vfs_posix_ilistdir_it_t *iter = mp_obj_malloc(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter);
234232
iter->iternext = vfs_posix_ilistdir_it_iternext;
235233
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;
236234
const char *path = vfs_posix_get_path_str(self, path_in);

ports/cc3200/misc/mpirq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ void mp_irq_init0 (void) {
6262
}
6363

6464
mp_obj_t mp_irq_new (mp_obj_t parent, mp_obj_t handler, const mp_irq_methods_t *methods) {
65-
mp_irq_obj_t *self = m_new_obj(mp_irq_obj_t);
66-
self->base.type = &mp_irq_type;
65+
mp_irq_obj_t *self = mp_obj_malloc(mp_irq_obj_t, &mp_irq_type);
6766
self->handler = handler;
6867
self->parent = parent;
6968
self->methods = (mp_irq_methods_t *)methods;

ports/cc3200/mods/pybsleep.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ void pyb_sleep_signal_soft_reset (void) {
210210
}
211211

212212
void pyb_sleep_add (const mp_obj_t obj, WakeUpCB_t wakeup) {
213-
pyb_sleep_obj_t *sleep_obj = m_new_obj(pyb_sleep_obj_t);
214-
sleep_obj->base.type = &pyb_sleep_type;
213+
pyb_sleep_obj_t *sleep_obj = mp_obj_malloc(pyb_sleep_obj_t, &pyb_sleep_type);
215214
sleep_obj->obj = obj;
216215
sleep_obj->wakeup = wakeup;
217216
// remove it in case it was already registered

ports/cc3200/mods/pybtimer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
406406
}
407407

408408
// allocate a new timer channel
409-
pyb_timer_channel_obj_t *ch = m_new_obj(pyb_timer_channel_obj_t);
410-
ch->base.type = &pyb_timer_channel_type;
409+
pyb_timer_channel_obj_t *ch = mp_obj_malloc(pyb_timer_channel_obj_t, &pyb_timer_channel_type);
411410
ch->timer = tim;
412411
ch->channel = channel_n;
413412

ports/esp32/esp32_nvs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ typedef struct _esp32_nvs_obj_t {
4444

4545
// *esp32_nvs_new allocates a python NVS object given a handle to an esp-idf namespace C obj.
4646
STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) {
47-
esp32_nvs_obj_t *self = m_new_obj(esp32_nvs_obj_t);
48-
self->base.type = &esp32_nvs_type;
47+
esp32_nvs_obj_t *self = mp_obj_malloc(esp32_nvs_obj_t, &esp32_nvs_type);
4948
self->namespace = namespace;
5049
return self;
5150
}

ports/esp32/esp32_partition.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ STATIC esp32_partition_obj_t *esp32_partition_new(const esp_partition_t *part, u
5757
if (part == NULL) {
5858
mp_raise_OSError(MP_ENOENT);
5959
}
60-
esp32_partition_obj_t *self = m_new_obj(esp32_partition_obj_t);
61-
self->base.type = &esp32_partition_type;
60+
esp32_partition_obj_t *self = mp_obj_malloc(esp32_partition_obj_t, &esp32_partition_type);
6261
self->part = part;
6362
self->block_size = block_size;
6463
if (self->block_size < NATIVE_BLOCK_SIZE_BYTES) {

ports/esp32/machine_i2s.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,8 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg
533533

534534
machine_i2s_obj_t *self;
535535
if (MP_STATE_PORT(machine_i2s_obj)[port] == NULL) {
536-
self = m_new_obj(machine_i2s_obj_t);
536+
self = mp_obj_malloc(machine_i2s_obj_t, &machine_i2s_type);
537537
MP_STATE_PORT(machine_i2s_obj)[port] = self;
538-
self->base.type = &machine_i2s_type;
539538
self->port = port;
540539
} else {
541540
self = MP_STATE_PORT(machine_i2s_obj)[port];

ports/esp32/machine_pwm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type,
556556
gpio_num_t pin_id = machine_pin_get_id(args[0]);
557557

558558
// create PWM object from the given pin
559-
machine_pwm_obj_t *self = m_new_obj(machine_pwm_obj_t);
560-
self->base.type = &machine_pwm_type;
559+
machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type);
561560
self->pin = pin_id;
562561
self->active = false;
563562
self->mode = -1;

0 commit comments

Comments
 (0)
0