Overview
| Artifact ID: | 981e54f9b9113d5cea112d037092b1a6961fda80f164ad6d37a51bd7eb73e392 |
|---|---|
| Ticket: | b343fe8656c16b2e02580f68423b6ef03463915c
TIP 636 Tcl_ListObjIndex incompatibility not documented |
| User & Date: | dkf on 2024-12-02 09:43:35 |
Changes
- icomment:
The hairiest hair on the monster happens when the called function decrements the reference count of the object back to zero. This definitely happens in `Tcl_EvalObj()` in some cases, but for `Tcl_ObjSetVar2()` is only ever likely to be a factor for the keyObj and valueObj arguments if there are traces in play (as those could effectively reject or replace the write). ## Background For ***untraced*** variables, the reference count changes are: * `nameObj`: don't increment reference count * `keyObj`: increment reference count _only_ when new array element is allocated * `valueObj`: increment reference count _only_ on successful write **Constants** reject writes prior to reference counts being updated, and don't apply to arrays or their elements (because there was a case in there that made my head ache and it was easier to just block safely and let someone else enable when they figure out what a constant array means and how you'd actually make it). This sort of thing is why I made constants a separate thing, despite it being possible to simulate them with traces/links in older versions of Tcl. **Traces** typically involve callbacks into the Tcl interpreter with no restrictions, and happen after the write has been done, so reference count updates can go down in that case (e.g., because a whole array trace removes the element you've just made) and full hairiness is achieved; both the key and the value arguments have their reference counts decreased back to their start value before the call to `Tcl_ObjSetVar2` exits (i.e., the handles are not safe to use after exit at all).
- login: "dkf"
- mimetype: "text/x-markdown"