make rl not deadlock under SIGINT

This commit is contained in:
Vítor Santos Costa 2011-03-01 12:31:19 +00:00
parent 73541f506f
commit b868d85ac8
9 changed files with 22 additions and 20 deletions

View File

@ -517,6 +517,7 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
error_exit_yap (1); error_exit_yap (1);
} }
case PURE_ABORT: case PURE_ABORT:
nt[0] = MkAtomTerm(AtomDAbort);
fun = FunctorVar; fun = FunctorVar;
serious = TRUE; serious = TRUE;
break; break;

View File

@ -1547,6 +1547,8 @@ InteractSIGINT(int ch) {
switch (ch) { switch (ch) {
case 'a': case 'a':
/* abort computation */ /* abort computation */
if (Yap_PrologMode &= InReadlineMode) {
}
if (Yap_PrologMode & (GCMode|ConsoleGetcMode|GrowStackMode|GrowHeapMode)) { if (Yap_PrologMode & (GCMode|ConsoleGetcMode|GrowStackMode|GrowHeapMode)) {
Yap_PrologMode |= AbortMode; Yap_PrologMode |= AbortMode;
} else { } else {
@ -1650,33 +1652,19 @@ HandleSIGINT (int sig, siginfo_t *x, ucontext_t *y)
HandleSIGINT (int sig) HandleSIGINT (int sig)
#endif #endif
{ {
LOCK(SignalLock);
my_signal(SIGINT, HandleSIGINT); my_signal(SIGINT, HandleSIGINT);
/* do this before we act */ /* do this before we act */
#if HAVE_ISATTY #if HAVE_ISATTY
if (!isatty(0) && !Yap_sockets_io) { if (!isatty(0) && !Yap_sockets_io) {
UNLOCK(SignalLock);
Yap_Error(INTERRUPT_ERROR,MkIntTerm(SIGINT),NULL); Yap_Error(INTERRUPT_ERROR,MkIntTerm(SIGINT),NULL);
return; return;
} }
#endif #endif
if (Yap_InterruptsDisabled) { if (Yap_InterruptsDisabled) {
UNLOCK(SignalLock);
return; return;
} }
if (Yap_PrologMode & (CritMode|ConsoleGetcMode)) { if (Yap_PrologMode & (CritMode|ConsoleGetcMode)) {
Yap_PrologMode |= InterruptMode; Yap_PrologMode |= InterruptMode;
#if HAVE_LIBREADLINE && HAVE_READLINE_READLINE_H
if (Yap_PrologMode & ConsoleGetcMode) {
fprintf(stderr, "Action (h for help): ");
rl_point = rl_end = 0;
#if HAVE_RL_SET_PROMPT
rl_set_prompt("Action (h for help): ");
#endif
}
#endif
UNLOCK(SignalLock);
return;
} }
#ifdef HAVE_SETBUF #ifdef HAVE_SETBUF
/* make sure we are not waiting for the end of line */ /* make sure we are not waiting for the end of line */
@ -1684,11 +1672,9 @@ HandleSIGINT (int sig)
#endif #endif
if (snoozing) { if (snoozing) {
snoozing = FALSE; snoozing = FALSE;
UNLOCK(SignalLock);
return; return;
} }
ProcessSIGINT(); ProcessSIGINT();
UNLOCK(SignalLock);
} }
#endif #endif

View File

@ -1184,7 +1184,8 @@ typedef enum
UserCCallMode = 0x4000, /* In User C-call Code */ UserCCallMode = 0x4000, /* In User C-call Code */
MallocMode = 0x8000, /* Doing malloc, realloc, free */ MallocMode = 0x8000, /* Doing malloc, realloc, free */
SystemMode = 0x10000, /* in system mode */ SystemMode = 0x10000, /* in system mode */
AsyncIntMode = 0x20000 /* YAP has just been interrupted from the outside */ AsyncIntMode = 0x20000, /* YAP has just been interrupted from the outside */
InReadlineMode = 0x40000 /* YAP has just been interrupted from the outside */
} prolog_exec_mode; } prolog_exec_mode;
extern Int Yap_PrologMode; extern Int Yap_PrologMode;

View File

@ -825,7 +825,7 @@ clean: clean_docs
@INSTALL_DLLS@ (cd packages/semweb; $(MAKE) clean) @INSTALL_DLLS@ (cd packages/semweb; $(MAKE) clean)
@INSTALL_DLLS@ (cd packages/sgml; $(MAKE) clean) @INSTALL_DLLS@ (cd packages/sgml; $(MAKE) clean)
@USE_MINISAT@ (cd packages/swi-minisat2; $(MAKE) clean) @USE_MINISAT@ (cd packages/swi-minisat2; $(MAKE) clean)
@USE_MINISAT@ (cd packages/packages/CLPBN/bp; $(MAKE) clean) @USE_MINISAT@ (cd packages/CLPBN/clpbn/bp; $(MAKE) clean)
@INSTALL_DLLS@ (cd packages/tai; $(MAKE) clean) @INSTALL_DLLS@ (cd packages/tai; $(MAKE) clean)
@INSTALL_DLLS@ (cd packages/zlib; $(MAKE) clean) @INSTALL_DLLS@ (cd packages/zlib; $(MAKE) clean)
@ENABLE_CPLINT@ (cd packages/cplint/approx/simplecuddLPADs; $(MAKE) clean) @ENABLE_CPLINT@ (cd packages/cplint/approx/simplecuddLPADs; $(MAKE) clean)

View File

@ -232,6 +232,7 @@
#undef HAVE_RL_CLEAR_PENDING_INPUT #undef HAVE_RL_CLEAR_PENDING_INPUT
#undef HAVE_RL_COMPLETION_MATCHES #undef HAVE_RL_COMPLETION_MATCHES
#undef HAVE_RL_FILENAME_COMPLETION_FUNCTION #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION
#undef HAVE_RL_FREE_LINE_STATE
#undef HAVE_RL_INSERT_CLOSE #undef HAVE_RL_INSERT_CLOSE
#undef HAVE_RL_SET_PROMPT #undef HAVE_RL_SET_PROMPT
#undef HAVE_SBRK #undef HAVE_SBRK

5
configure vendored
View File

@ -7988,6 +7988,11 @@ fi
ac_fn_c_check_func "$LINENO" "rl_filename_completion_function " "ac_cv_func_rl_filename_completion_function_" ac_fn_c_check_func "$LINENO" "rl_filename_completion_function " "ac_cv_func_rl_filename_completion_function_"
if test "x$ac_cv_func_rl_filename_completion_function_" = x""yes; then : if test "x$ac_cv_func_rl_filename_completion_function_" = x""yes; then :
fi
ac_fn_c_check_func "$LINENO" "rl_free_line_state " "ac_cv_func_rl_free_line_state_"
if test "x$ac_cv_func_rl_free_line_state_" = x""yes; then :
fi fi
ac_fn_c_check_func "$LINENO" "rl_set_prompt " "ac_cv_func_rl_set_prompt_" ac_fn_c_check_func "$LINENO" "rl_set_prompt " "ac_cv_func_rl_set_prompt_"

View File

@ -1383,6 +1383,7 @@ then
AC_CHECK_FUNC( rl_completion_matches ) AC_CHECK_FUNC( rl_completion_matches )
AC_CHECK_FUNC( rl_insert_close ) AC_CHECK_FUNC( rl_insert_close )
AC_CHECK_FUNC( rl_filename_completion_function ) AC_CHECK_FUNC( rl_filename_completion_function )
AC_CHECK_FUNC( rl_free_line_state )
AC_CHECK_FUNC( rl_set_prompt ) AC_CHECK_FUNC( rl_set_prompt )
AC_CHECK_FUNC( rl_clear_pending_input ) AC_CHECK_FUNC( rl_clear_pending_input )
fi fi

View File

@ -482,8 +482,9 @@ Sread_readline(void *handle, char *buf, size_t size)
rl_prep_terminal(FALSE); rl_prep_terminal(FALSE);
rl_readline_state = state; rl_readline_state = state;
rl_done = 0; rl_done = 0;
} else } else {
line = pl_readline(prompt); line = pl_readline(prompt);
}
in_readline--; in_readline--;
if ( my_prompt ) if ( my_prompt )
@ -513,6 +514,12 @@ Sread_readline(void *handle, char *buf, size_t size)
PL_clock_wait_ticks(clock() - oldclock); PL_clock_wait_ticks(clock() - oldclock);
#endif #endif
#if __YAP_PROLOG__
/* handle abort */
if (Yap_REGS.P_ == FAILCODE) {
return 0;
}
#endif
return rval; return rval;
} }

View File

@ -20,7 +20,7 @@ YAPLIBDIR=@libdir@/Yap
# #
DEFS=@DEFS@ -D_YAP_NOT_INSTALLED_=1 DEFS=@DEFS@ -D_YAP_NOT_INSTALLED_=1
CC=@CC@ CC=@CC@
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/../PLStream CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/../PLStream -I$(srcdir)/../../H
# #
# #
# You shouldn't need to change what follows. # You shouldn't need to change what follows.