extra fixes for overflows with global variables, especially showing up

with malloc (thanks to Paulo Moura!)


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1743 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2006-12-27 18:26:19 +00:00
parent bb51b72a9d
commit 7316eb490c
2 changed files with 21 additions and 7 deletions

View File

@ -168,9 +168,9 @@ GrowDelayArena(Term *arenap, UInt old_size, UInt size, UInt arity)
if (size == 0) {
if (old_size < 1024) {
size = old_size;
size = old_size*2;
} else {
size = 1024;
size = old_size+1024;
}
}
if (size < 64) {
@ -272,7 +272,7 @@ GrowArena(Term arena, CELL *pt, UInt old_size, UInt size, UInt arity)
if (old_size < 1024*1024) {
size = old_size;
} else {
size = 1024*1024;
size = old_size+1024*1024;
}
}
if (size < 4096) {
@ -842,6 +842,7 @@ CopyTermToArena(Term t, Term arena, UInt arity, Term *newarena, Term *att_arenap
case -3:
/* handle delay arena overflow */
old_size = DelayArenaSz(*att_arenap);
if (!GrowDelayArena(att_arenap, old_size, 0L, arity+4)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return 0L;
@ -1207,13 +1208,19 @@ p_nb_queue_enqueue(void)
CELL *qd = GetQueue(ARG1,"enqueue"), *oldH, *oldHB;
UInt old_sz;
Term arena, qsize, to;
UInt min_size;
if (!qd)
return FALSE;
arena = GetQueueArena(qd,"enqueue");
if (arena == 0L)
return FALSE;
to = CopyTermToArena(ARG2, arena, 2, qd+QUEUE_ARENA, qd+QUEUE_DELAY_ARENA,ArenaPt(arena)-RepPair(qd[QUEUE_HEAD]));
if (IsPairTerm(qd[QUEUE_HEAD])) {
min_size = ArenaPt(arena)-RepPair(qd[QUEUE_HEAD]);
} else {
min_size = 0L;
}
to = CopyTermToArena(ARG2, arena, 2, qd+QUEUE_ARENA, qd+QUEUE_DELAY_ARENA, min_size);
if (to == 0L)
return FALSE;
qd = GetQueue(ARG1,"enqueue");

View File

@ -618,7 +618,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
start_growth_time = Yap_cputime();
if (do_grow) {
if (!Yap_ExtendWorkSpace(size)) {
/* always fails when using malloc */
Yap_ErrorMessage = NULL;
size += AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+MinHeapGap); minimal_request = size;
size = Yap_ExtendWorkSpaceThroughHole(size);
@ -659,6 +659,13 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
TrDiff = DelayDiff = LDiff = 0;
GDiff = size;
}
GDiff0 = DelayDiff;
if (hsplit) {
GDiff = GDiff0+sz;
GSplit = hsplit;
} else {
GSplit = NULL;
}
#else
if (!do_grow) {
TrDiff = DelayDiff = LDiff = 0;
@ -671,7 +678,6 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
TrDiff = LDiff = GDiff = size;
DelayDiff = 0;
}
#endif
if (hsplit) {
GDiff0 = GDiff-size0;
GSplit = hsplit;
@ -679,6 +685,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
GDiff0 = DelayDiff;
GSplit = NULL;
}
#endif
XDiff = HDiff = 0;
Yap_GlobalBase = old_GlobalBase;
SetHeapRegs();
@ -710,7 +717,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
fprintf(Yap_stderr, "%% %cO Total of %g sec expanding stacks \n", vb_msg1, (double)total_delay_overflow_time/1000);
}
Yap_PrologMode &= ~GrowStackMode;
return size0;
return size;
}
static void