Tk Source Code

View Ticket
Login
Ticket UUID: 0189a9ae3921c907bff63e7aac7bb68d387a5a65
Title: Use of Tk_Uid in Tk API
Type: Bug Version: 8.6
Submitter: jan.nijtmans Created on: 2024-09-01 21:12:07
Subsystem: 28. Utility Functions Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-09-02 12:31:53
Resolution: Fixed Closed By: oehhar
    Closed on: 2024-09-02 12:31:53
Description:

According to the tk.decls files, Tk_Get3DBorder(), Tk_GetColor() and Tk_GetCursor() have a Tk_Uid argument. According to the documentation, those arguments were of type "char *", which is clearly wrong. I added the missing "const" keyword now.

The question now is: Are those arguments really a Tk_Uid, or are they "const char *"? Inspecting the implementation, I don't find any proof that the arguments should be a Tk_Uid. So, it looks like the tk.decls file is wrong. Therefore, I did an experiment, in which I violated all Tk_GetColor() and Tk_Get3DBorder() calls: All Tk_Uid argument were converted to a normal string before the call, and disposed afterwards. This proves that the arguments do not really need to be a Tk_Uid, otherwise I would expect a crash.

Proposal: Correct the tk.decls file to change those arguments to "const char *", which is according to the documentation.

Then, there's the function Tk_GetCursorFromData(). This is the only function in the Tk API, which still has an incoming Tk_Uid parameter (actually: 2 of them). I propose to change those in "const char *" too, it's a simple internal change to make that work. That will be done for 9.0 only (to reduce any mininimal risk ...).

Any objections?

User Comments: oehhar added on 2024-09-02 12:31:53:

Jan gave some additional insight within the TTT call. I try to get it in my words. I am sure, it is only 50% correct, but anyway.

The "Tk_Uid" interface was an interface from the TCL/Tk time, where there was no TCL_Obj data type and anything was stored as a string.

It is physically a string (e.g. char * type) with an additional contract, that the mapping between the object property (ex. color, border) and the string is constant, unique and existent over the runtime. E.g. the pointer value does not change.

In case of color and border, this was replaced long time ago by an object interface and a hash table. The "contract" was not fullfilled any more. The string is placed in a Tcl_Obj structure and in a hash table, but the structure may be moved. The pointer may be changed.

Due to that, it does not make sense any more to call those data types "Tk_Uid". They were changed to "const char *". It was documented, that those parameters are of type "char *", but the prototype did not reflect this.

Within the canvas code, there are usages of "Tk_Uid" and they are not touched. Those values are not jet transformed to a Tcl_Obj interface.

Thanks for all, Harald


jan.nijtmans added on 2024-09-02 09:40:53:

Give Christian Werner's approval, merged to trunk now.


jan.nijtmans added on 2024-09-02 09:28:02:

Christian Werner wrote on the Tcl Core list:

I see. Indeed this ship has sailed last century. The problem with the signature of e.g. Tk_Color() should have been solved when the underlaying color hashtable was changed from TCL_ONE_WORD_KEYS to TCL_STRING_KEYS. Seems that would have been in late 1998 if it had happened ever.

A fine reason to power up the flux capacitor.


oehhar added on 2024-09-02 08:45:01:

Result of TTT today:

this is a documentation fix. The parameter type "Tk_Uid" is also a char *.

But there is additional contract, that it is unique and constant.

This is not the case and the Tk documentation does also say this.

So, this "hint to properties" is just wrong.

So, we would be in favor of this change, but it does not make any impact.

Thank you for all, Harald


dgp added on 2024-09-01 23:36:47:
I don't have a strong understanding of what's happening here.  Is this
change the solution to a critical problem?  What has been broken that 
this change fixes?

What I see is a change late in the release cycle, creating a new interface
variant right before a stable release.  Something that was not tested in
any of the months of beta testing of Tk 9.0b*.

It's probably fine.  It's probably an improvement.  I probably will not
notice it at all, and to the extent I do notice it, I will probably like the
change.  But it is not well timed.  If nothing else, it is clear that
the change can raise alarms on TCLCORE.  Can we redirect this work toward
Tk 9.1.0 or Tk 9.0.1?  Recall that Tk should be able to make its own patch
releases without waiting for Tcl so the delay need not be long.

There are currently 5 checkins on the Tk trunk that I have not yet merged to 
the release branch.  I lack confidence about which of them are bug and
doc fixes important to get into the release, and which might be more in the
spirit of explorations that this looks like to me.  I'd be happier if I
could merge all trunk changes because folks keep the more exploratory
matters in some staging branches for now.  Easier for me, and a better
environment when those testing releases and those testing trunk are mutually
supporting each other and not testing divergent things.

If there's multiple Tk folks who think this change needs to be in the
Tk 9.0.0 release, I will follow the informed leaders.  Please raise that
voice of confidence if that is the necessary and proper path.

jan.nijtmans added on 2024-09-01 21:33:47:

Implementation is [58408333c7321547|here]