Overview
| Comment: | Addressing "lset leak via TclLsetList (Claude)" Shared a file, used Claude Docs, executed 29 commands. The `lset` leak has been fixed (v15o, in `typeparse.zip`). Along the way, I also corrected a type-loss issue in `lpop` and a minor leak occurring during the management of typed variables. The leak was more extensive than anticipated. It affected any `lset` operation targeting a single index within a typed list—such as the common case `lset L 0 9`, whether compiled or not—resulting in a leak of approximately 170 bytes per call (17 MB over 100,000 calls in v15). The root cause lies within Tcl 9.0 itself. The core lacks a consistent convention regarding the reference returned by an abstract list’s `setElementProc`: * `TclLsetList` (used for `lset L 0 9` and `lset L {0} 9`) as well as uncompiled `lset` operations with multiple indices add a reference; therefore, the returned value must not carry an additional reference. * `INST_LSET_FLAT` (for compiled `lset M 0 1 9`) and `lpop L i` use the value as-is, implying it must already carry a reference. Our `AnnotListSetElement` followed the second convention, which caused the leak. I initially attempted the reverse—aligning the core with our approach—but Tcl’s own test abstract list follows the first convention, causing `abstractlist.test` to crash. The fix: adopting a single convention—the first one. * `AnnotListSetElement` now returns the value without an added reference. * `INST_LSET_FLAT` and `lpop` (with indices) now add the reference they expect to be present. Also discovered (and already present in v15): * `lpop L` (without an index) caused the variable to lose its type; `type get $L` would return empty. It would modify the value of a typed list in place; the variable would then hold an untyped value, effectively losing its contract. A typed list is now copied before any modification, consistent with the behavior of `lset`. There was a minor memory leak during the handling of a retyped value (`tclVar.c`): when a value—arriving without a reference—was replaced by its retyped version, the original value was never freed. Additionally, an improperly targeted cleanup operation occurred in the same section: if a contract was rejected, the code would target the intermediate value instead of the caller’s original value. Tests against v15: The new test `t68_lset_reference` measures memory usage (Linux only; it reports "no /proc" on other systems). In v15, it showed a leak in four scenarios, as well as a type loss during `lpop`; now, there are no leaks or type losses. The project's tests and examples show no new differences compared to v15, and all `.out` outputs pass. The Tcl test suites—`lset*`, `lpop`, `list*`, `cmdIL`, `abstractlist`, `lseq`, `set*`, `var`, `upvar`, `append*`, `incr*`, and `trace`—result in 1,903 passes, 84 skips, and zero failures, exactly as in v15. `valgrind` shows no issues. |
|---|---|
| Timelines: | family | ancestors | descendants | both | tip-764_tcl90 |
| Files: | files | file ages | folders |
| SHA3-256: |
d03339047eac701b85993b6a3a557d5a |
| User & Date: | Florentis on 2026-10-23 11:38:18.695 |
| Other Links: | branch diff | manifest | tags |
Context
|
2026-10-23
| ||
| 16:08 | The three points are complete: this is version v15p, found in `typeparse.zip`. Along the way, `valgr... check-in: 40e39579b9 user: Florentis tags: tip-764_tcl90 | |
| 11:38 | Addressing "lset leak via TclLsetList (Claude)" Shared a file, used Claude Docs, executed 29 command... check-in: d03339047e user: Florentis tags: tip-764_tcl90 | |
| 11:20 | Conversion rules between variants are now in place: this is version v15n, found in typeparse.zip. t... check-in: 582865c204 user: Florentis tags: tip-764_tcl90 | |
Changes
Modified generic/tclAnnotObj.c
from [c508d04558]
to [9b1cec1038].
[diff]
Modified generic/tclCmdIL.c
from [940c60acd5]
to [9c040fb624].
[diff]
Modified generic/tclExecute.c
from [5219f18f56]
to [1cd33cd0b7].
[diff]
Modified generic/tclVar.c
from [98699e4d13]
to [a27790dff6].
[diff]
Modified typeparse/doc/ANNOTATIONS.fr.md
from [26ebc4d05e]
to [cbfbc97645].
[diff]
Modified typeparse/noyau/LISEZMOI.md
from [3f3d688888]
to [87f33cc4c0].
[diff]
Modified typeparse/noyau/ORDRE.txt
from [ddc94047b3]
to [1b7fbc343e].
[diff]
Added typeparse/noyau/lset-reference.patch version [eb41a2424a].
Modified typeparse/tclAnnotObj.c
from [c508d04558]
to [9b1cec1038].
[diff]
Added typeparse/tests_tclsh/t68_lset_reference.out version [9683946b2a].
Added typeparse/tests_tclsh/t68_lset_reference.tcl version [bc0e405fa0].