From 863747da7bcd335f7cb40d63f8b9938254ada241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 29 Nov 2010 18:08:11 +0000 Subject: [PATCH 1/2] fix save/1 and save/2 to at least work now. --- C/save.c | 45 ++++++++++++++++----------------------------- pl/utils.yap | 9 +++------ 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/C/save.c b/C/save.c index 30b06ff9e..dcb3b7600 100755 --- a/C/save.c +++ b/C/save.c @@ -97,7 +97,7 @@ STATIC_PROTO(int save_heap, (void)); STATIC_PROTO(int save_stacks, (int)); STATIC_PROTO(int save_crc, (void)); STATIC_PROTO(Int do_save, (int)); -STATIC_PROTO(Int p_save, (void)); +STATIC_PROTO(Int p_save2, (void)); STATIC_PROTO(Int p_save_program, (void)); STATIC_PROTO(int check_header, (CELL *, CELL *, CELL *, CELL *)); STATIC_PROTO(int get_heap_info, (void)); @@ -606,49 +606,36 @@ do_save(int mode) { /* Saves a complete prolog environment */ static Int -p_save(void) +p_save2(void) { Int res; + Term t; #if defined(YAPOR) && !defined(THREADS) if (number_workers != 1) { - Yap_Error(SYSTEM_ERROR,TermNil,"cannot perform save: more than a worker/thread running"); + Yap_Error(SYSTEM_ERROR,TermNil, + "cannot perform save: more than a worker/thread running"); return(FALSE); } #elif defined(THREADS) if (NOfThreads != 1) { - Yap_Error(SYSTEM_ERROR,TermNil,"cannot perform save: more than a worker/thread running"); + Yap_Error(SYSTEM_ERROR,TermNil, + "cannot perform save: more than a worker/thread running"); return(FALSE); } #endif - which_save = 1; + /* avoid double saves */ + if (IsNonVarTerm(t = Deref(ARG2))) + return TRUE; + if (!Yap_unify(ARG2,MkIntTerm(1))) + return FALSE; + which_save = 2; Yap_StartSlots(); res = do_save(DO_EVERYTHING); Yap_CloseSlots(); return res; } -/* Saves a complete prolog environment */ -static Int -p_save2(void) -{ -#if defined(YAPOR) && !defined(THREADS) - if (number_workers != 1) { - Yap_Error(SYSTEM_ERROR,TermNil, - "cannot perform save: more than a worker/thread running"); - return(FALSE); - } -#elif defined(THREADS) - if (NOfThreads != 1) { - Yap_Error(SYSTEM_ERROR,TermNil, - "cannot perform save: more than a worker/thread running"); - return(FALSE); - } -#endif - which_save = 2; - return(do_save(DO_EVERYTHING) && Yap_unify(ARG2,MkIntTerm(1))); -} - /* Just save the program, not the stacks */ static Int p_save_program(void) @@ -1778,6 +1765,7 @@ static Int p_restore(void) { int mode; + char s[YAP_FILENAME_MAX+1]; Term t1 = Deref(ARG1); #if defined(YAPOR) && !defined(THREADS) @@ -1791,11 +1779,11 @@ p_restore(void) return(FALSE); } #endif - if (!Yap_GetName(Yap_FileNameBuf, YAP_FILENAME_MAX, t1)) { + if (!Yap_GetName(s, YAP_FILENAME_MAX, t1)) { Yap_Error(TYPE_ERROR_LIST,t1,"restore/1"); return(FALSE); } - if ((mode = Restore(Yap_FileNameBuf, NULL)) == DO_ONLY_CODE) { + if ((mode = Restore(s, NULL)) == DO_ONLY_CODE) { #if PUSH_REGS restore_absmi_regs(&Yap_standard_regs); #endif @@ -1808,7 +1796,6 @@ p_restore(void) void Yap_InitSavePreds(void) { - Yap_InitCPred("$save", 1, p_save, SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$save", 2, p_save2, SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$save_program", 1, p_save_program, SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$restore", 1, p_restore, SyncPredFlag|HiddenPredFlag); diff --git a/pl/utils.yap b/pl/utils.yap index bf31e3640..798450484 100644 --- a/pl/utils.yap +++ b/pl/utils.yap @@ -307,19 +307,16 @@ getenv(Na,Val) :- %%% Saving and restoring a computation -save(A) :- var(A), !, - '$do_error'(instantiation_error,save(A)). -save(A) :- atom(A), !, name(A,S), '$save'(S). -save(S) :- '$save'(S). +save(A) :- save(A,_). save(A,_) :- var(A), !, '$do_error'(instantiation_error,save(A)). -save(A,OUT) :- atom(A), !, name(A,S), '$save'(S,OUT). +save(A,OUT) :- atom(A), !, atom_codes(A,S), '$save'(S,OUT). save(S,OUT) :- '$save'(S,OUT). save_program(A) :- var(A), !, '$do_error'(instantiation_error,save_program(A)). -save_program(A) :- atom(A), !, name(A,S), '$save_program'(S). +save_program(A) :- atom(A), !, atom_codes(A,S), '$save_program'(S). save_program(S) :- '$save_program'(S). save_program(A, G) :- var(A), !, From 2a8854094bdbd098dadad7669792f7bf6d2e7004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 29 Nov 2010 18:08:29 +0000 Subject: [PATCH 2/2] halt_hooks should not be in save/restore, this will cause trouble. --- H/dglobals.h | 2 ++ H/dhstruct.h | 2 -- H/hglobals.h | 2 ++ H/hstruct.h | 2 -- H/iglobals.h | 2 ++ H/ihstruct.h | 2 -- H/rglobals.h | 2 ++ H/rheap.h | 12 ------------ H/rhstruct.h | 2 -- misc/GLOBALS | 3 +++ misc/HEAPFIELDS | 3 --- 11 files changed, 11 insertions(+), 23 deletions(-) diff --git a/H/dglobals.h b/H/dglobals.h index 31d5a6ebd..b65cf8a51 100644 --- a/H/dglobals.h +++ b/H/dglobals.h @@ -217,3 +217,5 @@ #define Yap_PL_Argc Yap_global->pl_argc #define Yap_PL_Argv Yap_global->pl_argv +#define Yap_HaltHooks Yap_global->yap_halt_hook + diff --git a/H/dhstruct.h b/H/dhstruct.h index 19249f0ba..6be01d069 100644 --- a/H/dhstruct.h +++ b/H/dhstruct.h @@ -263,8 +263,6 @@ #define Stream Yap_heap_regs->yap_streams -#define Yap_HaltHooks Yap_heap_regs->yap_halt_hook - #define NOfFileAliases Yap_heap_regs->n_of_file_aliases #define SzOfFileAliases Yap_heap_regs->sz_of_file_aliases #define FileAliases Yap_heap_regs->file_aliases diff --git a/H/hglobals.h b/H/hglobals.h index e825d712d..c14707c6f 100644 --- a/H/hglobals.h +++ b/H/hglobals.h @@ -218,4 +218,6 @@ typedef struct worker_shared { int initialised_from_pl; int pl_argc; char **pl_argv; + + struct halt_hook *yap_halt_hook; } w_shared; diff --git a/H/hstruct.h b/H/hstruct.h index a9f44a7d6..99b06b296 100644 --- a/H/hstruct.h +++ b/H/hstruct.h @@ -263,8 +263,6 @@ struct stream_desc *yap_streams; - struct halt_hook *yap_halt_hook; - UInt n_of_file_aliases; UInt sz_of_file_aliases; struct AliasDescS *file_aliases; diff --git a/H/iglobals.h b/H/iglobals.h index 08cf8a73c..24e0db95d 100644 --- a/H/iglobals.h +++ b/H/iglobals.h @@ -216,4 +216,6 @@ static void InitGlobal(void) { Yap_global->initialised_from_pl = FALSE; Yap_global->pl_argc = 0; Yap_global->pl_argv = NULL; + + Yap_global->yap_halt_hook = NULL; } diff --git a/H/ihstruct.h b/H/ihstruct.h index e0f4c3e3d..a9e12a561 100644 --- a/H/ihstruct.h +++ b/H/ihstruct.h @@ -263,8 +263,6 @@ Yap_heap_regs->yap_streams = NULL; - Yap_heap_regs->yap_halt_hook = NULL; - Yap_heap_regs->n_of_file_aliases = 0; Yap_heap_regs->sz_of_file_aliases = 0; Yap_heap_regs->file_aliases = NULL; diff --git a/H/rglobals.h b/H/rglobals.h index 06fcdd842..304992160 100644 --- a/H/rglobals.h +++ b/H/rglobals.h @@ -216,4 +216,6 @@ static void RestoreGlobal(void) { + + } diff --git a/H/rheap.h b/H/rheap.h index a4c978728..127a32fd4 100755 --- a/H/rheap.h +++ b/H/rheap.h @@ -903,18 +903,6 @@ RestoreDBErasedIList(void) } } -static void -RestoreHaltHooks(void) -{ - struct halt_hook *hooke = Yap_HaltHooks = HaltHookAdjust(Yap_HaltHooks); - - while (hooke) { - hooke->next = HaltHookAdjust(hooke->next); - hooke = hooke->next; - } -} - - static void RestoreStreams(void) { diff --git a/H/rhstruct.h b/H/rhstruct.h index 688edfe8b..5e04e4521 100644 --- a/H/rhstruct.h +++ b/H/rhstruct.h @@ -263,8 +263,6 @@ RestoreStreams(); - RestoreHaltHooks(); - RestoreAliases(); diff --git a/misc/GLOBALS b/misc/GLOBALS index 8d1d2e35b..c1df5ec57 100644 --- a/misc/GLOBALS +++ b/misc/GLOBALS @@ -245,5 +245,8 @@ int initialised_from_pl Yap_InitialisedFromPL =FALSE int pl_argc Yap_PL_Argc =0 char **pl_argv Yap_PL_Argv =NULL +// halt hooks +struct halt_hook *yap_halt_hook Yap_HaltHooks =NULL + END_WORKER_SHARED diff --git a/misc/HEAPFIELDS b/misc/HEAPFIELDS index 6a5824733..a1ba72fa4 100644 --- a/misc/HEAPFIELDS +++ b/misc/HEAPFIELDS @@ -295,9 +295,6 @@ struct operator_entry *op_list OpList =NULL OpListAdjust /* stream array */ struct stream_desc *yap_streams Stream =NULL RestoreStreams() -/* halt hooks */ -struct halt_hook *yap_halt_hook Yap_HaltHooks =NULL RestoreHaltHooks() - /* stream aliases */ UInt n_of_file_aliases NOfFileAliases =0 void UInt sz_of_file_aliases SzOfFileAliases =0 void