avoid variable-length field

This commit is contained in:
Yuichi Nishiwaki 2017-04-12 13:09:21 +09:00
parent 1063c45105
commit 8d886db1db
3 changed files with 9 additions and 4 deletions

View File

@ -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:

View File

@ -95,7 +95,7 @@ struct frame {
int regc;
pic_value *regs;
struct frame *up;
pic_value storage[1];
pic_value *storage;
};
struct proc {

View File

@ -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;