Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 28bc23b340333c7daf38afffbded8c4b185fea57
Ticket: 218145ffffffffffffffffffffffffffffffffff
conflict between Stubs and C++ dlls with global constructors
User & Date: nobody on 2000-10-26 00:53:44
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 2119 Bug
    Version: 8.1
    SubmitDate: '1999-05-21'
    LastModified: '1999-05-26'
    Severity: CRIT
    Status: Closed
    Submitter: pat
    ChangedBy: redman
    OS: Windows NT
    OSVersion: 4.0sp3
    Machine: X86
    FixedDate: '2000-10-25'
    FixedInVersion: NA
    ClosedDate: '1999-05-26'
    
    
    Name:
    vince darley
    
    ReproducibleScript:
    Consider a C++ dll with some global constructors (i.e. constructors
        which
        are automagically called when the .dll is loaded, before the <Pkg>_Init
        function is called).  Now if those global constructors actually call
        Tcl, for instance if a 'cpp_mem' constuctor like the following is
        called:
        
        cpp_mem(const char* n=0) {
        if(n) {
        _name = Tcl_NewStringObj((char*)n,-1);
        Tcl_IncrRefCount(_name);
        }
        }
        
        Now this works fine without stubs, since we can call Tcl_NewStringObj
        etc without knowing the Tcl interpreter which is going to be used.
        However, with stubs, since we haven't yet called 'Tcl_InitStubs',
        Tcl_NewStringObj is obviously going to give an access violation.  This
        means the .dll fails to load, and the Tcl 'load' command returns the
        error message "invalid argument".
        
        The solution to this is to (i) avoid calling Tcl before the .dll is
        loaded (which is backwards incompatible, and removes what I find to be a
        useful feature), or (ii) call Tcl_InitStubs earlier.
        
        I view (i) as unacceptable, so let's try (ii): most platforms provide a
        (compiler/platform dependent) Dll-init function which will be called
        before the global constructors are, so we can call Tcl_InitStubs from
        that (on windows it's defined as 'BOOL APIENTRY DllEntryPoint(HINSTANCE
        hInst, DWORD reason, LPVOID reserved)', and must be defined by every
        dll).  Unfortunately, we can't call Tcl_InitStubs correctly from that
        function, because we don't know the interpreter yet!  If we try to call
        'Tcl_InitStubs' with a null interpreter, it just returns an error, since
        it needs to get a valid interpreter from which to extract the stubs ptr.
         I'm not sure what the best solution is!  There ought to be some way to
        get at the 'default' stubs table if such a thing exists.
        
        Unless this can be solved, my C++ extensions (Cpptcl, Plcpp,
        Cppmatrix..) cannot use Stubs...
    
    
    
    This is correct behavior.  Option (i) in his report is the only reasonable thing to do.
    
    -- 05/26/1999 redman
    
    
    
  4. foundin changed to: "obsolete: 8.1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to:
    conflict between Stubs and C++ dlls with global constructors
    
  11. type changed to: "Bug"