• Incompatible stubs mechanism - Tcl 9

    From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Sun Nov 16 14:00:36 2025
    From Newsgroup: comp.lang.tcl


    Hello,

    I am experimenting with a compiled package for Tcl 9 (9.0.1 to be more precise) and I get an error message:

    interpreter uses an incompatible stubs mechanism
    while executing
    "load ftcl.dll Ftcl"
    (file "runpkg.tcl" line 4)

    The call that causes this is Tcl_InitStubs( interp, "9.0", 0)

    I have no idea what may be wrong, so any suggestions are appreciated.
    (Note: the same code with a different import library of course works fine with Tcl 8.6)

    Regards,

    Arjen
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Christian Gollwitzer@auriocus@gmx.de to comp.lang.tcl on Sun Nov 16 17:21:01 2025
    From Newsgroup: comp.lang.tcl

    Am 16.11.25 um 15:00 schrieb Arjen:
    interpreter uses an incompatible stubs mechanism
    https://core.tcl-lang.org/tcl/tktview/6f22c7a1fc
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Mon Nov 17 07:31:08 2025
    From Newsgroup: comp.lang.tcl


    Christian Gollwitzer <auriocus@gmx.de> posted:

    Am 16.11.25 um 15:00 schrieb Arjen:
    interpreter uses an incompatible stubs mechanism
    https://core.tcl-lang.org/tcl/tktview/6f22c7a1fc

    Thanks, though I am not sure that applies in my case, as the code of my extension is Fortran-only ;) and therefore has nothing to do with a stray tcl.h file. Perhaps somehow the run-time library?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Mon Nov 17 12:04:49 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Hello,

    I am experimenting with a compiled package for Tcl 9 (9.0.1 to be more precise)
    and I get an error message:

    interpreter uses an incompatible stubs mechanism
    while executing
    "load ftcl.dll Ftcl"
    (file "runpkg.tcl" line 4)

    The call that causes this is Tcl_InitStubs( interp, "9.0", 0)

    I have no idea what may be wrong, so any suggestions are appreciated.
    (Note: the same code with a different import library of course works fine with
    Tcl 8.6)

    Regards,

    Arjen

    I overlooked the interface for the actual Tcl_InitStubs() function (there is an extra argument there). But a C version is not behaving correctly either. I will have to investigate this further.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Mon Nov 17 14:14:43 2025
    From Newsgroup: comp.lang.tcl

    Am 17.11.2025 um 13:04 schrieb Arjen:

    Arjen <user153@newsgrouper.org.invalid> posted:


    Hello,

    I am experimenting with a compiled package for Tcl 9 (9.0.1 to be more precise)
    and I get an error message:

    interpreter uses an incompatible stubs mechanism
    while executing
    "load ftcl.dll Ftcl"
    (file "runpkg.tcl" line 4)

    The call that causes this is Tcl_InitStubs( interp, "9.0", 0)

    I have no idea what may be wrong, so any suggestions are appreciated.
    (Note: the same code with a different import library of course works fine with
    Tcl 8.6)

    Regards,

    Arjen

    I overlooked the interface for the actual Tcl_InitStubs() function (there is an
    extra argument there). But a C version is not behaving correctly either. I will
    have to investigate this further.

    Yes, ping magic Jan, probably living next to you ;-).
    There was a lot magic for tcl8.7 which is obsolate now.
    And double compile tcl8.6/9.0 may also happen without knowing it...
    Great features with pitfalls...

    Take care,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Mon Nov 17 15:25:19 2025
    From Newsgroup: comp.lang.tcl


    Harald Oehlmann <wortkarg3@yahoo.com> posted:

    Am 17.11.2025 um 13:04 schrieb Arjen:

    Arjen <user153@newsgrouper.org.invalid> posted:


    Hello,

    I am experimenting with a compiled package for Tcl 9 (9.0.1 to be more precise)
    and I get an error message:

    interpreter uses an incompatible stubs mechanism
    while executing
    "load ftcl.dll Ftcl"
    (file "runpkg.tcl" line 4)

    The call that causes this is Tcl_InitStubs( interp, "9.0", 0)

    I have no idea what may be wrong, so any suggestions are appreciated.
    (Note: the same code with a different import library of course works fine with
    Tcl 8.6)

    Regards,

    Arjen

    I overlooked the interface for the actual Tcl_InitStubs() function (there is an
    extra argument there). But a C version is not behaving correctly either. I will
    have to investigate this further.

    Yes, ping magic Jan, probably living next to you ;-).
    There was a lot magic for tcl8.7 which is obsolate now.
    And double compile tcl8.6/9.0 may also happen without knowing it...
    Great features with pitfalls...

    Take care,
    Harald

    Good suggestion, though he lives on the other side of the country.
    Still, it is the same timezone :).

    Regards,

    Arjen
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Mon Nov 17 20:25:52 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Hello,

    I am experimenting with a compiled package for Tcl 9 (9.0.1 to be more precise)
    and I get an error message:

    interpreter uses an incompatible stubs mechanism
    while executing
    "load ftcl.dll Ftcl"
    (file "runpkg.tcl" line 4)

    The call that causes this is Tcl_InitStubs( interp, "9.0", 0)

    I have no idea what may be wrong, so any suggestions are appreciated.
    (Note: the same code with a different import library of course works fine with
    Tcl 8.6)

    Regards,

    Arjen

    Hm, I just built Tcl 9.1a1 from source and tried again. Now it worked (at least
    the simple C version). I have to figure out what the magic number is, since
    on the Fortran side I will have to pass the extra argument directly, but it
    is a start.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Tue Nov 18 07:42:29 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Hm, I just built Tcl 9.1a1 from source and tried again. Now it worked (at least
    the simple C version). I have to figure out what the magic number is, since on the Fortran side I will have to pass the extra argument directly, but it is a start.

    Partial success: I printed the value of TCL_STUB_MAGIC as seen by the
    C extension and inserted that as the last argument in the Fortran version. Now the error message is that the extension is built for 8.6 (while I clearly
    used Tcl 9.1a1) ... Anyway, some progress.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Tue Nov 18 15:56:45 2025
    From Newsgroup: comp.lang.tcl

    * Arjen <user153@newsgrouper.org.invalid>
    | Arjen <user153@newsgrouper.org.invalid> posted:
    | > Hm, I just built Tcl 9.1a1 from source and tried again. Now it worked (at least
    | > the simple C version). I have to figure out what the magic number is, since | > on the Fortran side I will have to pass the extra argument directly, but it
    | > is a start.

    | Partial success: I printed the value of TCL_STUB_MAGIC as seen by the
    | C extension and inserted that as the last argument in the Fortran version. Now
    | the error message is that the extension is built for 8.6 (while I clearly
    | used Tcl 9.1a1) ... Anyway, some progress.

    Could that be a byte-ordering problem? I seem to remember that we had
    to byte-swap values when intermixing FORTRAN and C (but this was 30
    years ago, so bear with me :-)

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Wed Nov 19 07:35:52 2025
    From Newsgroup: comp.lang.tcl


    Ralf Fassel <ralfixx@gmx.de> posted:



    Could that be a byte-ordering problem? I seem to remember that we had
    to byte-swap values when intermixing FORTRAN and C (but this was 30
    years ago, so bear with me :-)

    R'

    More probable: swap array indices - Fortran uses column-major and C uses row-major to address elements in a multidimensional array. And then of course the start of the indices at 1 or 0.

    Right now, my understanding of the C code fails with the bit operations
    in place ... ;).
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Wed Nov 19 12:29:16 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Ralf Fassel <ralfixx@gmx.de> posted:



    Could that be a byte-ordering problem? I seem to remember that we had
    to byte-swap values when intermixing FORTRAN and C (but this was 30
    years ago, so bear with me :-)

    R'

    More probable: swap array indices - Fortran uses column-major and C uses row-major to address elements in a multidimensional array. And then of course the start of the indices at 1 or 0.

    Right now, my understanding of the C code fails with the bit operations
    in place ... ;).

    Got it! The problem was of course in a different place than where I was looking.
    In the C code the function Tcl_InitStubs() is called via a macro and that manipulates the "exact" argument. My Fortran code was simply assuming the correct
    value for "exact" was a logical (or Boolean if you insist) value 0 or 1.
    The correct value to pass incorporates the major and minor version of Tcl and ends up in my case to be 67840. I could have guessed.

    Regards,

    Arjen
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Wed Nov 19 12:32:41 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Got it! The problem was of course in a different place than where I was looking.
    In the C code the function Tcl_InitStubs() is called via a macro and that manipulates the "exact" argument. My Fortran code was simply assuming the correct
    value for "exact" was a logical (or Boolean if you insist) value 0 or 1.
    The correct value to pass incorporates the major and minor version of Tcl and
    ends up in my case to be 67840. I could have guessed.


    Now I have to adjust my code to make the command actually work.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Wed Nov 19 16:18:14 2025
    From Newsgroup: comp.lang.tcl

    <slap on forehead> Ah, TCL 9. I was wondering, since TCL-8 just has
    if (exact)
    in the stubs code.

    * Arjen <user153@newsgrouper.org.invalid>
    | Got it! The problem was of course in a different place than where I was looking.
    | In the C code the function Tcl_InitStubs() is called via a macro and that
    | manipulates the "exact" argument.

    TCL 9 massages the passed-in value in tcl.h and adds some high-order
    bits - this is what you need to do when calling Tcl_InitStubs from 'outside'.

    # define Tcl_InitStubs(interp, version, exact) \
    (Tcl_InitStubs)(interp, version, \
    (exact)|(TCL_MAJOR_VERSION<<8)|(TCL_MINOR_VERSION<<16), \
    TCL_STUB_MAGIC)

    (or a derivate of it)

    | My Fortran code was simply assuming the correct value for "exact" was
    | a logical (or Boolean if you insist) value 0 or 1. The correct value
    | to pass incorporates the major and minor version of Tcl and ends up in
    | my case to be 67840. I could have guessed.

    Note that the final value of 'exact' needs to have the 1-bit set for
    "exact match required" (code tests for exact&1) , where tcl-8 accepted
    anything != 0.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Thu Nov 20 14:11:57 2025
    From Newsgroup: comp.lang.tcl


    Arjen <user153@newsgrouper.org.invalid> posted:


    Arjen <user153@newsgrouper.org.invalid> posted:


    Got it! The problem was of course in a different place than where I was looking.
    In the C code the function Tcl_InitStubs() is called via a macro and that manipulates the "exact" argument. My Fortran code was simply assuming the correct
    value for "exact" was a logical (or Boolean if you insist) value 0 or 1. The correct value to pass incorporates the major and minor version of Tcl and
    ends up in my case to be 67840. I could have guessed.


    Now I have to adjust my code to make the command actually work.

    Well, that required a bit of work, indeed, due to the stubs table being different from Tcl 8.6, but it now works. It is just a proof of concept, but what I find attractive about it, is that involves no intermediate layer in C. The interfacing is purely in Fortran. I will probably not be able to do everything in
    Fortran, because of the use of C macros, but for now it is a nice proof of concept.

    Regards,

    Arjen
    --- Synchronet 3.21a-Linux NewsLink 1.2