Overview
| Artifact ID: | 9ba1ec31755e4bb6b38346cad676e56f3177abddae0e73c0168696abc73371d3 |
|---|---|
| Ticket: | 0c82728f85760f36361fe42a15f55453c94d285d
lappend/linsert ignore the abstract-list Replace hook on some code paths |
| User & Date: | rocketship98 on 2026-10-21 00:01:55 |
Changes
- icomment:
While looking at why linsert behaves differently from lappend for us, I believe I found the cause of the linsert case (claude is more certain, and he's the I below in this comment). In Tcl_LinsertObjCmd (tclCmdIL.c) there is a special case for inserting exactly one element at the end of the list: if ((objc == 4) && (index == len)) { result = Tcl_ListObjAppendElement(NULL, listPtr, objv[3]); Tcl_ListObjAppendElement does not call the Replace hook of an abstract list, so the value is converted to an ordinary list. Every other form of linsert (two or more elements, middle, start) calls Tcl_ListObjReplace, which does call the hook, and keeps the type. The code is the same in 9.0.4 and 9.1.1, apart from the argument declarations. Changing that one call to the following made all the linsert forms I tried keep the type, on both a 9.0.4 and a 9.1.1 build (compiled at top level, command name in a variable, via eval, in a proc). The core's cmdIL, listObj, list and linsert test files also pass with it (324 tests, 0 failed); I have not run the rest of the core test suite: result = Tcl_ListObjReplace(NULL, listPtr, len, 0, 1, &objv[3]); Separately, for lappend: I believe the places where 9.1 already keeps the type (eval, uplevel #0) are where lappendListPtr in tclExecute.c calls Tcl_ListObjReplace instead of TclListObjAppendElements, which 9.0.4 still does: 9.0.4: TclListObjAppendElements(interp, valueToAssign, objc, objv) 9.1: Tcl_ListObjReplace(interp, valueToAssign, len, 0, objc, objv) Changing just that call in a 9.0.4 build gave the 9.1.1 results for those two cases. I think the change may come from the fix for INST_LAPPEND_LIST with zero-length lists (dkf, trunk, May 2025), but I could not confirm that from the repository history. The case that still loses the type on both versions is a plain lappend inside a proc, which is what this ticket covers. - login: "rocketship98"
- mimetype: "text/plain"