| Ticket UUID: | 6e156333bcf233a26216e3ee3e94f2761e97a34b | ||
| Title: | Documentation: Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc | ||
| Type: | Bug | Created on: | 2019-07-22 20:00:32 |
| Submitter: | anonymous | Assigned to: | dgp |
| Subsystem: | 10. Objects | Severity: | Minor |
| Priority: | 5 Medium | Last modified: | 2019-07-23 09:39:50 |
| Status: | Open | Closed by: | nobody |
| Resolution: | None | Closed on: | 2019-07-23 08:03:44 |
| Version: | 8.6 | ||
| Description: | ||||
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. | ||||
| User Comments: | ||||
sebres added on 2019-07-22 21:31:16:
> objPtr's bytes member is always NULL when it is called. means BEFORE, so the 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):
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. anonymous (claiming to be [email protected]) added on 2019-07-23 08:03:44:
Your comment restates what THE UPDATESTRING FIELD says and I have no issue with that. However, the But if the bytes member is So how is this supposed to work? (Or should the
sebres added on 2019-07-23 09:21:44:
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. Thanks! Thus reopening. sebres added on 2019-07-23 09:39:50:
Looks like Don were competent to this change (see "bug" [500930]). | ||||
