diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index 2470c8f8..1cd02594 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -701,8 +701,8 @@ codegen_context_destroy(pic_state *pic, codegen_context *cxt) irep->localc = (int)cxt->locals->len; irep->capturec = (int)cxt->captures->len; irep->code = pic_realloc(pic, cxt->code, sizeof(pic_code) * cxt->clen); - irep->irep = pic_realloc(pic, cxt->irep, sizeof(struct pic_irep *) * cxt->ilen); - irep->ilen = cxt->ilen; + irep->irep = pic_realloc(pic, cxt->irep, sizeof(struct pic_irep *) * (cxt->ilen + 1)); + irep->irep[cxt->ilen] = NULL; irep->pool = pic_realloc(pic, cxt->pool, sizeof(pic_value) * cxt->plen); irep->plen = cxt->plen; diff --git a/extlib/benz/include/picrin/irep.h b/extlib/benz/include/picrin/irep.h index 63d9a8eb..64fde79b 100644 --- a/extlib/benz/include/picrin/irep.h +++ b/extlib/benz/include/picrin/irep.h @@ -31,7 +31,6 @@ struct pic_irep { int argc, localc, capturec; bool varg; struct pic_irep **irep; - size_t ilen; pic_value *pool; size_t plen; }; diff --git a/extlib/benz/proc.c b/extlib/benz/proc.c index ab067ced..3c897448 100644 --- a/extlib/benz/proc.c +++ b/extlib/benz/proc.c @@ -13,7 +13,7 @@ pic_irep_incref(pic_state PIC_UNUSED(*pic), struct pic_irep *irep) void pic_irep_decref(pic_state *pic, struct pic_irep *irep) { - size_t i; + struct pic_irep **i; if (--irep->refc == 0) { pic_free(pic, irep->code); @@ -23,8 +23,9 @@ pic_irep_decref(pic_state *pic, struct pic_irep *irep) irep->list.prev->next = irep->list.next; irep->list.next->prev = irep->list.prev; - for (i = 0; i < irep->ilen; ++i) { - pic_irep_decref(pic, irep->irep[i]); + i = irep->irep; + while (*i) { + pic_irep_decref(pic, *i++); } pic_free(pic, irep->irep); pic_free(pic, irep);