Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e8a918cd1cd5a49713d75d9bd694bb841f025b66f65041734dc128bc0812c161
Ticket: 6e156333bcf233a26216e3ee3e94f2761e97a34b
Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc
User & Date: sebres on 2019-07-22 21:31:16
Changes

  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"