From b7d4f43e66f56115cb4725b6d6cdcede8b18f891 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 19 May 2019 09:43:07 +0200 Subject: [PATCH] :art: Improve mp_alloc --- include/import.h | 2 +- include/nspc.h | 5 +++-- include/oo.h | 2 +- src/emit/emit.c | 22 +++++++++++----------- src/emit/emitter.c | 2 +- src/emit/escape.c | 2 +- src/emit/memoize.c | 6 +++--- src/gwion.c | 2 +- src/gwiondata.c | 2 +- src/lib/array.c | 4 ++-- src/lib/import.c | 2 +- src/lib/object.c | 4 ++-- src/lib/ugen.c | 6 +++--- src/lib/vararg.c | 2 +- src/oo/context.c | 2 +- src/oo/env.c | 4 ++-- src/oo/nspc.c | 6 +++--- src/oo/switch.c | 4 ++-- src/oo/type.c | 4 ++-- src/oo/value.c | 2 +- src/parse/func.c | 2 +- src/parse/operator.c | 2 +- src/plug.c | 4 ++-- src/soundinfo.c | 4 ++-- src/vm/driver.c | 4 ++-- src/vm/shreduler.c | 2 +- src/vm/vm.c | 4 ++-- src/vm/vm_code.c | 2 +- src/vm/vm_shred.c | 4 ++-- tests/import/callback.c | 2 +- util | 2 +- 31 files changed, 59 insertions(+), 58 deletions(-) diff --git a/include/import.h b/include/import.h index 56a36330..efed9751 100644 --- a/include/import.h +++ b/include/import.h @@ -19,7 +19,7 @@ typedef struct Gwi_* Gwi; #else #define GWION_IMPORT(a) ANN m_bool import(const Gwi gwi) #endif -#define ALLOC_PTR(p, a, b, c) b* a = (b*)_mp_alloc(p, sizeof(b)); *a = (b)c +#define ALLOC_PTR(p, a, b, c) b* a = (b*)_mp_calloc(p, sizeof(b)); *a = (b)c #define _CHECK_OP(op, check, func)\ CHECK_BB(gwi_oper_add(gwi, opck_##check))\ CHECK_BB(gwi_oper_end(gwi, op_##op, func)) diff --git a/include/nspc.h b/include/nspc.h index f0cd52fa..2814097d 100644 --- a/include/nspc.h +++ b/include/nspc.h @@ -58,8 +58,9 @@ describe_nspc_func(Func, func) ANN void did_you_mean_nspc(const Nspc, const char*); ANN void did_you_mean_type(const Type, const char*); -ANN static inline void nspc_allocdata(const Nspc nspc) { +ANN static inline void nspc_allocdata(MemPool mp, const Nspc nspc) { if(nspc->info->class_data_size) - nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size); +// nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size); + nspc->info->class_data = (m_bit*)mp_calloc2(mp, nspc->info->class_data_size); } #endif diff --git a/include/oo.h b/include/oo.h index 6ca6a63b..9b44c414 100644 --- a/include/oo.h +++ b/include/oo.h @@ -13,7 +13,7 @@ typedef struct RefCount_ { #define HAS_OBJ RefCount* ref; ANN static inline RefCount* new_refcount(MemPool mp, void(*free)(void*,void*)) { - RefCount *ref = mp_alloc(mp, RefCount); + RefCount *ref = mp_calloc(mp, RefCount); ref->count = 1; ref->free= free; return ref; diff --git a/src/emit/emit.c b/src/emit/emit.c index d24779ca..7926d6fe 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -51,7 +51,7 @@ static inline m_uint emit_push_global(const Emitter emit) { } ANEW static Frame* new_frame(MemPool p) { - Frame* frame = mp_alloc(p, Frame); + Frame* frame = mp_calloc(p, Frame); vector_init(&frame->stack); vector_add(&frame->stack, (vtype)NULL); return frame; @@ -67,7 +67,7 @@ ANN static void free_frame(MemPool p, Frame* a) { } ANN static Local* new_local(MemPool p, const m_uint size, const m_bool is_obj) { - Local* local = mp_alloc(p, Local); + Local* local = mp_calloc(p, Local); local->size = size; local->is_obj = is_obj; return local; @@ -99,7 +99,7 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member); ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def); ANEW static Code* new_code(const Emitter emit, const m_str name) { - Code* code = mp_alloc(emit->gwion->mp, Code); + Code* code = mp_calloc(emit->gwion->mp, Code); code->name = code_name_set(name, emit->env->name); vector_init(&code->instr); vector_init(&code->stack_break); @@ -191,7 +191,7 @@ ANN static void emit_pre_constructor_array(const Emitter emit, const Type type) ANN ArrayInfo* emit_array_extend_inner(const Emitter emit, const Type t, const Exp e) { CHECK_BO(emit_exp(emit, e, 0)) const Type base = array_base(t); - ArrayInfo* info = mp_alloc(emit->gwion->mp, ArrayInfo); + ArrayInfo* info = mp_calloc(emit->gwion->mp, ArrayInfo); vector_init(&info->type); for(m_uint i = 1; i < t->array_depth; ++i) vector_add(&info->type, (vtype)array_type(emit->env, base, i)); @@ -589,7 +589,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de if(is_obj && (is_array || !is_ref)) CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) const Instr instr = emit_kind(emit, v->type->size, emit_addr, dotstatic); - v->d.ptr = mp_alloc2(emit->gwion->mp, v->type->size); + v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size); SET_FLAG(v, union); instr->m_val = (m_uint)v->d.ptr; instr->m_val2 = v->type->size; @@ -766,7 +766,7 @@ static inline m_bool push_func_code(const Emitter emit, const Func f) { char c[sz + 1]; memcpy(c, f->name, sz); c[sz] = '\0'; - struct dottmpl_ *dt = mp_alloc(emit->gwion->mp, dottmpl); + struct dottmpl_ *dt = mp_calloc(emit->gwion->mp, dottmpl); dt->name = s_name(insert_symbol(c)); dt->overload = f->def->tmpl->base; dt->tl = tmpl_tl(emit->env, c); @@ -1367,9 +1367,9 @@ ANN void emit_union_offset(Decl_List l, const m_uint o) { } while((l = l->next)); } -ANN static inline void union_allocdata(const Stmt_Union stmt) { +ANN static inline void union_allocdata(MemPool mp, const Stmt_Union stmt) { const Nspc nspc = (stmt->xid ? stmt->value->type : stmt->type)->nspc; - nspc_allocdata(nspc); + nspc_allocdata(mp, nspc); nspc->info->offset = stmt->s; } @@ -1378,7 +1378,7 @@ ANN static m_bool emit_stmt_union(const Emitter emit, const Stmt_Union stmt) { m_uint scope = emit->env->scope->depth; const m_bool global = GET_FLAG(stmt, global); if(stmt->xid) { - union_allocdata(stmt); + union_allocdata(emit->gwion->mp, stmt); Type_Decl *type_decl = new_type_decl(emit->gwion->mp, new_id_list(emit->gwion->mp, stmt->xid, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos)), stmt->flag); @@ -1397,7 +1397,7 @@ ANN static m_bool emit_stmt_union(const Emitter emit, const Stmt_Union stmt) { } scope = emit_push_type(emit, stmt->value->type); } else if(stmt->type_xid) { - union_allocdata(stmt); + union_allocdata(emit->gwion->mp, stmt); scope = emit_push_type(emit, stmt->type); } else if(emit->env->class_def) { if(!GET_FLAG(l->self->d.exp_decl.list->self->value, member)) @@ -1726,7 +1726,7 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { if(!base->nspc->pre_ctor) CHECK_BB(emit_class_def(emit, base->e->def)) } - nspc_allocdata(nspc); + nspc_allocdata(emit->gwion->mp, nspc); emit_class_code(emit, type->name); if(cdef->base.ext && cdef->base.ext->array) CHECK_BB(emit_array_extend(emit, type->e->parent, cdef->base.ext->array->exp)) diff --git a/src/emit/emitter.c b/src/emit/emitter.c index dda013c1..97b61034 100644 --- a/src/emit/emitter.c +++ b/src/emit/emitter.c @@ -28,7 +28,7 @@ ANN void free_emitter(Emitter a) { __attribute__((returns_nonnull)) ANN2(1) Instr emit_add_instr(const Emitter emit, const f_instr f) { - const Instr instr = mp_alloc(emit->gwion->mp, Instr); + const Instr instr = mp_calloc(emit->gwion->mp, Instr); if((m_uint)f < 255) instr->opcode = (m_uint)f; else { diff --git a/src/emit/escape.c b/src/emit/escape.c index c171c14a..697e5361 100644 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@ -8,7 +8,7 @@ #include "escape.h" char* escape_table(void) { - char *escape = (char*)xcalloc(256, sizeof(char)); + char *escape = (char*)calloc(256, sizeof(char)); escape['0'] = '0'; escape['\''] = '\''; escape['"'] = '"'; diff --git a/src/emit/memoize.c b/src/emit/memoize.c index 28fbdc1f..c9fe04d9 100644 --- a/src/emit/memoize.c +++ b/src/emit/memoize.c @@ -45,7 +45,7 @@ static void(*mreturn[])(m_bit*, const m_bit*, const m_uint) = { memoize_return1, memoize_return2, memoize_return3, memoize_return4}; Memoize memoize_ini(const Emitter emit, const Func f, const enum Kind kind) { - Memoize m = mp_alloc(emit->gwion->mp, Memoize); + Memoize m = mp_calloc(emit->gwion->mp, Memoize); vector_init(&m->v); m->ret_sz = f->def->base->ret_type->size; m->kind = kind; @@ -68,7 +68,7 @@ void memoize_end(MemPool p, Memoize m) { } static inline void memoize_set(Memoize m, const m_bit* arg) { - m_bit* data = _mp_alloc2(m->p); + m_bit* data = _mp_calloc2(m->p, 0); memcpy(data, arg, m->arg_sz); if(vector_size(&m->v) < m->limit) vector_add(&m->v, (vtype)data); @@ -111,4 +111,4 @@ INSTR(MemoizeStore) { mreturn[m->kind](data + m->arg_sz, shred->reg-m->ret_sz, m->ret_sz); return; } -} \ No newline at end of file +} diff --git a/src/gwion.c b/src/gwion.c index 00fdd99e..9b0c185c 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -45,7 +45,7 @@ ANN static inline void gwion_compile(const Gwion gwion, const Vector v) { #include "shreduler_private.h" ANN VM* gwion_cpy(const VM* src) { - const Gwion gwion = mp_alloc(src->gwion->mp, Gwion); + const Gwion gwion = mp_calloc(src->gwion->mp, Gwion); gwion->vm = new_vm(src->gwion->mp, 0); gwion->vm->gwion = gwion; gwion->vm->bbq->si = soundinfo_cpy(src->gwion->mp, src->bbq->si); diff --git a/src/gwiondata.c b/src/gwiondata.c index 653c8d9c..8d31b053 100644 --- a/src/gwiondata.c +++ b/src/gwiondata.c @@ -2,7 +2,7 @@ #include "gwiondata.h" ANN GwionData* new_gwiondata(MemPool mp) { - struct GwionData_ *data = mp_alloc(mp, GwionData); + struct GwionData_ *data = mp_calloc(mp, GwionData); map_init(&data->freearg); vector_init(&data->reserved); MUTEX_SETUP(data->mutex); diff --git a/src/lib/array.c b/src/lib/array.c index bc7b2e7d..2b421af3 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -29,7 +29,7 @@ ANN m_uint m_vector_size(const M_Vector v) { } M_Vector new_m_vector(MemPool p, const m_uint size) { - const M_Vector array = mp_alloc(p, M_Vector); + const M_Vector array = mp_calloc(p, M_Vector); const size_t sz = (ARRAY_OFFSET*SZ_INT) + (2*size); array->ptr = (m_bit*)xcalloc(1, sz); ARRAY_CAP(array) = 2; @@ -38,7 +38,7 @@ M_Vector new_m_vector(MemPool p, const m_uint size) { } M_Vector new_m_vector2(MemPool p, const m_uint size, const m_uint len) { - const M_Vector array = mp_alloc(p, M_Vector); + const M_Vector array = mp_calloc(p, M_Vector); const size_t sz = (ARRAY_OFFSET*SZ_INT) + (len*size); array->ptr = (m_bit*)xcalloc(1, sz); m_uint cap = 1; diff --git a/src/lib/import.c b/src/lib/import.c index ce6068c7..7b2dc7ee 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -267,7 +267,7 @@ ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td) { ANN m_int gwi_class_end(const Gwi gwi) { if(!gwi->gwion->env->class_def) GWI_ERR_B("import: too many class_end called.") - nspc_allocdata(gwi->gwion->env->class_def->nspc); + nspc_allocdata(gwi->gwion->mp, gwi->gwion->env->class_def->nspc); env_pop(gwi->gwion->env, 0); return GW_OK; } diff --git a/src/lib/object.c b/src/lib/object.c index d82a68c0..3a04f52b 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -21,12 +21,12 @@ ANN void exception(const VM_Shred shred, const m_str c) { } M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { - const M_Object a = mp_alloc(p, M_Object); + const M_Object a = mp_calloc(p, M_Object); a->ref = 1; a->type_ref = t; a->vtable = &t->nspc->info->vtable; if(t->nspc->info->offset) - a->data = (m_bit*)_mp_alloc(p, t->nspc->info->offset); + a->data = (m_bit*)_mp_calloc(p, t->nspc->info->offset); if(shred) vector_add(&shred->gc, (vtype)a); return a; diff --git a/src/lib/ugen.c b/src/lib/ugen.c index fe9bf20f..a9e33fe7 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -76,7 +76,7 @@ describe_compute(mono, trig, {u->module.gen.trig->compute(u->module.gen.trig);} describe_compute(multi, trig, {u->module.gen.trig->compute(u->module.gen.trig);}) ANEW static UGen new_UGen(MemPool p) { - const UGen u = mp_alloc(p, UGen); + const UGen u = mp_calloc(p, UGen); u->op = ugop_add; u->compute = gen_compute_mono; return u; @@ -116,11 +116,11 @@ ANN void ugen_gen(MemPool p, const UGen u, const f_tick tick, void* data, const ANN void ugen_ini(MemPool p, const UGen u, const uint in, const uint out) { const uint chan = in > out ? in : out; if(chan == 1) { - u->connect.net = mp_alloc(p, ugen_net); + u->connect.net = mp_calloc(p, ugen_net); vector_init(&u->connect.net->from); vector_init(&u->connect.net->to); } else { - u->connect.multi = mp_alloc(p, ugen_multi); + u->connect.multi = mp_calloc(p, ugen_multi); u->connect.multi->n_in = in; u->connect.multi->n_out = out; u->connect.multi->n_chan = chan; diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 42444dd9..34f4c2cb 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -32,7 +32,7 @@ INSTR(VarargTop) { } INSTR(VarargIni) { - struct Vararg_* arg = mp_alloc(shred->info->mp, Vararg); + struct Vararg_* arg = mp_calloc(shred->info->mp, Vararg); POP_REG(shred, instr->m_val - SZ_INT) arg->d = (m_bit*)xmalloc(instr->m_val); for(m_uint i = 0; i < instr->m_val; i += SZ_INT) diff --git a/src/oo/context.c b/src/oo/context.c index b940aa90..a9230850 100644 --- a/src/oo/context.c +++ b/src/oo/context.c @@ -14,7 +14,7 @@ ANN static void free_context(const Context a, Gwion gwion) { } ANN2(2) Context new_context(MemPool p, const Ast ast, const m_str str) { - const Context context = mp_alloc(p, Context); + const Context context = mp_calloc(p, Context); context->nspc = new_nspc(p, str); context->tree = ast; context->name = str; diff --git a/src/oo/env.c b/src/oo/env.c index ea3166a3..f7e305f7 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -17,13 +17,13 @@ #include "parse.h" ANN static struct Env_Scope_ *new_envscope(MemPool p) { - struct Env_Scope_ *a = mp_alloc(p, Env_Scope); + struct Env_Scope_ *a = mp_calloc(p, Env_Scope); vector_init(&a->breaks); vector_init(&a->conts); vector_init(&a->class_stack); vector_init(&a->nspc_stack); vector_init(&a->known_ctx); - a->swi = mp_alloc(p, Scope); + a->swi = mp_calloc(p, Scope); _scope_init(a->swi); map_init(&a->swi->map); return a; diff --git a/src/oo/nspc.c b/src/oo/nspc.c index 9d8477a8..993b6a3e 100644 --- a/src/oo/nspc.c +++ b/src/oo/nspc.c @@ -58,7 +58,7 @@ ANN static void free_nspc(Nspc a, Gwion gwion) { free_nspc_value(a, gwion); if(a->info->class_data) - free(a->info->class_data); + mp_free2(gwion->mp, a->info->class_data_size, a->info->class_data); if(a->info->vtable.ptr) vector_release(&a->info->vtable); if(a->info->op_map.ptr) @@ -72,9 +72,9 @@ ANN static void free_nspc(Nspc a, Gwion gwion) { } ANN Nspc new_nspc(MemPool p, const m_str name) { - const Nspc a = mp_alloc(p, Nspc); + const Nspc a = mp_calloc(p, Nspc); a->name = name; - a->info = mp_alloc(p, NspcInfo); + a->info = mp_calloc(p, NspcInfo); a->info->value = new_scope(p); a->info->type = new_scope(p); a->info->func = new_scope(p); diff --git a/src/oo/switch.c b/src/oo/switch.c index c32c511e..11a5485c 100644 --- a/src/oo/switch.c +++ b/src/oo/switch.c @@ -20,7 +20,7 @@ static inline vtype _scope_back(Scope s) { return vector_back((Vector)(void*)s); static inline void _scope_clear(Scope s) { vector_clear((Vector)(void*)s); } static Switch new_switch(MemPool p) { - Switch sw = mp_alloc(p, Switch); + Switch sw = mp_calloc(p, Switch); sw->cases = new_map(p); // could be struct ? vector_init(&sw->exp); sw->vec = new_vector(p); @@ -42,7 +42,7 @@ struct SwInfo_ { }; ANN static Switch new_swinfo(const Env env, const Stmt_Switch stmt) { - struct SwInfo_ *info = mp_alloc(env->gwion->mp, SwInfo); + struct SwInfo_ *info = mp_calloc(env->gwion->mp, SwInfo); info->s = stmt; info->t = env->class_def; info->f = env->func; diff --git a/src/oo/type.c b/src/oo/type.c index 3c0071a1..2c6b0b28 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -18,10 +18,10 @@ ANN static void free_type(Type a, Gwion gwion) { } Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) { - const Type type = mp_alloc(p, Type); + const Type type = mp_calloc(p, Type); type->xid = xid; type->name = name; - type->e = mp_alloc(p, TypeInfo); + type->e = mp_calloc(p, TypeInfo); type->e->parent = parent; if(type->e->parent) type->size = parent->size; diff --git a/src/oo/value.c b/src/oo/value.c index 07a0f949..3ef89738 100644 --- a/src/oo/value.c +++ b/src/oo/value.c @@ -19,7 +19,7 @@ ANN static void free_value(Value a, Gwion gwion) { } ANN Value new_value(MemPool p, const Type type, const m_str name) { - const Value a = mp_alloc(p, Value); + const Value a = mp_calloc(p, Value); a->type = type; a->name = name; a->ref = new_refcount(p, free_value); diff --git a/src/parse/func.c b/src/parse/func.c index 0ee82dd0..62597aaa 100644 --- a/src/parse/func.c +++ b/src/parse/func.c @@ -22,7 +22,7 @@ ANN static void free_func(Func a, Gwion gwion) { } ANN Func new_func(MemPool p, const m_str name, const Func_Def def) { - Func func = mp_alloc(p, Func); + Func func = mp_calloc(p, Func); func->name = name; func->def = def; func->ref = new_refcount(p, free_func); diff --git a/src/parse/operator.c b/src/parse/operator.c index bb5f9b3e..a29062bb 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -98,7 +98,7 @@ ANN m_bool add_op(const Gwion gwion, const Nspc nspc, const struct Op_Import* op map_set(&nspc->info->op_map, (vtype)opi->op, (vtype)v); } // new mo - mo = mp_alloc(gwion->mp, M_Operator); + mo = mp_calloc(gwion->mp, M_Operator); mo->lhs = opi->lhs; mo->rhs = opi->rhs; mo->ret = opi->ret; diff --git a/src/plug.c b/src/plug.c index d3158fc4..3f76968f 100644 --- a/src/plug.c +++ b/src/plug.c @@ -53,7 +53,7 @@ ANN static void plug_get(MemPool p, PlugInfo* pi, const m_str c) { vector_add(&pi->vec[GWPLUG_IMPORT], (vtype)imp); const modini ini = DLSYM(dl, modini, GWMODINI_NAME); if(ini) { - struct Plug_ *plug = mp_alloc(p, Plug); + struct Plug_ *plug = mp_calloc(p, Plug); plug->ini = ini; const modstr str = DLSYM(dl, modstr, GWMODSTR_NAME); plug->name = str(); @@ -70,7 +70,7 @@ ANN static void plug_get(MemPool p, PlugInfo* pi, const m_str c) { } ANN PlugInfo* new_plug(MemPool p, const Vector list) { - PlugInfo *pi = (PlugInfo*)mp_alloc(p, PlugInfo); + PlugInfo *pi = (PlugInfo*)mp_calloc(p, PlugInfo); for(m_uint i = 0; i < GWPLUG_LAST; ++i) vector_init(&pi->vec[i]); map_init(&pi->drv); diff --git a/src/soundinfo.c b/src/soundinfo.c index 0873d842..7f232a11 100644 --- a/src/soundinfo.c +++ b/src/soundinfo.c @@ -2,14 +2,14 @@ #include struct SoundInfo_ *new_soundinfo(MemPool p) { - struct SoundInfo_ *si = mp_alloc(p, SoundInfo); + struct SoundInfo_ *si = mp_calloc(p, SoundInfo); si->in = si->out = 2; si->sr = 48000; return si; } struct SoundInfo_ *soundinfo_cpy(MemPool p, const struct SoundInfo_ *src) { - struct SoundInfo_ *si = mp_alloc(p, SoundInfo); + struct SoundInfo_ *si = mp_calloc(p, SoundInfo); si->in = src->in; si->out = src->out; si->sr = src->sr; diff --git a/src/vm/driver.c b/src/vm/driver.c index e1a5f4b3..da06f6f9 100644 --- a/src/vm/driver.c +++ b/src/vm/driver.c @@ -12,9 +12,9 @@ #include "driver.h" ANN Driver* new_driver(MemPool p) { - Driver* di = (Driver*)mp_alloc(p, BBQ); + Driver* di = (Driver*)mp_calloc(p, BBQ); di->func = dummy_driver; - di->driver = (DriverData*)mp_alloc(p, DriverData); + di->driver = (DriverData*)mp_calloc(p, DriverData); di->is_running = 1; return di; } diff --git a/src/vm/shreduler.c b/src/vm/shreduler.c index a3b0c5b7..6d1e4371 100644 --- a/src/vm/shreduler.c +++ b/src/vm/shreduler.c @@ -100,7 +100,7 @@ ANN void shredule(const Shreduler s, const VM_Shred shred, const m_float wake_ti } ANN void shreduler_add(const Shreduler s, const VM_Shred shred) { - shred->tick = mp_alloc(shred->info->mp, ShredTick); + shred->tick = mp_calloc(shred->info->mp, ShredTick); shred->tick->self = shred; shred->tick->shreduler = s; shred->tick->xid = ++s->shred_ids; diff --git a/src/vm/vm.c b/src/vm/vm.c index 88475d85..51237539 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -810,11 +810,11 @@ static void vm_run_audio(const VM *vm) { } VM* new_vm(MemPool p, const m_bool audio) { - VM* vm = (VM*)mp_alloc(p, VM); + VM* vm = (VM*)mp_calloc(p, VM); vector_init(&vm->ugen); vm->bbq = new_driver(p); vm->bbq->run = audio ? vm_run_audio : vm_run; - vm->shreduler = (Shreduler)mp_alloc(p, Shreduler); + vm->shreduler = (Shreduler)mp_calloc(p, Shreduler); vector_init(&vm->shreduler->shreds); MUTEX_SETUP(vm->shreduler->mutex); vm->shreduler->bbq = vm->bbq; diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 092caadb..76078fdc 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -41,7 +41,7 @@ ANN static void free_vm_code(VM_Code a, Gwion gwion) { VM_Code new_vm_code(MemPool p, const Vector instr, const m_uint stack_depth, const ae_flag flag, const m_str name) { - VM_Code code = mp_alloc(p, VM_Code); + VM_Code code = mp_calloc(p, VM_Code); code->instr = instr ? vector_copy(p, instr) : NULL; code->name = strdup(name); code->stack_depth = stack_depth; diff --git a/src/vm/vm_shred.c b/src/vm/vm_shred.c index e4edcebd..02e4fc76 100644 --- a/src/vm/vm_shred.c +++ b/src/vm/vm_shred.c @@ -15,7 +15,7 @@ struct Stack_ { }; static inline struct ShredInfo_ *new_shredinfo(MemPool p, const m_str name) { - struct ShredInfo_ *info = mp_alloc(p, ShredInfo); + struct ShredInfo_ *info = mp_calloc(p, ShredInfo); info->mp = p; info->name = strdup(name); return info; @@ -34,7 +34,7 @@ static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) { } VM_Shred new_vm_shred(MemPool p, VM_Code c) { - const VM_Shred shred = mp_alloc(p, Stack); + const VM_Shred shred = mp_calloc(p, Stack); shred->code = c; shred->reg = (m_bit*)shred + sizeof(struct VM_Shred_); shred->base = shred->mem = shred->reg + SIZEOF_REG; diff --git a/tests/import/callback.c b/tests/import/callback.c index 4b35ea5f..1dfd3cdb 100644 --- a/tests/import/callback.c +++ b/tests/import/callback.c @@ -43,7 +43,7 @@ static SFUN(cb_func) { } m_uint offset = shred->mem - ((m_bit*)shred + sizeof(struct VM_Shred_) + SIZEOF_REG); PUSH_MEM(shred, offset); - Instr instr = mp_alloc(shred->info->mp, Instr); + Instr instr = mp_calloc(shred->info->mp, Instr); struct ret_info* info = (struct ret_info*)xmalloc(sizeof(struct ret_info)); info->offset = offset; info->code = shred->code; diff --git a/util b/util index bbaef376..059393b7 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit bbaef376bdbc13bba73d5f24e58701bcaf885f72 +Subproject commit 059393b7d69ed555bfef29ba99500d508a378637 -- 2.43.0