restore and agc of recorded terms
overflows in recorded.
This commit is contained in:
parent
aa1756c952
commit
a9587b5e3d
3
C/agc.c
3
C/agc.c
@ -143,6 +143,7 @@ static Term AdjustDBTerm(Term, Term *);
|
|||||||
#define OpcodeAdjust(P) (P)
|
#define OpcodeAdjust(P) (P)
|
||||||
#define ModuleAdjust(P) (P)
|
#define ModuleAdjust(P) (P)
|
||||||
#define ExternalFunctionAdjust(P) (P)
|
#define ExternalFunctionAdjust(P) (P)
|
||||||
|
#define DBRecordAdjust(P) (P)
|
||||||
#define PredEntryAdjust(P) (P)
|
#define PredEntryAdjust(P) (P)
|
||||||
#define ModEntryPtrAdjust(P) (P)
|
#define ModEntryPtrAdjust(P) (P)
|
||||||
#define AtomEntryAdjust(P) (P)
|
#define AtomEntryAdjust(P) (P)
|
||||||
@ -200,6 +201,8 @@ static Term AdjustDBTerm(Term, Term *);
|
|||||||
|
|
||||||
#include "rheap.h"
|
#include "rheap.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
RestoreHashPreds(void)
|
RestoreHashPreds(void)
|
||||||
{
|
{
|
||||||
|
@ -3152,20 +3152,80 @@ YAP_FileDescriptorFromStream(Term t)
|
|||||||
X_API void *
|
X_API void *
|
||||||
YAP_Record(Term t)
|
YAP_Record(Term t)
|
||||||
{
|
{
|
||||||
|
DBTerm *dbterm;
|
||||||
return (void *)Yap_StoreTermInDB(Deref(t), 0);
|
DBRecordList *dbt;
|
||||||
|
|
||||||
|
dbterm = Yap_StoreTermInDB(Deref(t), 0);
|
||||||
|
if (dbterm == NULL)
|
||||||
|
return NULL;
|
||||||
|
dbt = (struct record_list *)Yap_AllocCodeSpace(sizeof(struct record_list));
|
||||||
|
while (dbt == NULL) {
|
||||||
|
if (!Yap_growheap(FALSE, sizeof(struct record_list), NULL)) {
|
||||||
|
/* be a good neighbor */
|
||||||
|
Yap_FreeCodeSpace((void *)dbterm);
|
||||||
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "using YAP_Record");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Yap_Records) {
|
||||||
|
Yap_Records->prev_rec = dbt;
|
||||||
|
}
|
||||||
|
dbt->next_rec = Yap_Records;
|
||||||
|
dbt->prev_rec = NULL;
|
||||||
|
dbt->dbrecord = dbterm;
|
||||||
|
Yap_Records = dbt;
|
||||||
|
fprintf(stderr,"adding %p\n", dbt);
|
||||||
|
return dbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API Term
|
X_API Term
|
||||||
YAP_Recorded(void *handle)
|
YAP_Recorded(void *handle)
|
||||||
{
|
{
|
||||||
return Yap_FetchTermFromDB((DBTerm *)handle);
|
Term t;
|
||||||
|
fprintf(stderr,"reading %p\n", handle);
|
||||||
|
DBTerm *dbterm = ((DBRecordList *)handle)->dbrecord;
|
||||||
|
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
do {
|
||||||
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||||
|
t = Yap_FetchTermFromDB(dbterm);
|
||||||
|
if (Yap_Error_TYPE == YAP_NO_ERROR) {
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return t;
|
||||||
|
} else if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||||
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||||
|
if (!Yap_growglobal(NULL)) {
|
||||||
|
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||||
|
if (!Yap_growstack(dbterm->NOfCells*CellSize)) {
|
||||||
|
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (t == (CELL)0);
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API int
|
X_API int
|
||||||
YAP_Erase(void *handle)
|
YAP_Erase(void *handle)
|
||||||
{
|
{
|
||||||
Yap_ReleaseTermFromDB((DBTerm *)handle);
|
fprintf(stderr,"erasing %p\n", handle);
|
||||||
|
DBRecordList *dbr = (DBRecordList *)handle;
|
||||||
|
Yap_ReleaseTermFromDB(dbr->dbrecord);
|
||||||
|
if (dbr->next_rec)
|
||||||
|
dbr->next_rec->prev_rec = dbr->prev_rec;
|
||||||
|
if (dbr->prev_rec)
|
||||||
|
dbr->next_rec->prev_rec = dbr->next_rec;
|
||||||
|
else if (Yap_Records == dbr) {
|
||||||
|
Yap_Records = dbr->next_rec;
|
||||||
|
}
|
||||||
|
Yap_FreeCodeSpace(handle);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
C/save.c
15
C/save.c
@ -1691,6 +1691,20 @@ UnmarkTrEntries(void)
|
|||||||
|
|
||||||
int in_limbo = FALSE;
|
int in_limbo = FALSE;
|
||||||
|
|
||||||
|
/* cleanup any records we had in the saved state. They are now inaccessible */
|
||||||
|
static void
|
||||||
|
FreeRecords(void) {
|
||||||
|
struct record_list *ptr;
|
||||||
|
|
||||||
|
ptr = Yap_Records;
|
||||||
|
Yap_Records = NULL;
|
||||||
|
while (ptr) {
|
||||||
|
struct record_list *optr = ptr;
|
||||||
|
Yap_ReleaseTermFromDB(ptr->dbrecord);
|
||||||
|
ptr = ptr->next_rec;
|
||||||
|
Yap_FreeCodeSpace((void *)optr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is called when wanting only to restore the heap and
|
* This function is called when wanting only to restore the heap and
|
||||||
@ -1748,6 +1762,7 @@ Restore(char *s, char *lib_dir)
|
|||||||
Yap_InitPreAllocCodeSpace();
|
Yap_InitPreAllocCodeSpace();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
FreeRecords();
|
||||||
CloseRestore();
|
CloseRestore();
|
||||||
if (which_save == 2) {
|
if (which_save == 2) {
|
||||||
Yap_unify(ARG2, MkIntTerm(0));
|
Yap_unify(ARG2, MkIntTerm(0));
|
||||||
|
@ -95,6 +95,12 @@ typedef struct scratch_block_struct {
|
|||||||
UInt sz, msz;
|
UInt sz, msz;
|
||||||
} scratch_block;
|
} scratch_block;
|
||||||
|
|
||||||
|
typedef struct record_list {
|
||||||
|
/* a list of dbterms associated with a clause */
|
||||||
|
struct DB_TERM *dbrecord;
|
||||||
|
struct record_list *next_rec, *prev_rec;
|
||||||
|
} DBRecordList;
|
||||||
|
|
||||||
typedef struct restore_info {
|
typedef struct restore_info {
|
||||||
Int base_diff;
|
Int base_diff;
|
||||||
Int cl_diff;
|
Int cl_diff;
|
||||||
|
@ -298,6 +298,8 @@
|
|||||||
#define ForeignCodeTop Yap_heap_regs->foreign_code_top
|
#define ForeignCodeTop Yap_heap_regs->foreign_code_top
|
||||||
#define ForeignCodeMax Yap_heap_regs->foreign_code_max
|
#define ForeignCodeMax Yap_heap_regs->foreign_code_max
|
||||||
|
|
||||||
|
#define Yap_Records Yap_heap_regs->yap_records
|
||||||
|
|
||||||
#define SWI_Atoms Yap_heap_regs->swi_atoms
|
#define SWI_Atoms Yap_heap_regs->swi_atoms
|
||||||
#define SWI_Functors Yap_heap_regs->swi_functors
|
#define SWI_Functors Yap_heap_regs->swi_functors
|
||||||
#define SWI_ReverseHash Yap_heap_regs->swi_reverse_hash
|
#define SWI_ReverseHash Yap_heap_regs->swi_reverse_hash
|
||||||
|
@ -298,6 +298,8 @@
|
|||||||
ADDR foreign_code_top;
|
ADDR foreign_code_top;
|
||||||
ADDR foreign_code_max;
|
ADDR foreign_code_max;
|
||||||
|
|
||||||
|
struct record_list *yap_records;
|
||||||
|
|
||||||
Atom swi_atoms[N_SWI_ATOMS];
|
Atom swi_atoms[N_SWI_ATOMS];
|
||||||
Functor swi_functors[N_SWI_FUNCTORS];
|
Functor swi_functors[N_SWI_FUNCTORS];
|
||||||
struct swi_reverse_hash swi_reverse_hash[N_SWI_HASH];
|
struct swi_reverse_hash swi_reverse_hash[N_SWI_HASH];
|
||||||
|
@ -298,6 +298,8 @@
|
|||||||
Yap_heap_regs->foreign_code_top = NULL;
|
Yap_heap_regs->foreign_code_top = NULL;
|
||||||
Yap_heap_regs->foreign_code_max = NULL;
|
Yap_heap_regs->foreign_code_max = NULL;
|
||||||
|
|
||||||
|
Yap_heap_regs->yap_records = NULL;
|
||||||
|
|
||||||
InitSWIAtoms();
|
InitSWIAtoms();
|
||||||
|
|
||||||
|
|
||||||
|
15
H/rheap.h
15
H/rheap.h
@ -983,6 +983,21 @@ RestoreForeignCode(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
RestoreYapRecords(void)
|
||||||
|
{
|
||||||
|
struct record_list *ptr;
|
||||||
|
|
||||||
|
Yap_Records = DBRecordAdjust(Yap_Records);
|
||||||
|
ptr = Yap_Records;
|
||||||
|
while (ptr) {
|
||||||
|
ptr->next_rec = DBRecordAdjust(ptr->next_rec);
|
||||||
|
ptr->prev_rec = DBRecordAdjust(ptr->prev_rec);
|
||||||
|
ptr->dbrecord = DBTermAdjust(ptr->dbrecord);
|
||||||
|
RestoreDBTerm(ptr->dbrecord, FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
RestoreBallTerm(int wid)
|
RestoreBallTerm(int wid)
|
||||||
{
|
{
|
||||||
|
@ -298,6 +298,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RestoreYapRecords();
|
||||||
|
|
||||||
RestoreSWIAtoms();
|
RestoreSWIAtoms();
|
||||||
|
|
||||||
|
|
||||||
|
10
H/sshift.h
10
H/sshift.h
@ -309,6 +309,16 @@ HoldEntryAdjust (HoldEntry * ptr)
|
|||||||
return (HoldEntry *) (((HoldEntry *) (CharP (ptr) + HDiff)));
|
return (HoldEntry *) (((HoldEntry *) (CharP (ptr) + HDiff)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline EXTERN struct record_list *DBRecordAdjust (struct record_list *);
|
||||||
|
|
||||||
|
inline EXTERN struct record_list *
|
||||||
|
DBRecordAdjust (struct record_list * ptr)
|
||||||
|
{
|
||||||
|
if (!ptr)
|
||||||
|
return ptr;
|
||||||
|
return (struct record_list *) (CharP (ptr) + HDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if USE_OFFSETS
|
#if USE_OFFSETS
|
||||||
|
|
||||||
|
@ -2326,23 +2326,25 @@ X_API record_t
|
|||||||
PL_record(term_t ts)
|
PL_record(term_t ts)
|
||||||
{
|
{
|
||||||
Term t = Yap_GetFromSlot(ts);
|
Term t = Yap_GetFromSlot(ts);
|
||||||
return (record_t)Yap_StoreTermInDB(t, 0);
|
return (record_t)YAP_Record(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API int
|
X_API int
|
||||||
PL_recorded(record_t db, term_t ts)
|
PL_recorded(record_t db, term_t ts)
|
||||||
{
|
{
|
||||||
Term t = Yap_FetchTermFromDB((DBTerm *)db);
|
Term t = YAP_Recorded((void *)db);
|
||||||
if (t == 0L)
|
fprintf(stderr,"PL_recorded %ld\n", t);
|
||||||
|
if (t == ((CELL)0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
Yap_PutInSlot(ts,t);
|
Yap_PutInSlot(ts,t);
|
||||||
|
fprintf(stderr,"PL_recorded\n");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API void
|
X_API void
|
||||||
PL_erase(record_t db)
|
PL_erase(record_t db)
|
||||||
{
|
{
|
||||||
Yap_ReleaseTermFromDB((DBTerm *)db);
|
YAP_Erase((void *)db);
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API void PL_halt(int e)
|
X_API void PL_halt(int e)
|
||||||
|
@ -339,6 +339,9 @@ ADDR foreign_code_base ForeignCodeBase =NULL void
|
|||||||
ADDR foreign_code_top ForeignCodeTop =NULL void
|
ADDR foreign_code_top ForeignCodeTop =NULL void
|
||||||
ADDR foreign_code_max ForeignCodeMax =NULL void
|
ADDR foreign_code_max ForeignCodeMax =NULL void
|
||||||
|
|
||||||
|
/* recorded terms */
|
||||||
|
struct record_list *yap_records Yap_Records =NULL RestoreYapRecords()
|
||||||
|
|
||||||
/* SWI atoms and functors */
|
/* SWI atoms and functors */
|
||||||
Atom swi_atoms[N_SWI_ATOMS] SWI_Atoms InitSWIAtoms() RestoreSWIAtoms()
|
Atom swi_atoms[N_SWI_ATOMS] SWI_Atoms InitSWIAtoms() RestoreSWIAtoms()
|
||||||
Functor swi_functors[N_SWI_FUNCTORS] SWI_Functors void void
|
Functor swi_functors[N_SWI_FUNCTORS] SWI_Functors void void
|
||||||
|
Reference in New Issue
Block a user