Tk Source Code

View Ticket
Login
Ticket UUID: 219996
Title: Tcl_Exit() before Tk_Init() --> CRASH!
Type: Bug Version: final: 8.1.1
Submitter: welch Created on: 2000-10-31 21:58:16
Subsystem: 68. Win Window Operations Assigned To: nobody
Priority: 1 Zero Severity:
Status: Closed Last Modified: 2001-04-27 12:15:12
Resolution: Duplicate Closed By: dgp
    Closed on: 2001-04-27 05:15:12
Description:
OriginalBugID: 2247 Bug
Version: 8.1.1
SubmitDate: '1999-06-16'
LastModified: '1999-06-29'
Severity: CRIT
Status: Closed
Submitter: techsupp
ChangedBy: redman
RelatedBugIDs: 2269
OS: Windows 95
Machine: X86
ClosedDate: '1999-06-29'


Name:
Don Porter

Comments:
I still want to be able to build "big shells" using Tcl/Tk 8.1.x.
    
    Based on a very inadequate understanding of Tcl stubs tables, here's
    my guess at what is wrong.  I need the help of a stubs expert to help
    work around this problem.
    
    When "demo" calls Tcl_Exit, the program has not yet called Tk_Init(),
    so the Tk DLL has not yet called Tcl_InitStubs, and the Tk DLL cannot
    yet call any Tcl_* routines without crashing.
    
    However, Tcl_Exit()  calls exit() which calls routines to unload
    and cleanup after the Tk DLL.  This includes TkWinWmCleanup which
    tries to call Tcl_GetThreadData.  OOPS!  CRASH!
    
    This problem is holding back our release of an 8.1.x-compatible product.
    Any help finding a workaround is greatly appreciated.

ReproducibleScript:
/* FILE: demo.c */
    #include <tcl.h>
    #include <tk.h>
    
    int main(int argc, char *argv[])
    {
      Tcl_Interp *interp;
    
      Tcl_FindExecutable(argv[0]);
      interp = Tcl_CreateInterp();
      Tcl_Init(interp);
      /*
       * It might seem unusual to call Tcl_Exit() at this point, but
       * it might happen in response to an error in Tcl_Init, or an
       * error in the Foo_Init for another extension, Foo, initialized
       * at this point in a "big shell".
       */
      Tcl_Exit(1);
      Tk_Init(interp);
      Tk_MainLoop();
      Tcl_DeleteInterp(interp);
      Tcl_Exit(0);
      return(0);
    }
    /* End FILE: demo.c */
    
    Compile and link demo.c on MS Windows 95 with MSVC++ 5.0:
    
    C:\> cl /c "/IC:\Program Files\Tcl\include" demo.c
    C:\> link demo.obj "C:\Program Files\Tcl\lib\tcl81.lib" "C:\Program
    Files\Tcl\lib\tk81.lib"

ObservedBehavior:
Run the executable "demo".  A dialog box pops up reporting:
    
    "This program has performed an illegal operation and will be shut down.
    
    If the program persists, contact the program vendor."

DesiredBehavior:
I want the "demo" program to exit clean, without fatal error messages.



See 2269, includes patch. 
-- 06/29/1999 redman