diff --git a/C/absmi.c b/C/absmi.c index bfe2d6d09..b23593e8e 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -2096,24 +2096,24 @@ absmi(int inp) } else { #endif +#if _MSC_VER || defined(__MINGW32__) + /* I need this for Windows and other systems where SIGINT + is not proceesed by same thread as absmi */ if (PrologMode & (AbortMode|InterruptMode)) { CFREG = CalculateStackGap(); /* same instruction */ if (PrologMode & InterruptMode) { PrologMode &= ~InterruptMode; - ProcessSIGINT(); - } - if (PrologMode & AbortMode) { - PrologMode &= ~AbortMode; ASP = Y+E_CB; if (ASP > (CELL *)B) ASP = (CELL *)B; saveregs(); - Error(PURE_ABORT, TermNil, ""); + ProcessSIGINT(); setregs(); - } + } JMPNext(); } +#endif #if SHADOW_S S = SREG; #endif diff --git a/C/iopreds.c b/C/iopreds.c index 9e3c31fcf..5af4b3aea 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -83,8 +83,6 @@ static char SccsId[] = "%W% %G%"; /* if we botched in a LongIO operation */ jmp_buf IOBotch; -int in_getc = FALSE; - #if HAVE_LIBREADLINE #if _MSC_VER || defined(__MINGW32__) @@ -890,7 +888,6 @@ ReadlineGetc(int sno) register int ch; while (ttyptr == NULL) { - in_getc = TRUE; /* Only sends a newline if we are at the start of a line */ if (_line != NULL && _line != (char *) EOF) free (_line); @@ -906,16 +903,20 @@ ReadlineGetc(int sno) while ((ch = *cptr++) != '\0') { console_count_output_char(ch,Stream+StdErrStream,StdErrStream); } + PrologMode |= ConsoleGetcMode; _line = readline (Prompt); } else { + PrologMode |= ConsoleGetcMode; _line = readline (NULL); } } else { if (ReadlinePos != ReadlineBuf) { ReadlinePos[0] = '\0'; ReadlinePos = ReadlineBuf; + PrologMode |= ConsoleGetcMode; _line = readline (ReadlineBuf); } else { + PrologMode |= ConsoleGetcMode; _line = readline (NULL); } } @@ -923,16 +924,17 @@ ReadlineGetc(int sno) if (PrologMode & InterruptMode) { PrologMode &= ~InterruptMode; ProcessSIGINT(); + PrologMode &= ~ConsoleGetcMode; if (PrologMode & AbortMode) { - Error(PURE_ABORT, TermNil, NULL); ErrorMessage = "Abort"; return(console_post_process_read_char(EOF, s, sno)); } continue; + } else { + PrologMode &= ~ConsoleGetcMode; } newline=FALSE; strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); - in_getc = FALSE; /* window of vulnerability closed */ if (_line == NULL || _line == (char *) EOF) return(console_post_process_read_char(EOF, s, sno)); @@ -1123,11 +1125,13 @@ ConsoleSocketGetc(int sno) newline = FALSE; } /* should be able to use a buffer */ + PrologMode |= ConsoleGetcMode; #if _MSC_VER count = recv(s->u.socket.fd, &c, sizeof(char), 0); #else count = read(s->u.socket.fd, &c, sizeof(char)); #endif + PrologMode &= ~ConsoleGetcMode; if (count == 0) { ch = EOF; } else if (count > 0) { @@ -1196,12 +1200,16 @@ ConsolePipeGetc(int sno) } #if _MSC_VER || defined(__MINGW32__) if (WriteFile(s->u.pipe.hdl, &c, sizeof(c), &count, NULL) == FALSE) { + PrologMode |= ConsoleGetcMode; PlIOError (SYSTEM_ERROR,TermNil, "read from pipe returned error"); + PrologMode &= ~ConsoleGetcMode; return(EOF); } #else /* should be able to use a buffer */ + PrologMode |= ConsoleGetcMode; count = read(s->u.pipe.fd, &c, sizeof(char)); + PrologMode &= ~ConsoleGetcMode; #endif if (count == 0) { ch = EOF; @@ -1282,22 +1290,23 @@ ConsoleGetc(int sno) #if HAVE_SIGINTERRUPT siginterrupt(SIGINT, TRUE); #endif - in_getc = TRUE; + PrologMode |= ConsoleGetcMode; ch = YP_fgetc(s->u.file.file); - in_getc = FALSE; #if HAVE_SIGINTERRUPT siginterrupt(SIGINT, FALSE); #endif if (PrologMode & InterruptMode) { PrologMode &= ~InterruptMode; ProcessSIGINT(); + PrologMode &= ~ConsoleGetcMode; newline = TRUE; if (PrologMode & AbortMode) { - Error(PURE_ABORT, TermNil, NULL); ErrorMessage = "Abort"; return(console_post_process_read_char(EOF, s, sno)); } goto restart; + } else { + PrologMode &= ~ConsoleGetcMode; } return(console_post_process_read_char(ch, s, sno)); } diff --git a/C/sysbits.c b/C/sysbits.c index 176d73f8b..415a792f7 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1069,10 +1069,18 @@ InteractSIGINT(int ch) { switch (ch) { case 'a': /* abort computation */ - /* we can't do a direct abort, so ask the system to do - it for us */ - p_creep(); - PrologMode |= AbortMode; + if (PrologMode & ConsoleGetcMode) { + PrologMode |= AbortMode; + } else { + getc(stdin); + Error(PURE_ABORT, TermNil, ""); + /* in case someone mangles the P register */ +#if _MSC_VER || defined(__MINGW32__) + /* don't even think about trying this */ +#else + siglongjmp (RestartEnv, 1); +#endif + } return(-1); case 'c': /* continue */ @@ -1177,7 +1185,7 @@ ProcessSIGINT(void) do { #if HAVE_LIBREADLINE - if (_line != (char *) NULL) { + if ((PrologMode & ConsoleGetcMode) && _line != (char *) NULL) { ch = _line[0]; free(_line); _line = NULL; @@ -1188,6 +1196,7 @@ ProcessSIGINT(void) continue; } else { ch = _line[0]; + free(_line); _line = NULL; } @@ -1221,10 +1230,10 @@ HandleSIGINT (int sig) InteractSIGINT('e'); } #endif - if (in_getc || (PrologMode & CritMode)) { + if (PrologMode & (CritMode|ConsoleGetcMode)) { PrologMode |= InterruptMode; #if HAVE_LIBREADLINE - if (in_getc) { + if (PrologMode & ConsoleGetcMode) { fprintf(stderr, "Action (h for help): "); #if HAVE_RL_SET_PROMPT rl_set_prompt("Action (h for help): "); diff --git a/H/Yapproto.h b/H/Yapproto.h index 1db59f501..9989fa66f 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -10,7 +10,7 @@ * File: Yap.proto * * mods: * * comments: Function declarations for YAP * -* version: $Id: Yapproto.h,v 1.10 2002-02-11 20:46:41 stasinos Exp $ * +* version: $Id: Yapproto.h,v 1.11 2002-02-12 18:24:20 vsc Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -255,6 +255,7 @@ void STD_PROTO(InitSysPreds,(void)); int STD_PROTO(TrueFileName, (char *, char *, int)); int STD_PROTO(ProcessSIGINT,(void)); double STD_PROTO(yap_random, (void)); +void STD_PROTO(set_fpu_exceptions, (int)); /* tracer.c */ #ifdef LOW_LEVEL_TRACER diff --git a/m4/Yap.h.m4 b/m4/Yap.h.m4 index b05f02df0..0b84a6e0d 100644 --- a/m4/Yap.h.m4 +++ b/m4/Yap.h.m4 @@ -10,7 +10,7 @@ * File: Yap.h.m4 * * mods: * * comments: main header file for YAP * -* version: $Id: Yap.h.m4,v 1.20 2002-02-04 16:12:54 vsc Exp $ * +* version: $Id: Yap.h.m4,v 1.21 2002-02-12 18:24:20 vsc Exp $ * *************************************************************************/ #include "config.h" @@ -767,7 +767,8 @@ typedef enum { CritMode = 4, /* If we are meddling with the heap */ AbortMode = 8, /* expecting to abort */ InterruptMode = 16, /* under an interrupt */ - InErrorMode = 32 /* under an interrupt */ + InErrorMode = 32, /* under an interrupt */ + ConsoleGetcMode = 64 /* blocked reading from console */ } prolog_exec_mode; extern prolog_exec_mode PrologMode; diff --git a/pl/boot.yap b/pl/boot.yap index 8d11817f3..4e62742cf 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -886,13 +886,12 @@ break :- '$get_value'('$break',BL), NBL is BL+1, '$change_module'(M0). '$consult'(X) :- '$find_in_path'(X,Y,consult(X)), - ( '$open'(Y,'$csult',Stream,0), !, - '$record_loaded'(Stream), - '$consult'(X,Stream), - '$close'(Stream) - ; - throw(error(permission_error(input,stream,Y),consult(X))) - ). + '$open'(Y,'$csult',Stream,0), !, + '$record_loaded'(Stream), + '$consult'(X,Stream), + '$close'(Stream). +'$consult'(X) :- + throw(error(permission_error(input,stream,X),consult(X))). '$consult'(F,Stream) :- diff --git a/pl/consult.yap b/pl/consult.yap index 4ddd78a78..72ddca96e 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -31,23 +31,21 @@ ensure_loaded(V) :- '$change_module'(M0). '$ensure_loaded'(X) :- '$find_in_path'(X,Y,ensure_loaded(X)), - ( '$open'(Y, '$csult', Stream, 0), !, - ( '$loaded'(Stream) -> - ( '$consulting_file_name'(Stream,TFN), - '$recorded'('$module','$module'(TFN,M,P),_) -> - '$current_module'(T), '$import'(P,M,T) + '$open'(Y, '$csult', Stream, 0), !, + ( '$loaded'(Stream) -> + ( '$consulting_file_name'(Stream,TFN), + '$recorded'('$module','$module'(TFN,M,P),_) -> + '$current_module'(T), '$import'(P,M,T) ; - true - ) - ; - '$record_loaded'(Stream), - '$reconsult'(X,Stream) - ), - '$close'(Stream) + true + ) ; - - throw(error(permission_error(input,stream,X),ensure_loaded(X))) - ). + '$record_loaded'(Stream), + '$reconsult'(X,Stream) + ), + '$close'(Stream). +'$ensure_loaded'(X) :- + throw(error(permission_error(input,stream,X),ensure_loaded(X))). compile(P) :- @@ -87,12 +85,12 @@ reconsult(Fs) :- '$reconsult'(Fs). '$reconsult'(X) :- '$find_in_path'(X,Y,reconsult(X)), - ( '$open'(Y,'$csult',Stream,0), !, - '$record_loaded'(Stream), - '$reconsult'(X,Stream), '$close'(Stream) - ; - throw(error(permission_error(input,stream,X),reconsult(X))) - ). + '$open'(Y,'$csult',Stream,0), !, + '$record_loaded'(Stream), + '$reconsult'(X,Stream), + '$close'(Stream). +'$reconsult'(X) :- + throw(error(permission_error(input,stream,X),reconsult(X))). '$reconsult'(F,Stream) :- '$getcwd'(OldD), diff --git a/pl/errors.yap b/pl/errors.yap index 6c364f2c7..3a4065593 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -50,7 +50,7 @@ print_message(Level, Mss) :- '$print_message'(error,error(Msg,Where)) :- '$output_error_message'(Msg, Where), !. '$print_message'(error,Throw) :- - '$format'(user_error,"[ No handler for ball ~w ]~n", [Throw]). + '$format'(user_error,"[ No handler for error ~w ]~n", [Throw]). '$print_message'(informational,M) :- ( '$get_value'('$verbose',on) -> '$do_print_message'(M) ; diff --git a/pl/modules.yap b/pl/modules.yap index 7b75a74cf..fd3b4e76e 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -34,12 +34,15 @@ use_module(M) :- '$use_module'(F), '$change_module'(M0). '$use_module'(File) :- - '$find_in_path'(File,X,use_module(File)), + '$find_in_path'(File,X,use_module(File)), !, ( '$recorded'('$module','$module'(_,X,Publics),_) -> '$use_module'(File,Publics) ; '$ensure_loaded'(File) ). +'$use_module'(File) :- + throw(error(permission_error(input,stream,File),use_module(File))). + use_module(M,I) :- '$use_module'(M, I). @@ -55,8 +58,8 @@ use_module(M,I) :- '$change_module'(M0). '$use_module'(File,Imports) :- '$current_module'(M), - '$find_in_path'(File,X,use_module(File,Imports)), - ( '$open'(X,'$csult',Stream,0), !, + '$find_in_path'(File,X,use_module(File,Imports)), !, + '$open'(X,'$csult',Stream,0), !, '$consulting_file_name'(Stream,TrueFileName), ( '$loaded'(Stream) -> true ; @@ -72,10 +75,9 @@ use_module(M,I) :- ; '$format'(user_error,"[ use_module/2 can not find a module in file ~w]~n",File), fail - ) - ; - throw(error(permission_error(input,stream,X),use_module(X,Imports))) - ). + ). +'$use_module'(File,Imports) :- + throw(error(permission_error(input,stream,File),use_module(File,Imports))). use_module(Mod,F,I) :- '$use_module'(Mod,F,I). @@ -87,28 +89,32 @@ use_module(Mod,F,I) :- '$use_module'(Module,File,Imports), '$change_module'(M0). '$use_module'(Module,File,Imports) :- - '$current_module'(M), '$find_in_path'(File,X,use_module(Module,File,Imports)), - ( '$open'(X,'$csult',Stream,0), !, + '$open'(X,'$csult',Stream,0), !, '$consulting_file_name'(Stream,TrueFileName), - ( '$loaded'(Stream) -> true - ; - '$record_loaded'(Stream), - % the following avoids import of all public predicates - '$recorda'('$importing','$importing'(TrueFileName),R), - '$reconsult'(File,Stream) - ), - '$close'(Stream), - ( var(R) -> true; erased(R) -> true; erase(R)), - ( '$recorded'('$module','$module'(TrueFileName,Module,Publics),_) -> - '$use_preds'(Imports,Publics,Module,M) - ; - '$format'(user_error,"[ use_module/2 can not find module ~w in file ~w]~n",[Module,File]), - fail - ) - ; - throw(error(permission_error(input,stream,library(X)),use_module(Module,File,Imports))) - ). + '$current_module'(M), + ( + '$loaded'(Stream) + -> + true + ; + '$record_loaded'(Stream), + % the following avoids import of all public predicates + '$recorda'('$importing','$importing'(TrueFileName),R), + '$reconsult'(File,Stream) + ), + '$close'(Stream), + ( var(R) -> true; erased(R) -> true; erase(R)), + ( + '$recorded'('$module','$module'(TrueFileName,Module,Publics),_) + -> + '$use_preds'(Imports,Publics,Module,M) + ; + '$format'(user_error,"[ use_module/2 can not find module ~w in file ~w]~n",[Module,File]), + fail + ). +'$use_module'(Module,File,Imports) :- + throw(error(permission_error(input,stream,File),use_module(Module,File,Imports))). '$consulting_file_name'(Stream,F) :- '$file_name'(Stream, F).