From 8d886db1db1d44cda07f07346d67b3defb5b5a83 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 12 Apr 2017 13:09:21 +0900 Subject: [PATCH] avoid variable-length field --- lib/gc.c | 5 ++++- lib/object.h | 2 +- lib/proc.c | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/gc.c b/lib/gc.c index 133646c8..e36b9834 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -422,9 +422,12 @@ gc_finalize_object(pic_state *pic, struct object *obj) pic_fclose(pic, obj_value(pic, obj)); /* FIXME */ break; } + case PIC_TYPE_FRAME: { + pic_free(pic, obj->u.frame.storage); + break; + } case PIC_TYPE_PAIR: - case PIC_TYPE_FRAME: case PIC_TYPE_ERROR: case PIC_TYPE_RECORD: case PIC_TYPE_PROC_FUNC: diff --git a/lib/object.h b/lib/object.h index 9f152a49..2aae3d00 100644 --- a/lib/object.h +++ b/lib/object.h @@ -95,7 +95,7 @@ struct frame { int regc; pic_value *regs; struct frame *up; - pic_value storage[1]; + pic_value *storage; }; struct proc { diff --git a/lib/proc.c b/lib/proc.c index 5d4e2467..8751c8a9 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -39,7 +39,8 @@ pic_make_proc_func(pic_state *pic, pic_func_t func, int n, pic_value *env) if (n > 0) { int i; - fp = (struct frame *)pic_obj_alloc(pic, offsetof(struct frame, storage) + sizeof(pic_value) * n, PIC_TYPE_FRAME); + fp = (struct frame *)pic_obj_alloc(pic, sizeof(struct frame), PIC_TYPE_FRAME); + fp->storage = pic_malloc(pic, sizeof(pic_value) * n); fp->regc = n; fp->regs = fp->storage; fp->up = NULL; @@ -350,7 +351,8 @@ vm_push_cxt(pic_state *pic) { struct callinfo *ci = pic->ci; - ci->cxt = (struct frame *)pic_obj_alloc(pic, offsetof(struct frame, storage) + sizeof(pic_value) * ci->regc, PIC_TYPE_FRAME); + ci->cxt = (struct frame *)pic_obj_alloc(pic, sizeof(struct frame), PIC_TYPE_FRAME); + ci->cxt->storage = pic_malloc(pic, sizeof(pic_value) * ci->regc); ci->cxt->up = ci->up; ci->cxt->regc = ci->regc; ci->cxt->regs = ci->regs;