diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2022-04-22 17:09:15 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-05-03 22:28:14 +1000 |
commit | 0e7bfc88c6ac6b5d64240f91183a3cfe2ab67ade (patch) | |
tree | b578372082eb5b661263d61a1194af3868968cf9 /py/objstr.c | |
parent | 6a3bc0e1a1f4dc0ad0b71ca0f168ad1a87d28859 (diff) |
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>
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/py/objstr.c b/py/objstr.c index 321bb058d..6e5a316d7 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2026,8 +2026,7 @@ const mp_obj_str_t mp_const_empty_bytes_obj = {{&mp_type_bytes}, 0, 0, (const by // the data is copied across. This function should only be used if the type is bytes, // or if the type is str and the string data is known to be not interned. mp_obj_t mp_obj_new_str_copy(const mp_obj_type_t *type, const byte *data, size_t len) { - mp_obj_str_t *o = m_new_obj(mp_obj_str_t); - o->base.type = type; + mp_obj_str_t *o = mp_obj_malloc(mp_obj_str_t, type); o->len = len; if (data) { o->hash = qstr_compute_hash(data, len); @@ -2070,8 +2069,7 @@ mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr) { } // make a new str/bytes object - mp_obj_str_t *o = m_new_obj(mp_obj_str_t); - o->base.type = type; + mp_obj_str_t *o = mp_obj_malloc(mp_obj_str_t, type); o->len = vstr->len; o->hash = qstr_compute_hash((byte *)vstr->buf, vstr->len); if (vstr->len + 1 == vstr->alloc) { |