Overview
| Artifact ID: | 9fcc1f8173ef3720588686bf324343241eca6de609f3c6695cbfc738d982d571 |
|---|---|
| Ticket: | a34733451b2cf189528061944466cf7ce7015008
Regression with TIP #636 in foreach |
| User & Date: | apnadkarni on 2023-07-12 05:46:40 |
Changes
- icomment:
Adding my two cents, more to clarify my own thinking: * Tcl values are defined by their string representation as stored in the `Tcl_Obj.bytes` field * `Tcl_DuplicateObj` preserves the value sematics by preserving the `bytes`, while `TclDuplicatePureObj` does not. Consider two objects, both of type `intType` (or whatever the `int` internal rep is) with value 16 but `obj1.bytes` being "16" and `obj2.bytes` being "0x10". These are not equal values but `obj1` and `TclDuplicatePureObj(obj2)` will be equal. * `Tcl_DuplicateObj` was used in at least two ways. One was to make an unshared copy for further modification. The other was to ensure the internal rep remained valid (e.g. iterating a list) even though no modification was planned. `TclDuplicatePureObj` can replace `Tcl_DuplicateObj` in the first instance since anyways the `bytes` will be invalidated. I don't think it can replace in the second instance. All uses need to be examined for which of the two cases applies. * I am a bit uncomfortable with the implementation which copies the `bytes` pointer from the source to the dup object and calls `Tcl_ConvertToType`. I don't know if there are any guarantees that `Tcl_ConvertToType` will not somehow manipulate the allocation if the Tcl_Obj is unshared. May not be a problem now but in the future for all possible types? * Although I initially thought the option table code might also violate consistency, I am not so sure any more based on my `int` example above. It is legitimate to have two string values map to the same internal rep. However, when generated from a string, the string representation *must* be preserved. This does not happen due to `TclDuplicatePureObj`, not because of the option table code.
- login: "apnadkarni"
- mimetype: "text/x-markdown"