fix save & restore in 6.3.

This commit is contained in:
Vitor Santos Costa 2012-06-12 14:50:36 +01:00
parent 7db18d5ce2
commit a997f5647c
9 changed files with 49 additions and 41 deletions

View File

@ -148,7 +148,7 @@ AtomAdjust(Atom a)
#define DelayAddrAdjust(P) (P) #define DelayAddrAdjust(P) (P)
#define DelayAdjust(P) (P) #define DelayAdjust(P) (P)
#define GlobalAdjust(P) (P) #define GlobalAdjust(P) (P)
#define DBRefAdjust(P) (P) #define DBRefAdjust(P,REF) (P)
#define DBRefPAdjust(P) (P) #define DBRefPAdjust(P) (P)
#define DBTermAdjust(P) (P) #define DBTermAdjust(P) (P)
#define LUIndexAdjust(P) (P) #define LUIndexAdjust(P) (P)

View File

@ -253,7 +253,7 @@ InsertOPCODE(OPCODE op0, int i, OPCODE op)
} }
static DBRef static DBRef
LookupDBRef(DBRef dbr) LookupDBRef(DBRef dbr, int inc_ref)
{ {
CACHE_REGS CACHE_REGS
CELL hash = (CELL)(dbr) % LOCAL_ImportDBRefHashTableSize; CELL hash = (CELL)(dbr) % LOCAL_ImportDBRefHashTableSize;
@ -262,7 +262,9 @@ LookupDBRef(DBRef dbr)
p = LOCAL_ImportDBRefHashChain[hash]; p = LOCAL_ImportDBRefHashChain[hash];
while (p) { while (p) {
if (p->oval == dbr) { if (p->oval == dbr) {
p->count++; if (inc_ref) {
p->count++;
}
return p->val; return p->val;
} }
p = p->next; p = p->next;
@ -528,11 +530,11 @@ CellPtoHeapAdjust__ (CELL * dbtp USES_REGS)
#define DelayAdjust(P) (P) #define DelayAdjust(P) (P)
#define GlobalAdjust(P) (P) #define GlobalAdjust(P) (P)
#define DBRefAdjust(P) DBRefAdjust__(P PASS_REGS) #define DBRefAdjust(P, Ref) DBRefAdjust__(P, Ref PASS_REGS)
static inline DBRef static inline DBRef
DBRefAdjust__ (DBRef dbtp USES_REGS) DBRefAdjust__ (DBRef dbtp, int do_reference USES_REGS)
{ {
return LookupDBRef(dbtp); return LookupDBRef(dbtp, do_reference);
} }
#define DBRefPAdjust(P) DBRefPAdjust__(P PASS_REGS) #define DBRefPAdjust(P) DBRefPAdjust__(P PASS_REGS)
@ -793,7 +795,6 @@ ReadHash(IOSTREAM *stream)
} }
RCHECK(read_tag(stream) == QLY_START_DBREFS); RCHECK(read_tag(stream) == QLY_START_DBREFS);
LOCAL_ImportDBRefHashTableNum = read_uint(stream); LOCAL_ImportDBRefHashTableNum = read_uint(stream);
fprintf(stderr,"reading %ld\n",LOCAL_ImportDBRefHashTableNum);
for (i = 0; i < LOCAL_ImportDBRefHashTableNum; i++) { for (i = 0; i < LOCAL_ImportDBRefHashTableNum; i++) {
LogUpdClause *ocl = (LogUpdClause *)read_uint(stream); LogUpdClause *ocl = (LogUpdClause *)read_uint(stream);
UInt sz = read_uint(stream); UInt sz = read_uint(stream);

View File

@ -300,7 +300,7 @@ PtoPredAdjust(PredEntry *pe)
#define DelayAdjust(P) (P) #define DelayAdjust(P) (P)
#define GlobalAdjust(P) (P) #define GlobalAdjust(P) (P)
#define DBRefAdjust(P) DBRefAdjust__(P PASS_REGS) #define DBRefAdjust(P,DoRef) DBRefAdjust__(P PASS_REGS)
static inline DBRef static inline DBRef
DBRefAdjust__ (DBRef dbt USES_REGS) DBRefAdjust__ (DBRef dbt USES_REGS)
{ {
@ -457,7 +457,6 @@ SaveHash(IOSTREAM *stream)
} }
save_tag(stream, QLY_START_DBREFS); save_tag(stream, QLY_START_DBREFS);
save_uint(stream, LOCAL_ExportDBRefHashTableNum); save_uint(stream, LOCAL_ExportDBRefHashTableNum);
fprintf(stderr,"exporting %ld\n",LOCAL_ImportDBRefHashTableNum);
for (i = 0; i < LOCAL_ExportDBRefHashTableSize; i++) { for (i = 0; i < LOCAL_ExportDBRefHashTableSize; i++) {
export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain[i]; export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain[i];
while (p) { while (p) {

View File

@ -241,7 +241,7 @@ static char SccsId[] = "@(#)rheap.c 1.3 3/15/90";
#define ConstantTermAdjust(P) ConstantTermAdjust__(P PASS_REGS) #define ConstantTermAdjust(P) ConstantTermAdjust__(P PASS_REGS)
#define DBGroundTermAdjust(P) DBGroundTermAdjust__(P PASS_REGS) #define DBGroundTermAdjust(P) DBGroundTermAdjust__(P PASS_REGS)
#define AdjustDBTerm(P,A,B) AdjustDBTerm__(P,A,B PASS_REGS) #define AdjustDBTerm(P,A,B,C) AdjustDBTerm__(P,A,B,C PASS_REGS)
#define AdjustSwitchTable(op, table, i) AdjustSwitchTable__(op, table, i PASS_REGS) #define AdjustSwitchTable(op, table, i) AdjustSwitchTable__(op, table, i PASS_REGS)
#define RestoreOtaplInst(start, opc, pe) RestoreOtaplInst__(start, opc, pe PASS_REGS) #define RestoreOtaplInst(start, opc, pe) RestoreOtaplInst__(start, opc, pe PASS_REGS)
#define RestoreDBErasedMarker() RestoreDBErasedMarker__( PASS_REGS1 ) #define RestoreDBErasedMarker() RestoreDBErasedMarker__( PASS_REGS1 )
@ -460,7 +460,7 @@ RestoreInvisibleAtoms__( USES_REGS1 )
/* adjusts terms stored in the data base, when they have no variables */ /* adjusts terms stored in the data base, when they have no variables */
static Term static Term
AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim USES_REGS) AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim, Term *p_max USES_REGS)
{ {
if (IsVarTerm(trm)) if (IsVarTerm(trm))
return CodeVarAdjust(trm); return CodeVarAdjust(trm);
@ -474,7 +474,7 @@ AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim USES_REGS)
out = AbsPair(p); out = AbsPair(p);
loop: loop:
if (p >= p_base || p < p_lim) { if (p >= p_base || p < p_lim) {
p[0] = AdjustDBTerm(p[0], p, p_lim); p[0] = AdjustDBTerm(p[0], p, p_lim, p_max);
if (IsPairTerm(p[1])) { if (IsPairTerm(p[1])) {
/* avoid term recursion with very deep lists */ /* avoid term recursion with very deep lists */
Term *newp = PtoHeapCellAdjust(RepPair(p[1])); Term *newp = PtoHeapCellAdjust(RepPair(p[1]));
@ -483,7 +483,7 @@ AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim USES_REGS)
p = newp; p = newp;
goto loop; goto loop;
} else { } else {
p[1] = AdjustDBTerm(p[1], p, p_lim); p[1] = AdjustDBTerm(p[1], p, p_lim, p_max);
} }
} }
return out; return out;
@ -495,6 +495,11 @@ AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim USES_REGS)
/* if it is before the current position, then we are looking /* if it is before the current position, then we are looking
at old code */ at old code */
if (p >= p_base || p < p_lim) { if (p >= p_base || p < p_lim) {
if (p >= p_max || p < p_lim) {
if (DBRefOfTerm(trm)!=DBRefAdjust(DBRefOfTerm(trm),FALSE))
/* external term pointer, has to be a DBRef */
return MkDBRefTerm(DBRefAdjust(DBRefOfTerm(trm),FALSE));
}
f = (Functor)p[0]; f = (Functor)p[0];
if (!IsExtensionFunctor(f)) { if (!IsExtensionFunctor(f)) {
UInt Arity, i; UInt Arity, i;
@ -503,9 +508,10 @@ AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim USES_REGS)
*p++ = (Term)f; *p++ = (Term)f;
Arity = ArityOfFunctor(f); Arity = ArityOfFunctor(f);
for (i = 0; i < Arity; ++i) { for (i = 0; i < Arity; ++i) {
*p = AdjustDBTerm(*p, p0, p_lim); *p = AdjustDBTerm(*p, p0, p_lim, p_max);
p++; p++;
} }
} else if (f == FunctorDBRef) {
} }
} }
return AbsAppl(p0); return AbsAppl(p0);
@ -519,22 +525,23 @@ RestoreDBTerm(DBTerm *dbr, int attachments USES_REGS)
if (attachments) { if (attachments) {
#ifdef COROUTINING #ifdef COROUTINING
if (dbr->ag.attachments) if (dbr->ag.attachments)
dbr->ag.attachments = AdjustDBTerm(dbr->ag.attachments, dbr->Contents, dbr->Contents); dbr->ag.attachments = AdjustDBTerm(dbr->ag.attachments, dbr->Contents, dbr->Contents, dbr->Contents+dbr->NOfCells);
#endif #endif
} else { } else {
if (dbr->ag.NextDBT) if (dbr->ag.NextDBT)
dbr->ag.NextDBT = DBTermAdjust(dbr->ag.NextDBT); dbr->ag.NextDBT = DBTermAdjust(dbr->ag.NextDBT);
} }
if (dbr->DBRefs != NULL) { if (dbr->DBRefs) {
DBRef *cp; DBRef *cp;
DBRef tm; DBRef tm;
dbr->DBRefs = DBRefPAdjust(dbr->DBRefs); dbr->DBRefs = DBRefPAdjust(dbr->DBRefs);
cp = dbr->DBRefs; cp = dbr->DBRefs;
while ((tm = *--cp) != 0) while ((tm = *--cp) != 0) {
*cp = DBRefAdjust(tm); *cp = DBRefAdjust(tm,TRUE);
}
} }
dbr->Entry = AdjustDBTerm(dbr->Entry, dbr->Contents, dbr->Contents); dbr->Entry = AdjustDBTerm(dbr->Entry, dbr->Contents, dbr->Contents, dbr->Contents+dbr->NOfCells);
} }
/* Restoring the heap */ /* Restoring the heap */
@ -863,7 +870,7 @@ static void
RestoreDBErasedMarker__( USES_REGS1 ) RestoreDBErasedMarker__( USES_REGS1 )
{ {
Yap_heap_regs->db_erased_marker = Yap_heap_regs->db_erased_marker =
DBRefAdjust(Yap_heap_regs->db_erased_marker); DBRefAdjust(Yap_heap_regs->db_erased_marker,TRUE);
Yap_heap_regs->db_erased_marker->id = FunctorDBRef; Yap_heap_regs->db_erased_marker->id = FunctorDBRef;
Yap_heap_regs->db_erased_marker->Flags = ErasedMask; Yap_heap_regs->db_erased_marker->Flags = ErasedMask;
Yap_heap_regs->db_erased_marker->Code = NULL; Yap_heap_regs->db_erased_marker->Code = NULL;
@ -1069,9 +1076,9 @@ RestoreDBEntry(DBRef dbr USES_REGS)
if (dbr->Code != NULL) if (dbr->Code != NULL)
dbr->Code = PtoOpAdjust(dbr->Code); dbr->Code = PtoOpAdjust(dbr->Code);
if (dbr->Prev != NULL) if (dbr->Prev != NULL)
dbr->Prev = DBRefAdjust(dbr->Prev); dbr->Prev = DBRefAdjust(dbr->Prev,TRUE);
if (dbr->Next != NULL) if (dbr->Next != NULL)
dbr->Next = DBRefAdjust(dbr->Next); dbr->Next = DBRefAdjust(dbr->Next,TRUE);
#ifdef DEBUG_RESTORE2 #ifdef DEBUG_RESTORE2
fprintf(stderr, "Recomputing masks\n"); fprintf(stderr, "Recomputing masks\n");
#endif #endif
@ -1085,26 +1092,26 @@ RestoreDB(DBEntry *pp USES_REGS)
register DBRef dbr; register DBRef dbr;
if (pp->First != NULL) if (pp->First != NULL)
pp->First = DBRefAdjust(pp->First); pp->First = DBRefAdjust(pp->First,TRUE);
if (pp->Last != NULL) if (pp->Last != NULL)
pp->Last = DBRefAdjust(pp->Last); pp->Last = DBRefAdjust(pp->Last, TRUE);
if (pp->ArityOfDB) if (pp->ArityOfDB)
pp->FunctorOfDB = FuncAdjust(pp->FunctorOfDB); pp->FunctorOfDB = FuncAdjust(pp->FunctorOfDB);
else else
pp->FunctorOfDB = (Functor) AtomAdjust((Atom)(pp->FunctorOfDB)); pp->FunctorOfDB = (Functor) AtomAdjust((Atom)(pp->FunctorOfDB));
if (pp->F0 != NULL) if (pp->F0 != NULL)
pp->F0 = DBRefAdjust(pp->F0); pp->F0 = DBRefAdjust(pp->F0, TRUE);
if (pp->L0 != NULL) if (pp->L0 != NULL)
pp->L0 = DBRefAdjust(pp->L0); pp->L0 = DBRefAdjust(pp->L0, TRUE);
/* immediate update semantics */ /* immediate update semantics */
dbr = pp->F0; dbr = pp->F0;
/* While we have something in the data base, even if erased, restore it */ /* While we have something in the data base, even if erased, restore it */
while (dbr) { while (dbr) {
RestoreDBEntry(dbr PASS_REGS); RestoreDBEntry(dbr PASS_REGS);
if (dbr->n != NULL) if (dbr->n != NULL)
dbr->n = DBRefAdjust(dbr->n); dbr->n = DBRefAdjust(dbr->n, TRUE);
if (dbr->p != NULL) if (dbr->p != NULL)
dbr->p = DBRefAdjust(dbr->p); dbr->p = DBRefAdjust(dbr->p, TRUE);
dbr = dbr->n; dbr = dbr->n;
} }
} }

View File

@ -72,7 +72,7 @@
#define DelayAddrAdjust(P) DelayAddrAdjust__(P PASS_REGS) #define DelayAddrAdjust(P) DelayAddrAdjust__(P PASS_REGS)
#define DelayAdjust(P) DelayAdjust__(P PASS_REGS) #define DelayAdjust(P) DelayAdjust__(P PASS_REGS)
#define GlobalAdjust(P) GlobalAdjust__(P PASS_REGS) #define GlobalAdjust(P) GlobalAdjust__(P PASS_REGS)
#define DBRefAdjust(P) DBRefAdjust__(P PASS_REGS) #define DBRefAdjust(P,C) DBRefAdjust__(P PASS_REGS)
#define DBRefPAdjust(P) DBRefPAdjust__(P PASS_REGS) #define DBRefPAdjust(P) DBRefPAdjust__(P PASS_REGS)
#define DBTermAdjust(P) DBTermAdjust__(P PASS_REGS) #define DBTermAdjust(P) DBTermAdjust__(P PASS_REGS)
#define LUIndexAdjust(P) LUIndexAdjust__(P PASS_REGS) #define LUIndexAdjust(P) LUIndexAdjust__(P PASS_REGS)

View File

@ -52,14 +52,15 @@ true :- true.
; ;
set_value('$verbose',off) set_value('$verbose',off)
), ),
( % '$init_preds', % needs to be done before library_directory
retractall(user:library_directory(_)), % (
'$system_library_directories'(D), % retractall(user:library_directory(_)),
assertz(user:library_directory(D)), % '$system_library_directories'(D),
fail % assertz(user:library_directory(D)),
; % fail
true % ;
), % true
% ),
'$enter_system_mode', '$enter_system_mode',
'$init_globals', '$init_globals',
'$swi_set_prolog_flag'(fileerrors, true), '$swi_set_prolog_flag'(fileerrors, true),

View File

@ -223,8 +223,9 @@ beautify_hidden_goal('$call'(G,CP,G0,M),prolog) -->
[call(M:G0)]. [call(M:G0)].
beautify_hidden_goal('$current_predicate'(M,Na,Ar),prolog) --> beautify_hidden_goal('$current_predicate'(M,Na,Ar),prolog) -->
[current_predicate(M,Na/Ar)]. [current_predicate(M,Na/Ar)].
beautify_hidden_goal('$current_predicate_for_atom'(M,Na,Ar),prolog) --> beautify_hidden_goal('$current_predicate_for_atom'(Name,M,Ar),prolog) -->
[current_predicate(M,Na/Ar)]. { functor(P, Name, Ar) },
[current_predicate(Name,M:P)].
beautify_hidden_goal('$list_clauses'(Stream,M,Pred),prolog) --> beautify_hidden_goal('$list_clauses'(Stream,M,Pred),prolog) -->
[listing(M:Pred)]. [listing(M:Pred)].

View File

@ -121,7 +121,7 @@ otherwise.
:- ['protect.yap']. :- ['protect.yap'].
version(yap,[6,0]). version(yap,[6,3]).
system_mode(verbose,on) :- set_value('$verbose',on). system_mode(verbose,on) :- set_value('$verbose',on).
system_mode(verbose,off) :- set_value('$verbose',off). system_mode(verbose,off) :- set_value('$verbose',off).

View File

@ -29,7 +29,6 @@ save_program(File, Goal) :-
recorda('$restore_goal', Goal ,_R), recorda('$restore_goal', Goal ,_R),
fail. fail.
save_program(File, _Goal) :- save_program(File, _Goal) :-
writeln(here),
qsave_program(File). qsave_program(File).
'$save_program_status' :- '$save_program_status' :-