improve signal handling.

This commit is contained in:
Vitor Santos Costa 2017-07-24 18:17:51 +01:00
parent 530d73c470
commit 22837d498b
5 changed files with 30 additions and 24 deletions

View File

@ -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;

View File

@ -28,9 +28,9 @@ static char SccsId[] = "%W% %G%";
#include <io.h>
#include <stdio.h>
#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

View File

@ -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]);

View File

@ -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);

View File

@ -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