diff --git a/C/save.c b/C/save.c index 6185cac4e..1b2fabc5c 100755 --- a/C/save.c +++ b/C/save.c @@ -573,6 +573,7 @@ save_crc(void) static Int do_save(int mode USES_REGS) { + extern void Scleanup(void); Term t1 = Deref(ARG1); if (Yap_HoleSize) { @@ -584,6 +585,7 @@ do_save(int mode USES_REGS) { Yap_Error(TYPE_ERROR_LIST,t1,"save/1"); return FALSE; } + Scleanup(); Yap_CloseStreams(TRUE); if ((splfild = open_file(Yap_FileNameBuf, O_WRONLY | O_CREAT)) < 0) { Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)), @@ -1382,10 +1384,12 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A return(FAIL_RESTORE); Yap_PrologMode = BootMode; if (Yap_HeapBase) { + extern void Scleanup(void); if (!yap_flags[HALT_AFTER_CONSULT_FLAG] && !yap_flags[QUIET_MODE_FLAG]) { Yap_TrueFileName(s,Yap_FileNameBuf2, YAP_FILENAME_MAX); fprintf(stderr, "%% Restoring file %s\n", Yap_FileNameBuf2); } + Scleanup(); Yap_CloseStreams(TRUE); } #ifdef DEBUG_RESTORE4 @@ -1758,8 +1762,6 @@ Restore(char *s, char *lib_dir USES_REGS) } Yap_ReOpenLoadForeign(); - /* restore SWI IO */ - initIO (); Yap_InitPlIO(); /* reset time */ Yap_ReInitWallTime(); diff --git a/packages/PLStream/pl-file.c b/packages/PLStream/pl-file.c index 5d1104c76..6063f64ee 100755 --- a/packages/PLStream/pl-file.c +++ b/packages/PLStream/pl-file.c @@ -328,6 +328,10 @@ initIO() const atom_t *np; int i; +#ifdef __YAP_PROLOG__ + memset(GD, 0, sizeof(gds_t)); + memset(LD, 0, sizeof(PL_local_data_t)); +#endif streamAliases = newHTable(16); streamContext = newHTable(16); PL_register_blob_type(&stream_blob); diff --git a/packages/PLStream/pl-stream.c b/packages/PLStream/pl-stream.c index 7d5f31451..1664c0d88 100755 --- a/packages/PLStream/pl-stream.c +++ b/packages/PLStream/pl-stream.c @@ -3330,7 +3330,7 @@ static const IOSTREAM S__iob0[] = void -SinitStreams() +SinitStreams(void) { static int done; if ( !done++ )