From 4b5ba54bb6ee4a981710a02461294583c34a966d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 6 May 2020 12:28:29 +0200 Subject: [PATCH] :bug: Afl fixes --- include/env/tuple.h | 2 +- src/env/tupleform.c | 5 ++++- src/env/type.c | 4 ++-- src/parse/scan0.c | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/env/tuple.h b/include/env/tuple.h index a39d2b7d..5cdda4f1 100644 --- a/include/env/tuple.h +++ b/include/env/tuple.h @@ -10,7 +10,7 @@ struct TupleForm_ { ANN Type tuple_type(const Env, const Vector, const loc_t); ANN void tuple_info(const Env, const Value); ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type); -ANN void free_tupleform(const TupleForm tuple); +ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion); #ifdef __INSTR INSTR(TupleCtor); diff --git a/src/env/tupleform.c b/src/env/tupleform.c index f5403217..59f77001 100644 --- a/src/env/tupleform.c +++ b/src/env/tupleform.c @@ -17,6 +17,7 @@ ANN void tuple_info(const Env env, const Value v) { const m_uint offset = vector_back(&env->class_def->e->tuple->offset); + ADD_REF(v->type); vector_add(&env->class_def->e->tuple->types, (vtype)v->type); vector_add(&env->class_def->e->tuple->offset, offset + v->type->size); } @@ -43,7 +44,9 @@ ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { return tuple; } -ANN void free_tupleform(const TupleForm tuple) { +ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) { + for(m_uint i = 0; i < vector_size(&tuple->types); ++i) + REM_REF((Type)vector_at(&tuple->types, i), (void*)gwion); vector_release(&tuple->types); vector_release(&tuple->offset); } diff --git a/src/env/type.c b/src/env/type.c index e12ae708..46fe3001 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -28,7 +28,7 @@ ANN static void free_type(Type a, Gwion gwion) { if(a->nspc) REM_REF(a->nspc, gwion); if(a->e->tuple) - free_tupleform(a->e->tuple); + free_tupleform(a->e->tuple, gwion); mp_free(gwion->mp, TypeInfo, a->e); mp_free(gwion->mp, Type, a); } @@ -86,7 +86,7 @@ ANN Type typedef_base(Type t) { ANN Type array_base(Type type) { const Type t = typedef_base(type); - return t->e->d.base_type; + return t->array_depth ? t->e->d.base_type : t; } ANN static Symbol array_sym(const Env env, const Type src, const m_uint depth) { diff --git a/src/parse/scan0.c b/src/parse/scan0.c index ce645987..7e5adef3 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -153,8 +153,9 @@ ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type ba ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, const Type base) { const ae_flag flag = base->e->def ? base->e->def->flag : 0; - const Class_Def cdef = new_class_def(env->gwion->mp, flag, tdef->xid, tdef->ext, NULL, - loc_cpy(env->gwion->mp, td_pos(tdef->ext))); + const Class_Def cdef = new_class_def(env->gwion->mp, flag, tdef->xid, + cpy_type_decl(env->gwion->mp, tdef->ext), NULL, + loc_cpy(env->gwion->mp, td_pos(tdef->ext))); CHECK_BB(scan0_class_def(env, cdef)) tdef->type = cdef->base.type; cdef->base.tmpl = tdef->tmpl;// check cpy -- 2.43.0