From efd998524fd25beffb8187853580d164da46b70b Mon Sep 17 00:00:00 2001 From: vsc Date: Wed, 27 Jun 2001 13:22:30 +0000 Subject: [PATCH] More interrupt handling cleanups! git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@104 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 14 ++++++++---- C/errors.c | 1 + C/init.c | 3 ++- C/iopreds.c | 21 ++++++++---------- C/sysbits.c | 32 ++++++++++++++------------- changes4.3.html | 5 +++++ m4/Yap.h.m4 | 59 +++++++++++++++++++++++++++++++++++++------------ 7 files changed, 89 insertions(+), 46 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 395ce2de7..8b95cf8b5 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -1977,7 +1977,7 @@ absmi(int inp) * *cannot* fail before having woken up all suspended goals. */ /* make sure we are here because of an awoken goal */ - if (CFREG == Unsigned(LCL0) && !(PrologMode & AbortMode)) { + if (CFREG == Unsigned(LCL0) && !(PrologMode & (InterruptMode|AbortMode))) { Term WGs; Term my_goal; @@ -2051,11 +2051,17 @@ absmi(int inp) } else { #endif - if (PrologMode & AbortMode) { - PrologMode &= ~AbortMode; + if (PrologMode & (AbortMode|InterruptMode)) { CFREG = CalculateStackGap(); /* same instruction */ - if (ProcessSIGINT() < 0) Abort(""); + if (PrologMode & InterruptMode) { + PrologMode &= ~InterruptMode; + ProcessSIGINT(); + } + if (PrologMode & AbortMode) { + PrologMode &= ~AbortMode; + Abort(""); + } JMPNext(); } #if SHADOW_S diff --git a/C/errors.c b/C/errors.c index b652eb772..477d95659 100644 --- a/C/errors.c +++ b/C/errors.c @@ -211,6 +211,7 @@ Abort (char *format,...) va_list ap; va_start (ap, format); + PrologMode &= ~AbortMode; if (format) { char ch; diff --git a/C/init.c b/C/init.c index bc64c3a60..4f2b05592 100644 --- a/C/init.c +++ b/C/init.c @@ -138,7 +138,8 @@ char FileNameBuf[YAP_FILENAME_MAX], FileNameBuf2[YAP_FILENAME_MAX]; /********* Prolog State ********************************************/ -int PrologMode = BootMode; +prolog_exec_mode PrologMode = BootMode; +int CritLocks = 0; #if PUSH_REGS REGSTORE standard_regs; diff --git a/C/iopreds.c b/C/iopreds.c index af3dc742a..7323340fa 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -1196,26 +1196,23 @@ ConsoleGetc(int sno) strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); newline = FALSE; } - in_getc = TRUE; #if HAVE_SIGINTERRUPT siginterrupt(SIGINT, TRUE); #endif + in_getc = TRUE; ch = YP_fgetc(s->u.file.file); + in_getc = FALSE; #if HAVE_SIGINTERRUPT siginterrupt(SIGINT, FALSE); #endif - in_getc = FALSE; - if (PrologMode & AbortMode) { - PrologMode &= ~AbortMode; - CreepFlag = CalculateStackGap(); - if (ProcessSIGINT() < 0) Abort(""); - newline = TRUE; - goto restart; - } else if (ch == -1 && errno == EINTR) { - errno = 0; - PrologMode &= ~AbortMode; - if (ProcessSIGINT() < 0) Abort(""); + if (PrologMode & InterruptMode) { + PrologMode &= ~InterruptMode; + ProcessSIGINT(); newline = TRUE; + if (PrologMode & AbortMode) { + PrologMode &= ~AbortMode; + Abort(""); + } goto restart; } return(console_post_process_read_char(ch, s, sno)); diff --git a/C/sysbits.c b/C/sysbits.c index 5697192a2..b5b5f40de 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1076,7 +1076,7 @@ InteractSIGINT(char ch) { /* we can't do a direct abort, so ask the system to do it for us */ p_creep(); - PutValue(AtomThrow, MkAtomTerm(AtomTrue)); + PrologMode |= AbortMode; return(-1); case 'c': /* continue */ @@ -1177,16 +1177,6 @@ ProcessSIGINT(void) { int ch, out; -#if HAVE_ISATTY - if (!isatty(0)) { - InteractSIGINT('e'); - } -#if !HAVE_LIBREADLINE - if (in_getc) { - return(0); - } -#endif -#endif do { #if HAVE_LIBREADLINE if (_line != (char *) NULL && _line != (char *) EOF) @@ -1227,10 +1217,22 @@ HandleSIGINT (int sig) #endif { my_signal(SIGINT, HandleSIGINT); -#if (_MSC_VER || defined(__MINGW32__)) - printf("hello\n"); - return; +#if HAVE_ISATTY + if (!isatty(0)) { + InteractSIGINT('e'); + } #endif +#if !HAVE_LIBREADLINE + if (in_getc) { + PrologMode |= InterruptMode; + return; + } +#endif + if (PrologMode & CritMode) { + /* delay processing if we are messing with the Code space */ + PrologMode |= InterruptMode; + return; + } #ifdef HAVE_SETBUF /* make sure we are not waiting for the end of line */ YP_setbuf (stdin, NULL); @@ -1301,7 +1303,7 @@ MSCHandleSignal(DWORD dwCtrlType) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: p_creep(); - PrologMode |= AbortMode; + PrologMode |= InterruptMode; return(TRUE); default: return(FALSE); diff --git a/changes4.3.html b/changes4.3.html index a794462f5..919f3f21f 100644 --- a/changes4.3.html +++ b/changes4.3.html @@ -16,6 +16,11 @@

Yap-4.3.19: