improve signal handling.
This commit is contained in:
parent
530d73c470
commit
22837d498b
@ -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)
|
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
|
||||||
Yap_init_yapor_global_local_memory();
|
Yap_init_yapor_global_local_memory();
|
||||||
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
||||||
// GLOBAL_PrologShouldHandleInterrupts =
|
|
||||||
// yap_init->PrologShouldHandleInterrupts &&
|
|
||||||
if (!yap_init->Embedded) {
|
if (!yap_init->Embedded) {
|
||||||
|
GLOBAL_PrologShouldHandleInterrupts =
|
||||||
|
~yap_init->PrologCannotHandleInterrupts;
|
||||||
Yap_InitSysbits(0); /* init signal handling and time, required by later
|
Yap_InitSysbits(0); /* init signal handling and time, required by later
|
||||||
functions */
|
functions */
|
||||||
GLOBAL_argv = yap_init->Argv;
|
GLOBAL_argv = yap_init->Argv;
|
||||||
|
14
C/signals.c
14
C/signals.c
@ -28,9 +28,9 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "YapEval.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "YapEval.h"
|
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
#include "tab.macros.h"
|
#include "tab.macros.h"
|
||||||
@ -65,10 +65,8 @@ static yap_signals InteractSIGINT(int ch) {
|
|||||||
case 'a':
|
case 'a':
|
||||||
/* abort computation */
|
/* abort computation */
|
||||||
#if PUSH_REGS
|
#if PUSH_REGS
|
||||||
// restore_absmi_regs(&Yap_standard_regs);
|
// restore_absmi_regs(&Yap_standard_regs);
|
||||||
#endif
|
#endif
|
||||||
LOCAL_RestartEnv = malloc( sizeof(sigjmp_buf) );
|
|
||||||
siglongjmp(*LOCAL_RestartEnv, 4);
|
|
||||||
return YAP_ABORT_SIGNAL;
|
return YAP_ABORT_SIGNAL;
|
||||||
case 'b':
|
case 'b':
|
||||||
/* continue */
|
/* 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
|
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)
|
the context of the main Prolog thread (trivial in Unix, but hard in WIN32).
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static yap_signals ProcessSIGINT(void) {
|
static yap_signals ProcessSIGINT(void) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
@ -1155,9 +1155,12 @@ bool Yap_find_prolog_culprit(USES_REGS1) {
|
|||||||
|
|
||||||
while (curCP != YESCODE) {
|
while (curCP != YESCODE) {
|
||||||
curENV = (CELL *)(curENV[E_E]);
|
curENV = (CELL *)(curENV[E_E]);
|
||||||
if (curENV == NULL)
|
if (curENV < ASP || curENV >= LCL0)
|
||||||
break;
|
break;
|
||||||
pe = EnvPreg(curCP);
|
pe = EnvPreg(curCP);
|
||||||
|
if (pe==NULL) {
|
||||||
|
pe = PredMetaCall;
|
||||||
|
}
|
||||||
if (pe->ModuleOfPred)
|
if (pe->ModuleOfPred)
|
||||||
return set_clause_info(curCP, pe);
|
return set_clause_info(curCP, pe);
|
||||||
curCP = (yamop *)(curENV[E_CP]);
|
curCP = (yamop *)(curENV[E_CP]);
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/** @file readline.c
|
||||||
|
*
|
||||||
|
*
|
||||||
* This file includes the interface to the readline library, if installed in the
|
* This file includes the interface to the readline library, if installed in the
|
||||||
*system.
|
*system.
|
||||||
*
|
*
|
||||||
@ -339,22 +341,22 @@ static bool getLine(int inp) {
|
|||||||
/* window of vulnerability opened */
|
/* window of vulnerability opened */
|
||||||
LOCAL_PrologMode |= ConsoleGetcMode;
|
LOCAL_PrologMode |= ConsoleGetcMode;
|
||||||
if (Yap_DoPrompt(s)) { // no output so far
|
if (Yap_DoPrompt(s)) { // no output so far
|
||||||
|
rl_set_signals();
|
||||||
myrl_line = (unsigned char *)readline(LOCAL_Prompt);
|
myrl_line = (unsigned char *)readline(LOCAL_Prompt);
|
||||||
s->stream_getc = ReadlineGetc;
|
rl_clear_signals();
|
||||||
} else {
|
} else {
|
||||||
|
rl_set_signals();
|
||||||
myrl_line = (unsigned char *)readline(NULL);
|
myrl_line = (unsigned char *)readline(NULL);
|
||||||
|
rl_clear_signals();
|
||||||
}
|
}
|
||||||
/* Do it the gnu way */
|
/* Do it the gnu way */
|
||||||
|
LOCAL_PrologMode &= ~ConsoleGetcMode;
|
||||||
|
if (rl_pending_signal()) {
|
||||||
|
LOCAL_PrologMode |= InterruptMode;
|
||||||
|
}
|
||||||
if (LOCAL_PrologMode & InterruptMode) {
|
if (LOCAL_PrologMode & InterruptMode) {
|
||||||
Yap_external_signal(0, YAP_INT_SIGNAL);
|
Yap_HandleSIGINT();
|
||||||
LOCAL_PrologMode &= ~ConsoleGetcMode;
|
|
||||||
if (LOCAL_PrologMode & AbortMode) {
|
|
||||||
Yap_Error(ABORT_EVENT, TermNil, "");
|
|
||||||
LOCAL_ErrorMessage = "Abort";
|
|
||||||
return console_post_process_eof(s);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOCAL_PrologMode &= ~ConsoleGetcMode;
|
|
||||||
LOCAL_newline = true;
|
LOCAL_newline = true;
|
||||||
}
|
}
|
||||||
strncpy(LOCAL_Prompt, RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT);
|
strncpy(LOCAL_Prompt, RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT);
|
||||||
@ -437,7 +439,6 @@ int Yap_ReadlineForSIGINT(void) {
|
|||||||
int ch;
|
int ch;
|
||||||
StreamDesc *s = &GLOBAL_Stream[StdInStream];
|
StreamDesc *s = &GLOBAL_Stream[StdInStream];
|
||||||
const unsigned char *myrl_line = s->u.irl.buf;
|
const unsigned char *myrl_line = s->u.irl.buf;
|
||||||
|
|
||||||
if ((LOCAL_PrologMode & ConsoleGetcMode) && myrl_line != NULL) {
|
if ((LOCAL_PrologMode & ConsoleGetcMode) && myrl_line != NULL) {
|
||||||
ch = myrl_line[0];
|
ch = myrl_line[0];
|
||||||
free((void *)myrl_line);
|
free((void *)myrl_line);
|
||||||
|
6
os/sig.c
6
os/sig.c
@ -317,8 +317,10 @@ static bool set_fpu_exceptions(Term flag) {
|
|||||||
static void ReceiveSignal(int s, void *x, void *y) {
|
static void ReceiveSignal(int s, void *x, void *y) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_PrologMode |= InterruptMode;
|
LOCAL_PrologMode |= InterruptMode;
|
||||||
printf("11ooo\n");
|
if (s == SIGINT && (LOCAL_PrologMode & ConsoleGetcMode)) {
|
||||||
my_signal(s, ReceiveSignal);
|
return;
|
||||||
|
}
|
||||||
|
my_signal(s, ReceiveSignal);
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
// always direct SIGINT to console
|
// always direct SIGINT to console
|
||||||
|
Reference in New Issue
Block a user