changeset 16404:24e755668237

remove special sigint handling for Windows systems * sighandlers.cc (sigint_handler, (octave_catch_interrupts): Delete special case for Windows. (w32_sigint_handler): Delete function. * sysdep.cc (MINGW_signal_cleanup): Don't call w32_raise_final. (MINGW_initMSVC_init): Don't call w32_sigint_init or w32_set_quiet_shutdown. * sysdep.h: Don't define USE_W32_SIGINT. * cquit.c (PRINT_CURRENT_THREAD, DEBUGs, DEBUGd): Delete macros. (w32_thread_setjmp_mutex, w32_signal_context, w32_signal_to_raise, w32_main_thread_id, w32_main_thread, w32_restore_thread): Delete global and static variables. (w32_in_main_thread, w32_reset_context, w32_raise_in_main, w32_raise_final, w32_raise, w32_sigint_init): Delete functions.
author John W. Eaton <jwe@octave.org>
date Sun, 31 Mar 2013 23:49:50 -0400
parents 1de4ec2a856d
children eeedbc7c0740
files libinterp/interpfcn/sighandlers.cc libinterp/interpfcn/sysdep.cc libinterp/interpfcn/sysdep.h liboctave/cruft/misc/cquit.c
diffstat 4 files changed, 0 insertions(+), 262 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/sighandlers.cc	Sun Mar 31 19:19:04 2013 -0400
+++ b/libinterp/interpfcn/sighandlers.cc	Sun Mar 31 23:49:50 2013 -0400
@@ -378,14 +378,7 @@
 static void
 sigint_handler (int sig)
 {
-#ifdef USE_W32_SIGINT
-  if (w32_in_main_thread ())
-    user_abort (strsignal (sig), sig);
-  else
-    w32_raise (sig);
-#else
   user_abort (strsignal (sig), sig);
-#endif
 }
 
 #ifdef SIGPIPE
@@ -403,62 +396,6 @@
 }
 #endif /* defined (SIGPIPE) */
 
-#ifdef USE_W32_SIGINT
-static BOOL CALLBACK
-w32_sigint_handler (DWORD sig)
-{
-  const char *sig_name;
-
-  switch (sig)
-    {
-      case CTRL_BREAK_EVENT:
-        sig_name = "Ctrl-Break";
-        break;
-      case CTRL_C_EVENT:
-        sig_name = "Ctrl-C";
-        break;
-      case CTRL_CLOSE_EVENT:
-        sig_name = "close console";
-        break;
-      case CTRL_LOGOFF_EVENT:
-        sig_name = "logoff";
-        break;
-      case CTRL_SHUTDOWN_EVENT:
-        sig_name = "shutdown";
-        break;
-      default:
-        sig_name = "unknown console event";
-        break;
-    }
-
-  switch (sig)
-    {
-      case CTRL_BREAK_EVENT:
-      case CTRL_C_EVENT:
-        w32_raise (SIGINT);
-        break;
-
-      case CTRL_CLOSE_EVENT:
-        clean_up_and_exit (0);
-        break;
-      case CTRL_LOGOFF_EVENT:
-      case CTRL_SHUTDOWN_EVENT:
-      default:
-        // We should do the following:
-        //    clean_up_and_exit (0);
-        // We can't because we aren't running in the normal Octave thread.
-        user_abort (sig_name, sig);
-        break;
-    }
-
-  // Return TRUE if the event was handled, or FALSE if another handler
-  // should be called.
-  // FIXME check that windows terminates the thread.
-  return TRUE;
-}
-#endif /* w32_sigint_handler */
-
-
 octave_interrupt_handler
 octave_catch_interrupts (void)
 {
@@ -472,22 +409,6 @@
   retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler);
 #endif
 
-#ifdef USE_W32_SIGINT
-
-  // Intercept windows console control events.
-  // Note that the windows console signal handlers chain, so if
-  // install_signal_handlers is called more than once in the same program,
-  // then first call the following to avoid duplicates:
-  //
-  //   SetConsoleCtrlHandler (w32_sigint_handler, FALSE);
-
-  if (! SetConsoleCtrlHandler (w32_sigint_handler, TRUE))
-    error ("SetConsoleCtrlHandler failed with %ld\n", GetLastError ());
-
-  w32_set_quiet_shutdown ();
-
-#endif
-
   return retval;
 }
 
--- a/libinterp/interpfcn/sysdep.cc	Sun Mar 31 19:19:04 2013 -0400
+++ b/libinterp/interpfcn/sysdep.cc	Sun Mar 31 23:49:50 2013 -0400
@@ -167,8 +167,6 @@
 MINGW_signal_cleanup (void)
 {
   w32_set_quiet_shutdown ();
-
-  w32_raise_final ();
 }
 #endif
 
@@ -177,11 +175,6 @@
 MINGW_init (void)
 {
   w32_set_octave_home ();
-
-  // Init mutex to protect setjmp/longjmp and get main thread context
-  w32_sigint_init ();
-
-  w32_set_quiet_shutdown ();
 }
 #endif
 
@@ -190,11 +183,6 @@
 MSVC_init (void)
 {
   w32_set_octave_home ();
-
-  // Init mutex to protect setjmp/longjmp and get main thread context
-  w32_sigint_init ();
-
-  w32_set_quiet_shutdown ();
 }
 #endif
 
--- a/libinterp/interpfcn/sysdep.h	Sun Mar 31 19:19:04 2013 -0400
+++ b/libinterp/interpfcn/sysdep.h	Sun Mar 31 23:49:50 2013 -0400
@@ -47,7 +47,6 @@
 
 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
 extern void MINGW_signal_cleanup (void);
-#define USE_W32_SIGINT 1
 #define MINGW_SIGNAL_CLEANUP() MINGW_signal_cleanup ()
 #else
 #define MINGW_SIGNAL_CLEANUP() do { } while (0)
--- a/liboctave/cruft/misc/cquit.c	Sun Mar 31 19:19:04 2013 -0400
+++ b/liboctave/cruft/misc/cquit.c	Sun Mar 31 23:49:50 2013 -0400
@@ -43,176 +43,6 @@
   memcpy (current_context, save_buf, sizeof (octave_jmp_buf));
 }
 
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-
-/* FIXME -- eventually remove the debugging */
-#if defined (DEBUG)
-
-#define PRINT_CURRENT_THREAD() printf ("%lx: ", GetCurrentThreadId ())
-
-#define DEBUGs(s) \
-  do \
-    { \
-      PRINT_CURRENT_THREAD (); \
-      printf (s "\n"); \
-      fflush (stdout); \
-    } \
-  while (0)
-
-#define DEBUGd(s, d) \
-  do \
-    { \
-      PRINT_CURRENT_THREAD (); \
-      printf (s "\n", d); \
-      fflush (stdout); \
-    } \
-  while (0)
-
-#else
-#define DEBUGs(s)
-#define DEBUGd(s, d)
-#endif
-
-CRITICAL_SECTION w32_thread_setjmp_mutex;
-static CONTEXT w32_signal_context;
-static int w32_signal_to_raise = 0;
-static DWORD w32_main_thread_id;
-static HANDLE w32_main_thread;
-static HANDLE w32_restore_thread = NULL;
-
-int
-w32_in_main_thread(void)
-{
-  return (GetCurrentThreadId () == w32_main_thread_id);
-}
-
-static DWORD WINAPI
-w32_reset_context (LPVOID v)
-{
-  PCONTEXT context = (PCONTEXT)v;
-  int ret;
-
-  /* Mutex the setjmp/longjmp */
-  EnterCriticalSection (&w32_thread_setjmp_mutex);
-
-  DEBUGs ("enter w32_set_context");
-  SuspendThread (w32_main_thread);
-  DEBUGs ("main suspended");
-  if (! SetThreadContext (w32_main_thread, context))
-    {
-      fprintf (stderr, "%lx: context failed: ctrl-c won't work\n",
-               GetCurrentThreadId ());
-      fflush (stderr);
-    }
-  DEBUGs ("context captured (or not)");
-  ret = ResumeThread (w32_main_thread);
-  DEBUGd ("main resumed with %d", ret);
-
-  LeaveCriticalSection (&w32_thread_setjmp_mutex);
-  return 0;
-}
-
-static void
-w32_raise_in_main (void)
-{
-  DWORD threadid;
-
-  DEBUGd ("w32_raise_in_main with signal %d", w32_signal_to_raise);
-  raise (w32_signal_to_raise);
-  DEBUGd ("w32_raise_in_main signal %d returned a value",
-          w32_signal_to_raise);
-
-  DEBUGs ("attempting to restore main to pre-signal configuration");
-  if (w32_restore_thread != NULL) /* Catch leaky threads */
-    CloseHandle (w32_restore_thread);
-  w32_restore_thread = CreateThread (NULL, 10000, w32_reset_context,
-                                     &w32_signal_context, 0, &threadid);
-  if (w32_restore_thread == NULL)
-    {
-      fprintf (stderr, "w32_raise_in_main couldn't create thread\n");
-      fflush (stderr);
-    }
-  else
-    {
-      DEBUGs ("waiting to restore raise context");
-      WaitForSingleObject (w32_restore_thread, INFINITE);
-      fprintf (stderr, "w32_raise_in_main couldn't restore context\n");
-      fflush (stderr);
-    }
-}
-
-void
-w32_raise_final (void)
-{
-  CloseHandle (w32_main_thread);
-  if (w32_restore_thread != NULL) /* Catch leaky threads */
-    CloseHandle (w32_restore_thread);
-  w32_main_thread = w32_restore_thread = NULL;
-}
-
-/* Raise the given signal in the main thread.  w32_raise_init ()
-   must have been called from the main thread already.  */
-void
-w32_raise (int sig)
-{
-  int ret;
-
-  if (w32_in_main_thread ())
-    {
-      /* Called from main thread -- a simple raise () should work.  */
-      DEBUGd ("raising signal %d within main", signal);
-      raise (sig);
-      DEBUGd ("returning from signal %d within main", signal);
-    }
-  else
-    {
-      /* Called from alternate thread -- call w32_raise_in_main in the
-         main thread with w32_signal_to_raise set to the signal */
-      CONTEXT raise_context;
-      DEBUGd ("raising signal %d from separate thread", signal);
-
-      /* Suspend main and remember the context.  */
-      SuspendThread (w32_main_thread);
-      /* X86 code */
-      w32_signal_context.ContextFlags
-        = CONTEXT_FULL|CONTEXT_FLOATING_POINT|CONTEXT_DEBUG_REGISTERS;
-      GetThreadContext (w32_main_thread, &w32_signal_context);
-
-      /* Change the context to w32_raise_in_main.  The
-         context.Eip=&fn trick for setting the program counter is
-         courtesy of
-
-           http://fit.c2.com/files/LispPlatform/lisp/clisp-2.28/src/win32aux.d
-
-         Auxiliary functions for CLISP on Win32, Bruno Haible
-         1997-1999.  */
-
-      memcpy (&raise_context, &w32_signal_context, sizeof (CONTEXT));
-      raise_context.Eip = (DWORD)&w32_raise_in_main; /* X86 code */
-      w32_signal_to_raise = sig;
-      SetThreadContext (w32_main_thread, &raise_context);
-
-      /* Resume main at w32_raise_in_main */
-      ret = ResumeThread (w32_main_thread);
-      DEBUGd ("main resumed at w32_raise_in_main with suspend count %d",
-              ret);
-    }
-}
-
-void
-w32_sigint_init (void)
-{
-  /* Capture main context */
-  w32_main_thread_id = GetCurrentThreadId ();
-  DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
-                   GetCurrentProcess (), &w32_main_thread,
-                   0, FALSE, DUPLICATE_SAME_ACCESS);
-
-  InitializeCriticalSectionAndSpinCount (&w32_thread_setjmp_mutex, 0);
-}
-
-#endif /* #if defined (__WIN32__) && ! defined (_POSIX_VERSION) */
-
 void
 octave_jump_to_enclosing_context (void)
 {