From: fennecdjay Date: Tue, 19 Jul 2022 21:50:36 +0000 (+0200) Subject: :bug: Fix uninit mem in effects and global funptrs X-Git-Tag: nightly~264^2~86 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5f4920cfa7d06749ea0aa993958daff220d074d9;p=gwion.git :bug: Fix uninit mem in effects and global funptrs --- diff --git a/src/emit/emit.c b/src/emit/emit.c index bdc8a984..e3c7c897 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1817,8 +1817,6 @@ ANN2(1,2) static Instr _flow(const Emitter emit, const Exp e, Instr *const instr const Instr ex = (Instr)vector_back(&emit->code->instr); if(ex->execute == fast_except) { vector_rem(&emit->code->instr, vector_size(&emit->code->instr) - 1); - if(ex->m_val2) - mp_free2(emit->gwion->mp, sizeof(struct FastExceptInfo), (struct FastExceptInfo*)ex->m_val2); free_instr(emit->gwion, ex); } } @@ -2391,7 +2389,6 @@ ANN static inline m_bool emit_handler_list(const restrict Emitter emit, const Instr instr = emit_add_instr(emit, HandleEffect); instr->m_val2 = (m_uint)handler->xid; CHECK_BB(scoped_stmt(emit, handler->stmt, 1)); - //if (handler->next) CHECK_BB(emit_handler_list(emit, handler->next, v)); emit_try_goto(emit, v); instr->m_val = emit_code_size(emit); } diff --git a/src/lib/instr.c b/src/lib/instr.c index 05438217..5e476494 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -159,13 +159,15 @@ INSTR(fast_except) { VAL = -SZ_INT; instr->opcode = eNoOp; if(info) mp_free2(shred->info->mp, sizeof(struct FastExceptInfo), info); + instr->m_val2 = 0; return; } else if(info) { if(info->file) gwerr_basic("Object not instantiated", NULL, NULL, info->file, info->loc, 0); if(info->file2) gwerr_warn("declared here", NULL, NULL, info->file2, info->loc2); - mp_free2(shred->info->mp, sizeof(struct FastExceptInfo), info); +// mp_free2(shred->info->mp, sizeof(struct FastExceptInfo), info); +// instr->m_val2 = 0; } handle(shred, "NullPtrException"); } diff --git a/src/lib/xork.c b/src/lib/xork.c index 997d9cb2..8a56ccfc 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -84,6 +84,11 @@ static OP_EMIT(opem_spork) { static FREEARG(freearg_xork) { vmcode_remref((VM_Code)instr->m_val, gwion); } +static FREEARG(clean_fast_except) { + struct FastExceptInfo *info = (struct FastExceptInfo *)instr->m_val2; + if(info) mp_free2(((Gwion)gwion)->mp, sizeof(struct FastExceptInfo), info); +} + GWION_IMPORT(xork) { GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_spork)) @@ -93,5 +98,6 @@ GWION_IMPORT(xork) { GWI_BB(gwi_oper_emi(gwi, opem_spork)) GWI_BB(gwi_oper_end(gwi, "fork", NULL)) gwi_register_freearg(gwi, SporkIni, freearg_xork); + gwi_register_freearg(gwi, fast_except, clean_fast_except); return GW_OK; } diff --git a/src/parse/check.c b/src/parse/check.c index baf35d0d..04ac3b0f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1824,7 +1824,10 @@ ANN static m_bool check_trait_def(const Env env, const Trait_Def pdef) { } ANN m_bool check_fptr_def(const Env env, const Fptr_Def fptr) { - return check_class_def(env, fptr->cdef); + if(GET_FLAG(fptr->cdef, global)) env_push_global(env); + const m_bool ret = check_class_def(env, fptr->cdef); + if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); + return ret; } //#define check_fptr_def dummy_func diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 24710be2..456fdcbf 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -459,7 +459,10 @@ ANN static m_bool scan1_fdef_base_tmpl(const Env env, const Func_Def fdef) { #include "import.h" ANN m_bool scan1_fptr_def(const Env env, const Fptr_Def fptr) { - return scan1_class_def(env, fptr->cdef); + if(GET_FLAG(fptr->cdef, global))env_push_global(env); + const m_bool ret = scan1_class_def(env, fptr->cdef); + if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); + return ret; } ANN m_bool scan1_type_def(const Env env, const Type_Def tdef) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index dfda9c33..943b50a3 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -75,10 +75,12 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d, } ANN m_bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) { - CHECK_BB(scan2_class_def(env, fptr->cdef)); - const Func_Def fdef = mp_vector_at(fptr->cdef->body, struct Section_ , 0)->d.func_def; + if(GET_FLAG(fptr->cdef, global)) env_push_global(env); + const m_bool ret = scan2_class_def(env, fptr->cdef); + const Func_Def fdef = mp_vector_at(fptr->cdef->base.type->info->cdef->body, struct Section_ , 0)->d.func_def; if(fdef->base->func) set_fflag(fdef->base->func, fflag_fptr); - return GW_OK; + if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); + return ret; } ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f); diff --git a/src/vm/vm.c b/src/vm/vm.c index a787db6a..1f31a702 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -61,7 +61,7 @@ ANN static void clean_values(const VM_Shred shred) { ANN static uint16_t find_pc(const VM_Shred shred, const Symbol effect, const m_uint size) { const VM_Code code = shred->code; - const m_uint start = VKEY(&shred->info->frame, size - 1); + const m_uint start = vector_at(&shred->info->frame, vector_size(&shred->info->frame) - 2); if (start > shred->pc) return true; const Map m = &shred->code->handlers; for (m_uint i = 0; i < map_size(m); i++) { @@ -77,12 +77,8 @@ ANN static uint16_t find_pc(const VM_Shred shred, const Symbol effect, const m_u } ANN static inline bool find_handle(const VM_Shred shred, const Symbol effect, const m_uint size) { - const m_uint start = VKEY(&shred->info->frame, size - 1); - if (start > shred->pc) return true; const uint16_t pc = find_pc(shred, effect, size); - if (!pc) // outside of a try statement - return false; - // we should clean values here + if (!pc) return false; // outside of a try statement shred->reg = // restore reg (m_bit *)VPTR(&shred->info->frame, VLEN(&shred->info->frame) - 1); shredule(shred->tick->shreduler, shred, 0);