Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-01-30
13:15 • Ticket [70f3b23cad] Tcl_InitStubs: is the "-" in the version requireme... artifact: 1761c14c8b user: oehhar
2025-01-13
09:56 • Ticket [70f3b23cad]: 5 changes artifact: 2781e9247d user: jan.nijtmans
09:11 • Ticket [70f3b23cad]: 6 changes artifact: b1874f9610 user: oehhar
08:35 • Ticket [70f3b23cad]: 5 changes artifact: 9369d94098 user: jan.nijtmans
07:25 • Ticket [70f3b23cad]: 6 changes artifact: d892e9b835 user: oehhar
2025-01-12
18:15 • Closed ticket [70f3b23cad]. artifact: 8a594be2b6 user: jan.nijtmans
18:10
Fix [70f3b23cad]. Doc fix only check-in: 5d7aa913b0 user: jan.nijtmans tags: trunk, main
18:04
Fix [70f3b23cad]. Doc fix only check-in: e3fb9432f2 user: jan.nijtmans tags: core-8-branch
17:51
Fix [70f3b23cad]. Doc fix only check-in: 9ab8873b08 user: jan.nijtmans tags: core-8-6-branch
2025-01-10
19:57 • Ticket [70f3b23cad] Tcl_InitStubs: is the "-" in the version requireme... artifact: 48abc4dccc user: fvogel
14:06 • Ticket [70f3b23cad]: 3 changes artifact: 7169a15925 user: jan.nijtmans
2025-01-07
06:47 • Ticket [70f3b23cad]: 3 changes artifact: eae9891ce0 user: fvogel
03:05 • Ticket [70f3b23cad]: 3 changes artifact: baddd29b75 user: apnadkarni
2025-01-06
22:19 • Ticket [70f3b23cad]: 3 changes artifact: 09f4fe2d03 user: jan.nijtmans
21:27 • Ticket [70f3b23cad]: 4 changes artifact: c2982775a7 user: oehhar
21:24 • Ticket [70f3b23cad]: 3 changes artifact: 4a9572239c user: jan.nijtmans
18:21 • Ticket [70f3b23cad]: 4 changes artifact: 98c9f9e505 user: oehhar
2025-01-03
14:52 • Ticket [70f3b23cad]: 3 changes artifact: 5cc9296f87 user: jan.nijtmans
2024-12-20
10:21 • Ticket [70f3b23cad]: 4 changes artifact: c6b87da8fd user: oehhar
2024-12-16
11:51 • Ticket [70f3b23cad]: 4 changes artifact: 9961591c04 user: oehhar
11:50
Ticket [70f3b23cad]: propose new doc wording for requirement strings check-in: 607aea587f user: oehhar tags: 70f3b23cad-docs-version-requirement
2024-12-15
22:11 • Ticket [70f3b23cad] Tcl_InitStubs: is the "-" in the version requireme... artifact: 49ca7bb96f user: jan.nijtmans
18:28 • Ticket [70f3b23cad]: 3 changes artifact: 5f58a6f2ac user: fvogel
17:58 • Ticket [70f3b23cad]: 3 changes artifact: 197652ac66 user: oehhar
17:47 • Ticket [70f3b23cad]: 3 changes artifact: ad54581286 user: oehhar
17:46 • New ticket [70f3b23cad]. artifact: 062caa7aa8 user: oehhar

Tcl_InitStubs: is the "-" in the version requirement "8.5-" allowed?

Closed / Fixed70f3b23caddc1a1cf77a3f7ed7daa6f9f6405ee5Created 2 years agoUpdated 2 years ago
Descriptionwiki2024-12-15 17:46:31
The wiki page for extension migration https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9&p contains:
#ifdef USE_TCL_STUBS
    if (Tcl_InitStubs(interp, "8.5-", 0) == NULL)
#else
    if (Tcl_PkgRequire(interp, "Tcl", "8.5-", 0) == NULL)
#endif
    {
        return TCL_ERROR;
    }

This might be wrong in two senses:

  • The #ifdef is not required, as without defining USE_TCL_STUBS, "Tcl_InitStubs" works like "Tcl_PkgRequire"
  • Following the Tcl_InitStubs documentation, the "-" character is not allowed within the argument.

Also, the sample extension is related here.

Here is the TCL 8.6. description stating, that only numbers and dots are allowed: https://core.tcl-lang.org/tcl/file?name=doc/InitStubs.3&ci=84c07aaa29698bb8&ln=23-24 IMHO, the "PackageRequire" capability without "USE_TCL_STUBS" is also undocumented.

Here is the 9.0 (main) description which is identical: https://core.tcl-lang.org/tcl/file?udc=1&ln=on&ci=tip&name=doc%2FInitStubs.3

THanks to Francois to point-out this issue.

Referenced by4
oehhar Ticket [70f3b23cad]: 3 changes [History diff]2024-12-15 17:47:28
oehhar Ticket [70f3b23cad]: 3 changes [History diff]2024-12-15 17:58:58
fvogelplain2024-12-15 18:28:09
Regarding the dash "-" char: from a very quick look at the code it seems the actual version is obtained through tcl_PkgRequireEx, which *I think* calls Tcl_PkgRequireEx, which allows version numbers as documented for package require. So I think that it's probably the documentation that should be improved. But don't take this as certain since I didn't check sufficiently in depth.
jan.nijtmanswiki2024-12-15 22:11:25

The enhanced "package" syntax is described in TIP #268, and is available since Tcl 8.5.

Apparently, "InitStubs.3" was never adapted to describe the enhanced TIP #268 syntax.

oehharwiki2024-12-16 11:51:45

Propose new wording for the documentation with checkin [607aea587f] of branch [70f3b23cad-docs-version-requirement].

Comments welcome ! Harald

oehharwiki2024-12-20 10:21:18

Possible merge is postponed after 9.0.1 release.

Thanks for all, Harald

jan.nijtmanswiki2025-01-03 14:52:12

Looks good to me. Just one minor remark and an addition: [90436ee9e3ff3b1f]

+1 for merge to trunk and 8.7

oehharwiki2025-01-06 18:21:28

Thanks, Jan, for looking into this. Jan, we need your light here.

The last meeting revealed other issues:

  • an application will probably crash, if another version is used than the compiled one (e.g. 8.6 or 9.0).
  • Ashok proposed to use "TCL_VERSION" as content.
  • The magic functionality will probable work to make a binary work for 8.7 and 9.0. But 8.7 is not released, so this is a future feature.
  • The strict flag is overladed by macros to hold other information. But this is not packward compatible and not tipped. So this documentation correction would manifest it.
  • The macro stuff is not tipped neither.

Sorry, but this may be subject of the next telco. So, we get Jans light....

Take care, Harald

jan.nijtmanswiki2025-01-06 21:24:28

> Ashok proposed to use "TCL_VERSION" as content

This is a bad idea. I created a [demo] why. (try this with Linux or gcc on Windows)

oehharwiki2025-01-06 21:27:53

Thanks, Jan ! Nor Don, nor Ashok have any clue what to put into the version field. So, your light is really required.

Thanks, Harald

jan.nijtmanswiki2025-01-06 22:19:08

In most cases "8.6" is the right answer. After conversion to work with 9.0, "8.6-" or "8.6-10" is the right answer. Who is still interested in 8.5? And 8.7 doesn't exist yet.

apnadkarnimarkdown2025-01-07 03:05:10

To clarify, what I was trying to say is that I saw no use for the version parameter. In my view the argument passed to Tcl_InitStubs should always be TCL_VERSION and never a hardcoded "8.6" or similar. And this has nothing to do with Tcl 8 vs 9. It ensures that any attempt to load an extension into a version of Tcl older than the one against which it is built will fail.

For example, the extension might say Tcl_InitStubs(..., "8.5",...) but then be built against Tcl 8.6. That binary built against 8.6 should not be loadable into 8.5. No matter the programmer's claim that it only uses 8.5 stubs functions. Even if that was the case when initially written, over time as the extension evolves, 8.6 stubs might be called. The whole purpose is to protect against inadvertent programmer errors and hardcoding "8.5" defeats that purpose.

Put it differently, the Tcl_InitStubs call should not have had a version parameter at all. It should have just used TCL_VERSION in it's internal checks. It's too late to change now, but the advice should be to always just pass TCL_VERSION to the function.

fvogelwiki2025-01-07 06:47:12

One point regarding Jan's attempt to clarify even more in the man pages in [3200a10430]: The comments following each line of code must be correct as of now only. As time passes and more Tcl version come out we will have to remember to update these comments. That's why I'm not 100% comfortable with this commit. I would see a pointer to the "VERSION NUMBERS" section and to the package vatisfies section of the [package] man page as a better alternative since those are much less specific.

jan.nijtmanswiki2025-01-10 14:06:42

Another [attempt] to make things more clear without too much bloat.

fvogelplain2025-01-10 19:57:38
Nice, thanks!
jan.nijtmanswiki2025-01-12 18:15:04

Merged to [trunk] and other branches.

Since this is a doc-fix only, no need to mention this in changes.md

oehharplain2025-01-13 07:25:15
Thanks, great.

The new text mentions "8.6", "8.6-", but not "8.6-9".

Would it be a good idea also to add the 3rd form "8.6-9" ?

Thanks,
Harald
jan.nijtmanswiki2025-01-13 08:35:04

> Would it be a good idea also to add the 3rd form "8.6-9" ?

No, because "8.6-9" is exactly the same as "8.6", I see no added value.

What you probably mean is "8.6-10" (because the max-value is _exclusive_, remember ....), Which means that all between 8.6 (inclusive) and 10.0 (exclusive) works.

It's exactly this risk, people forgetting that the end-value is _exclusive_ why I prefer "8.6-" more than "8.6-10". Whether Tcl 10.0 will work or not, is not a concern yet, I don't think we will see Tcl 10.0 before my pension.

oehharplain2025-01-13 09:11:22
Ok, thanks, great work.
I was trapped by my own trap ;-).

The change of the strict parameter from boolean to "list of flags" should be mentioned in the release notes.

Remark that at least in machine language, a boolean 1 is always "-1" (all bits set) and not "1" (only LSB set).

Thank you and take care,
Harald
jan.nijtmansmarkdown2025-01-13 09:56:43

I have no objection, mentioning this in the release notes.

I don't know anyone calling Tcl_InitStubs(.... , 1). We should recommend the 'exact' parameter to be 0 always. There's no use-case for making it 1 (or -1, if you like).

In C, printing a boolean always gives '1' or '0', never '-1'.

oehharwiki2025-01-30 13:15:26

Mnetioned in the Migration wiki page of TCL by [efbd9d4fb4] and Tk by https://core.tcl-lang.org/tk/info/2775ca08f78b27ab.

I think, this is the best place for this information.

Thanks, Harald

Log in (anonymous is fine) to add a comment.