Artifacts Associated With Ticket 6e156333bcf233a2
Ticket change [5bf2cfe647] (rid 173580) by anonymous on 2019-07-22 20:00:32:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
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.
- foundin initialized to: "8.6"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "9ab7cae6a79106af802b939550556c6a60bbac54"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "10. Objects"
- title initialized to:
Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
- type initialized to: "Bug"
Ticket change [e8a918cd1c] (rid 173581) by sebres on 2019-07-22 21:31:16:
- closedate changed to: "2458687.39671544"
- closer changed to: "sebres"
- icomment:
<i>> objPtr's bytes member is always NULL when it is called.</i> means <b>BEFORE</b>, so the <code>updateStringProc</code> is never called if <code>objPtr->bytes</code> is not NULL and vice versa (only called if it is NULL). See [https://core.tcl-lang.org/tcl/artifact?name=be4f8c6174676167&ln=1624|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 <b>must ALWAYS</b> update it (so set to not NULL): <ul> <li>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 [https://wiki.tcl-lang.org/page/everything+is+a+string|EIAS]. </li> <li>or set it to <code>tclEmptyStringRep</code> if you don't "need" to follow EIAS (and if you have tcl-internal's or obtained <code>tclEmptyStringRep</code> pointer from some function).<br/> If you would not create it, so after call of <code>updateStringProc</code> it is still NULL - then the only thing you'd get hereafter is a <b>SEGFAULT</b> (or at least panic with "failed to create a valid string rep" on tcl before 9.0). </li> </ul> 3. Once created, it remains quasi immutable (at least it should), you can free the string representation (e. g. using <code>Tcl_InvalidateStringRep</code>) 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 [https://stackoverflow.com/questions/54337750/shouldnt-tclinvalidatestringrep-reset-length/54369232#54369232|my answer for such question on SO]). Thus closed as invalid, please reopen if I'm wrong.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Closed"
Ticket change [2d1736322b] (rid 173596) by anonymous on 2019-07-23 08:03:44:
- closedate changed to: "2458687.83592755"
- closer changed to: "anonymous"
- icomment:
Your comment restates what THE UPDATESTRING FIELD says and I have no issue with that. However, the <code>Tcl_GetString</code> documentation is saying something else: it says you can call <code>Tcl_GetString</code> from the <i>UpdateStringProc</i> 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 <code>NULL</code> when <i>UpdateStringProc</i> is called, and <i>UpdateStringProc</i> calls <code>Tcl_GetString</code>, then <code>Tcl_GetString</code> would have no recourse but to call <i>UpdateStringProc</i> again, leading to infinite recursion (unless the type pointer had been changed before calling <code>Tcl_GetString</code>). So how is this supposed to work? (Or should the <code>Tcl_GetString</code> documentation be changed?)
- login: "anonymous"
- mimetype: "text/x-fossil-wiki"
- username: "[email protected]"
Ticket change [90c0235c93] (rid 173597) by sebres on 2019-07-23 09:21:44:
- closer changed to: "nobody"
- icomment:
Oh... do you mean this sentence? <p style="padding-left:10pt; font-style: italic"> 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. <b>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.</b> </p> Indeed, this looks a bit confusing resp. one could understand ambiguous in this context.<br/> It was firstly introduced in check-in [b1c464dbcaf08c6d], and I'm still not quite following the meaning of that change. Thanks! Thus reopening.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "None"
- status changed to: "Open"
- title changed to:
Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
Ticket change [95b1188f83] (rid 173598) by sebres on 2019-07-23 09:39:50:
- assignee changed to: "dgp"
- icomment:
Looks like Don were competent to this change (see "bug" [500930]).<br/> Assigned.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"