diff --git a/C/c_interface.c b/C/c_interface.c index 5361bbead..c74f91b4e 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -2390,9 +2390,9 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) Yap_init_yapor_global_local_memory(); #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ - // GLOBAL_PrologShouldHandleInterrupts = - // yap_init->PrologShouldHandleInterrupts && if (!yap_init->Embedded) { + GLOBAL_PrologShouldHandleInterrupts = + ~yap_init->PrologCannotHandleInterrupts; Yap_InitSysbits(0); /* init signal handling and time, required by later functions */ GLOBAL_argv = yap_init->Argv; diff --git a/C/signals.c b/C/signals.c index 17b6c8baa..58aca8d47 100755 --- a/C/signals.c +++ b/C/signals.c @@ -28,9 +28,9 @@ static char SccsId[] = "%W% %G%"; #include #include #endif +#include "YapEval.h" #include "YapHeap.h" #include "Yatom.h" -#include "YapEval.h" #include "yapio.h" #ifdef TABLING #include "tab.macros.h" @@ -65,10 +65,8 @@ static yap_signals InteractSIGINT(int ch) { case 'a': /* abort computation */ #if PUSH_REGS -// restore_absmi_regs(&Yap_standard_regs); + // restore_absmi_regs(&Yap_standard_regs); #endif - LOCAL_RestartEnv = malloc( sizeof(sigjmp_buf) ); - siglongjmp(*LOCAL_RestartEnv, 4); return YAP_ABORT_SIGNAL; case 'b': /* continue */ @@ -112,9 +110,11 @@ static yap_signals InteractSIGINT(int ch) { } } -/* - This function talks to the user about a signal. We assume we are in - the context of the main Prolog thread (trivial in Unix, but hard in WIN32) +/** + This function interacts with the user about a signal. We assume we are in + the context of the main Prolog thread (trivial in Unix, but hard in WIN32). + + */ static yap_signals ProcessSIGINT(void) { CACHE_REGS diff --git a/C/stack.c b/C/stack.c index c1bb25b7a..35381c80d 100644 --- a/C/stack.c +++ b/C/stack.c @@ -1155,9 +1155,12 @@ bool Yap_find_prolog_culprit(USES_REGS1) { while (curCP != YESCODE) { curENV = (CELL *)(curENV[E_E]); - if (curENV == NULL) + if (curENV < ASP || curENV >= LCL0) break; pe = EnvPreg(curCP); + if (pe==NULL) { + pe = PredMetaCall; + } if (pe->ModuleOfPred) return set_clause_info(curCP, pe); curCP = (yamop *)(curENV[E_CP]); diff --git a/os/readline.c b/os/readline.c index d96757f9e..5c946d825 100644 --- a/os/readline.c +++ b/os/readline.c @@ -18,7 +18,9 @@ static char SccsId[] = "%W% %G%"; #endif -/* +/** @file readline.c + * + * * This file includes the interface to the readline library, if installed in the *system. * @@ -339,22 +341,22 @@ static bool getLine(int inp) { /* window of vulnerability opened */ LOCAL_PrologMode |= ConsoleGetcMode; if (Yap_DoPrompt(s)) { // no output so far + rl_set_signals(); myrl_line = (unsigned char *)readline(LOCAL_Prompt); - s->stream_getc = ReadlineGetc; - } else { + rl_clear_signals(); +} else { + rl_set_signals(); myrl_line = (unsigned char *)readline(NULL); + rl_clear_signals(); } /* Do it the gnu way */ + LOCAL_PrologMode &= ~ConsoleGetcMode; + if (rl_pending_signal()) { + LOCAL_PrologMode |= InterruptMode; + } if (LOCAL_PrologMode & InterruptMode) { - Yap_external_signal(0, YAP_INT_SIGNAL); - LOCAL_PrologMode &= ~ConsoleGetcMode; - if (LOCAL_PrologMode & AbortMode) { - Yap_Error(ABORT_EVENT, TermNil, ""); - LOCAL_ErrorMessage = "Abort"; - return console_post_process_eof(s); - } + Yap_HandleSIGINT(); } else { - LOCAL_PrologMode &= ~ConsoleGetcMode; LOCAL_newline = true; } strncpy(LOCAL_Prompt, RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT); @@ -437,7 +439,6 @@ int Yap_ReadlineForSIGINT(void) { int ch; StreamDesc *s = &GLOBAL_Stream[StdInStream]; const unsigned char *myrl_line = s->u.irl.buf; - if ((LOCAL_PrologMode & ConsoleGetcMode) && myrl_line != NULL) { ch = myrl_line[0]; free((void *)myrl_line); diff --git a/os/sig.c b/os/sig.c index cbd4c4029..99ceae5f1 100644 --- a/os/sig.c +++ b/os/sig.c @@ -317,8 +317,10 @@ static bool set_fpu_exceptions(Term flag) { static void ReceiveSignal(int s, void *x, void *y) { CACHE_REGS LOCAL_PrologMode |= InterruptMode; - printf("11ooo\n"); - my_signal(s, ReceiveSignal); + if (s == SIGINT && (LOCAL_PrologMode & ConsoleGetcMode)) { + return; + } + my_signal(s, ReceiveSignal); switch (s) { case SIGINT: // always direct SIGINT to console