don't chain ireps whose npool is zero

This commit is contained in:
Yuichi Nishiwaki 2016-03-07 08:23:05 +09:00
parent 52b5e6e521
commit 5af735d796
2 changed files with 11 additions and 6 deletions

View File

@ -635,6 +635,7 @@ codegen_context_destroy(pic_state *pic, codegen_context *cxt)
/* create irep */
irep = pic_malloc(pic, sizeof(struct irep));
irep->list.next = irep->list.prev = 0;
irep->refc = 1;
irep->varg = pic_sym_p(pic, cxt->rest);
irep->argc = pic_vec_len(pic, cxt->args) + 1;
@ -651,10 +652,12 @@ codegen_context_destroy(pic_state *pic, codegen_context *cxt)
irep->nnums = cxt->flen;
irep->npool = cxt->plen;
irep->list.next = pic->ireps.next;
irep->list.prev = &pic->ireps;
irep->list.next->prev = &irep->list;
irep->list.prev->next = &irep->list;
if (irep->npool > 0) {
irep->list.next = pic->ireps.next;
irep->list.prev = &pic->ireps;
irep->list.next->prev = &irep->list;
irep->list.prev->next = &irep->list;
}
return irep;
}

View File

@ -934,8 +934,10 @@ pic_irep_decref(pic_state *pic, struct irep *irep)
pic_free(pic, irep->pool);
/* unchain before decref children ireps */
irep->list.prev->next = irep->list.next;
irep->list.next->prev = irep->list.prev;
if (irep->list.prev) { /* && irep->list.next */
irep->list.prev->next = irep->list.next;
irep->list.next->prev = irep->list.prev;
}
for (i = 0; i < irep->nirep; ++i) {
pic_irep_decref(pic, irep->irep[i]);