Skip to content
Tcl Source Code Check-in [d03339047e]
Login

Check-in [d03339047e]

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: d03339047eac701b85993b6a3a557d5a4da000ecaa03aa02cc4fa027442d6c69
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