diff --git a/C/globals.c b/C/globals.c index 30843296d..0e4f7dd4a 100644 --- a/C/globals.c +++ b/C/globals.c @@ -265,8 +265,10 @@ GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity) if (size < 4096) { size = 4096; } - if (pt == H && ArenaPt(arena) >= B->cp_h) { + if (pt == H) { + choiceptr b_ptr; if (H+size > ASP-1024) { + XREGS[arity+1] = arena; if (!Yap_gcl(size*sizeof(CELL), arity+1, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); @@ -274,6 +276,12 @@ GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity) } arena = XREGS[arity+1]; } + /* adjust possible back pointers in choice-point stack */ + b_ptr = B; + while (b_ptr->cp_h == H) { + b_ptr->cp_h += size; + b_ptr = b_ptr->cp_b; + } H += size; } else { XREGS[arity+1] = arena;