From f37bc03304f045101585660553e65022e22efb00 Mon Sep 17 00:00:00 2001 From: vsc Date: Tue, 1 Apr 2008 14:09:43 +0000 Subject: [PATCH] improve restore git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2184 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/grow.c | 2 +- C/init.c | 15 ++++++++++----- C/save.c | 28 +++++++++++++++++++--------- H/rheap.h | 7 +++++-- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/C/grow.c b/C/grow.c index b9f978901..b588a5a3f 100644 --- a/C/grow.c +++ b/C/grow.c @@ -1435,7 +1435,7 @@ growstack(long size) fprintf(Yap_stderr, "%% took %g sec\n", (double)growth_time/1000); fprintf(Yap_stderr, "%% Total of %g sec expanding stacks \n", (double)total_stack_overflow_time/1000); } - return(TRUE); + return TRUE; } /* Used by parser when we're short of stack space */ diff --git a/C/init.c b/C/init.c index b21920970..f7f321c76 100644 --- a/C/init.c +++ b/C/init.c @@ -622,13 +622,18 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, pe->ModuleOfPred = CurrentModule; if (def != NULL) { yamop *p_code = ((StaticClause *)NULL)->ClCode; - StaticClause *cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l)); + StaticClause *cl; - if (!cl) { - Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred"); - return; + if (pe->CodeOfPred == (yamop *)(&(pe->OpcodeOfPred))) { + cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l)); + if (!cl) { + Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred"); + return; + } + Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l); + } else { + cl = ClauseCodeToStaticClause(pe->CodeOfPred); } - Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),p),l); cl->ClFlags = StaticMask; cl->ClNext = NULL; cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),e),e); diff --git a/C/save.c b/C/save.c index 28e2d18d3..4d143c971 100644 --- a/C/save.c +++ b/C/save.c @@ -1286,15 +1286,21 @@ RestoreAtomList(Atom atm) static void RestoreHashPreds(void) { - UInt new_size = PredHashTableSize; - PredEntry **oldp = (PredEntry **)AddrAdjust((ADDR)PredHash); - PredEntry **np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry **)*new_size); + UInt size = PredHashTableSize; + int malloced = FALSE; + PredEntry **np; UInt i; + PredEntry **oldp = PredHash = (PredEntry **)AddrAdjust((ADDR)PredHash); + np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry **)*size); if (!np) { - Yap_Error(FATAL_ERROR,TermNil,"Could not allocate space for pred table"); + if (!(np = (PredEntry **) malloc(sizeof(PredEntry **)*size))) { + Yap_Error(FATAL_ERROR,TermNil,"Could not allocate space for pred table"); + return; + } + malloced = TRUE; } - for (i = 0; i < new_size; i++) { + for (i = 0; i < size; i++) { np[i] = NULL; } for (i = 0; i < PredHashTableSize; i++) { @@ -1310,15 +1316,19 @@ RestoreHashPreds(void) p->NextOfPE = PropAdjust(p->NextOfPE); nextp = p->NextOfPE; CleanCode(p); - hsh = PRED_HASH(p->FunctorOfPred, p->ModuleOfPred, new_size); + hsh = PRED_HASH(p->FunctorOfPred, p->ModuleOfPred, size); p->NextOfPE = AbsPredProp(np[hsh]); np[hsh] = p; p = RepPredProp(nextp); } } - PredHashTableSize = new_size; - PredHash = np; - Yap_FreeAtomSpace((ADDR)oldp); + for (i = 0; i < size; i++) { + PredHash[i] = np[i]; + } + if (malloced) + free((ADDR)np); + else + Yap_FreeAtomSpace((ADDR)np); } diff --git a/H/rheap.h b/H/rheap.h index d5b91e3d1..8e704d048 100644 --- a/H/rheap.h +++ b/H/rheap.h @@ -11,8 +11,11 @@ * File: rheap.h * * comments: walk through heap code * * * -* Last rev: $Date: 2008-04-01 09:41:05 $,$Author: vsc $ * +* Last rev: $Date: 2008-04-01 14:09:43 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.89 2008/04/01 09:41:05 vsc +* more fixes to restore +* * Revision 1.88 2008/04/01 08:42:46 vsc * fix restore and small VISTA thingies * @@ -435,7 +438,7 @@ restore_codes(void) { Yap_heap_regs->heap_top = AddrAdjust(OldHeapTop); if (Yap_heap_regs->heap_lim) { - Yap_heap_regs->heap_lim = AddrAdjust(Yap_heap_regs->heap_lim); + Yap_heap_regs->heap_lim = GlobalAddrAdjust(Yap_heap_regs->heap_lim); } #ifdef YAPOR Yap_heap_regs->seq_def = TRUE;