Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: d66b0d964355e33fc7ffe9eaa44e660786f0dfb9f3a698e4231d29329a5139e7
Ticket: 5c3679820afa2aca58ef3bb2041181669fab5ac7
64-Bit Extensions Do Not Work With Old Tcl Applications
User & Date: jan.nijtmans on 2025-03-03 15:00:43
Changes

  1. icomment:
    > Is it really correct that only the 64 bit applications (version 8 and 9) are binary incompatible and the 32 bit applications remain binary compatible?
    
    First question: Yes! For example, try:
    <pre>
    Tcl_Obj *obj = Tcl_NewStringObj("hello", -1);
    printf(obj->bytes);
    </pre>
    If you do this in a 64-bit Tcl-8.6-compiled extension, running in Tcl 9.0. the second argument of Tcl_NewStringObj() is a "int", so the value 0xFFFFFFFF (4 bytes) will be pushed on stack. Tcl9.0 will pull 8 bytes off the stack, which will be 4 0xFF bytes followed by 4 bytes of random data. That will crash, unless .... modern compilers don't use the stack for such function parameters but internal registers. That will work. Phew, you are lucky. Then, the obj->bytes field is just after the obj->refCount field, which is 4 bytes in Tcl 8.6 and 8 bytes in Tcl 9.0. Since most compilers align the obj->bytes fields on a multiple of 8 bytes, you are lucky again: it will work. But - you see - you cannot depend on that. More complicated examples will certainly crash. You will be on your own trying that, that's why the magic value was changed.
    
    On 32-bit machines, it will be almost binary compatible. There are 2 things you cannot do:
    * Call any of the deprecated functions, like Tcl_MakeSafe(). They only work in Tcl 8.6
    * Call any of the internal functions (in tclIntDecls.h), they moved to different stub entries
    Since there is no way to know if an already-compiled extension voilates that, I don't recommend running a Tcl 8.6 extension in Tcl 9.0 or reverse. If it works, you are lucky. Better recompile it in a Tcl 9.0 environment, then the compiler should complain if there is a problem.
    
  2. login: "jan.nijtmans"
  3. mimetype: "text/x-fossil-wiki"