Skip to content
Tcl Source Code History Of Ticket 6e156333bc
Login

History Of Ticket 6e156333bc

Artifacts Associated With Ticket 6e156333bc

  1. Ticket change [5bf2cfe647] (rid 173580) by anonymous on 2019-07-22 20:00:32:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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.
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9ab7cae6a79106af802b939550556c6a60bbac54"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "10. Objects"
    15. title initialized to:
      Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
      
    16. type initialized to: "Bug"
  2. Ticket change [e8a918cd1c] (rid 173581) by sebres on 2019-07-22 21:31:16:

    1. closedate changed to: "2458687.39671544"
    2. closer changed to: "sebres"
    3. 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.
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
  3. Ticket change [2d1736322b] (rid 173596) by anonymous on 2019-07-23 08:03:44:

    1. closedate changed to: "2458687.83592755"
    2. closer changed to: "anonymous"
    3. 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?)
      
    4. login: "anonymous"
    5. mimetype: "text/x-fossil-wiki"
    6. username: "[email protected]"
  4. Ticket change [90c0235c93] (rid 173597) by sebres on 2019-07-23 09:21:44:

    1. closer changed to: "nobody"
    2. 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.
      
    3. login: "sebres"
    4. mimetype: "text/x-fossil-wiki"
    5. resolution changed to: "None"
    6. status changed to: "Open"
    7. title changed to:
      Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
      
  5. Ticket change [95b1188f83] (rid 173598) by sebres on 2019-07-23 09:39:50:

    1. assignee changed to: "dgp"
    2. icomment:
      Looks like Don were competent to this change (see "bug" [500930]).<br/>
      Assigned.
      
    3. login: "sebres"
    4. mimetype: "text/x-fossil-wiki"