|
2019-07-23
| ||
| 09:39 | • Ticket [6e156333bc] Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFr... artifact: 95b1188f83 user: sebres | |
| 09:21 | • Open ticket [6e156333bc]. artifact: 90c0235c93 user: sebres | |
| 08:03 | • Ticket [6e156333bc]: 6 changes artifact: 2d1736322b user: anonymous | |
|
2019-07-22
| ||
| 21:31 | • Closed ticket [6e156333bc]. artifact: e8a918cd1c user: sebres | |
| 20:00 | • New ticket [6e156333bc]. artifact: 5bf2cfe647 user: anonymous | |
Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
Tcl_GetString documentation (http://www.tcl.tk/man/tcl8.6/TclLib/StringObj.htm) says: [The object's string representation] is passed back as a writable pointer so that extension author creating their own Tcl_ObjType will be able to modify the string representation within the Tcl_UpdateStringProc of their Tcl_ObjType. THE UPDATESTRINGPROC FIELD in http://www.tcl.tk/man/tcl8.6/TclLib/ObjectType.htm says: objPtr's bytes member is always NULL when it is called. This would seem to be a contradiction: if the bytes member is NULL, then updateStringProc would need to be called to set it to non-null; trying to invoke Tcl_GetString or Tcl_GetStringFromObj would just result in a recursive call to updateStringProc -- unless the typePtr were temporarily changed to a different type. Is that (temporary modification of the typePtr) the intended meaning? BTW: I don't know how to change my password on this site.
> objPtr's bytes member is always NULL when it is called.
means BEFORE, so the updateStringProc is never called if objPtr->bytes is not NULL and vice versa (only called if it is NULL).
See tclObj.c#Tcl_GetString for more info.
Three main things are important here:
1. The handler used to update the string representation only if it is NULL (and never if it is not NULL);
2. It must ALWAYS update it (so set to not NULL):
- either set it to some buffer (allocated by ckalloc) and fill with NTS corresponding your internal representation and set objPtr->length to proper length of that, so follow EIAS.
- or set it to
tclEmptyStringRepif you don't "need" to follow EIAS (and if you have tcl-internal's or obtainedtclEmptyStringReppointer from some function).
If you would not create it, so after call ofupdateStringProcit is still NULL - then the only thing you'd get hereafter is a SEGFAULT (or at least panic with "failed to create a valid string rep" on tcl before 9.0).
Tcl_InvalidateStringRep) but only if the object is not shared or you have it only under your control, e. g. you know all the references are yours (see my answer for such question on SO).
Thus closed as invalid, please reopen if I'm wrong.
Your comment restates what THE UPDATESTRING FIELD says and I have no issue with that.
However, the Tcl_GetString documentation is
saying something else:
it says you can call Tcl_GetString from the
UpdateStringProc
to get a modifiable string that you can then change (presumably without
changing its length or at most shortening it).
But if the bytes member is NULL when
UpdateStringProc is called,
and UpdateStringProc calls Tcl_GetString,
then Tcl_GetString
would have no recourse but to call UpdateStringProc again,
leading to infinite recursion (unless
the type pointer had been changed before calling
Tcl_GetString).
So how is this supposed to work? (Or should the
Tcl_GetString documentation
be changed?)
Oh... do you mean this sentence?
If the value's UTF string representation is invalid (its byte pointer is NULL), the string representation is regenerated from the value's internal representation. The storage referenced by the returned byte pointer is owned by the value manager. It is passed back as a writable pointer so that extension author creating their own Tcl_ObjType will be able to modify the string representation within the Tcl_UpdateStringProc of their Tcl_ObjType.
Indeed, this looks a bit confusing resp. one could understand ambiguous in this context.
It was firstly introduced in check-in [b1c464dbcaf08c6d], and I'm still not quite following the meaning of that change.
Thanks! Thus reopening.
Looks like Don were competent to this change (see "bug" [500930]).
Assigned.