Tcl Source Code

Attachment Details
Login
Overview

Artifact ID: e0bf03860f793fac873ab2b35cea987aea00485f
Ticket: 219355ffffffffffffffffffffffffffffffffff
Date: 2002-09-29 07:50:26
User: davygrvy
Artifact Attached: 951fd7f0a1e306e6e53beef95ee728c6466bdb97
Filename:patch.txt
Description:suggested patch to tclAppInit.c to fix the problem
Content:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
*** win/tclAppInit.c	21 Feb 2002 21:20:08 -0000	1.8
--- win/tclAppInit.c	29 Sep 2002 00:43:00 -0000
***************
*** 29,34 ****
--- 29,39 ----
  #endif /* TCL_TEST */
  
  static void		setargv _ANSI_ARGS_((int *argcPtr, char ***argvPtr));
+ static BOOL __stdcall	sigHandler (DWORD fdwCtrlType);
+ static Tcl_AsyncProc	asyncExit;
+ 
+ Tcl_AsyncHandler	exitToken;
+ DWORD			exitErrorCode;
  
  
  /*
***************
*** 135,140 ****
--- 140,151 ----
  	return TCL_ERROR;
      }
  
+     /*
+      * Install a signal handler to the win32 console tclsh is running in.
+      */
+     SetConsoleCtrlHandler(sigHandler, TRUE); 
+     exitToken = Tcl_AsyncCreate(asyncExit, NULL); 
+ 
  #ifdef TCL_TEST
      if (Tcltest_Init(interp) == TCL_ERROR) {
  	return TCL_ERROR;
***************
*** 299,301 ****
--- 310,379 ----
      *argcPtr = argc;
      *argvPtr = argv;
  }
+ 
+ /*
+  *----------------------------------------------------------------------
+  *
+  * asyncExit --
+  *
+  * 	The AsyncProc for the exitToken.
+  *
+  * Results:
+  * 	doesn't actually return.
+  *
+  * Side effects:
+  * 	tclsh cleanly exits.
+  *
+  *----------------------------------------------------------------------
+  */
+ 
+ int
+ asyncExit (ClientData clientData, Tcl_Interp *interp, int code)
+ {
+     Tcl_Exit((int)exitErrorCode);
+ 
+     /* NOTREACHED */
+     return code;
+ }
+ 
+ /*
+  *----------------------------------------------------------------------
+  *
+  * sigHandler --
+  *
+  *	Signal handler for the Win32 OS. Catches Ctrl+C, Ctrl+Break and
+  *	other exits. This is needed so tclsh can do it's real clean-up
+  *	and not an unclean crash terminate.
+  *
+  * Results:
+  *	TRUE.
+  *
+  * Side effects:
+  *	Effects the way the app exits from a signal. This is an
+  *	operating system supplied thread and unsafe to call ANY
+  *	Tcl commands except for Tcl_AsyncMark.
+  *
+  *----------------------------------------------------------------------
+  */
+ 
+ BOOL __stdcall
+ sigHandler(DWORD fdwCtrlType)
+ {
+     /*
+      * If Tcl is currently executing some bytecode or in the eventloop,
+      * this will cause Tcl to enter asyncExit at the next command
+      * boundry.
+      */
+     exitErrorCode = fdwCtrlType;
+     Tcl_AsyncMark(exitToken);
+ 
+     /* 
+      * This will cause Tcl_Gets in Tcl_Main() to drop-out with an <EOF> 
+      * should it be blocked on input and our Tcl_AsyncMark didn't grab 
+      * the attention of the interpreter. 
+      */ 
+     /* CloseHandle(GetStdHandle(STD_INPUT_HANDLE)); */ 
+ 
+     /* indicate to the OS not to call the default terminator */ 
+     return TRUE; 
+ }