Artifacts Associated With Ticket 4f6a1ebd64
Ticket change [fcd4c610d1] (rid 158917) by pooryorick on 2017-11-25 15:41:13:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
The following example causes a segmentation fault: <code><verbatim> namespace eval n {namespace ensemble create} dict set list one ::two namespace ensemble configure n -subcommands $list -map $list n one </verbatim></code> The problem is that <code>tclEnsemble.c/BuildEnsembleConfig</code> [https://core.tcl.tk/tcl/artifact?ln=2536-2537&name=9cf6780328312995|gets hold of a List internal representation] of <code>ensemblePtr->subcommandList</code>, but then [https://core.tcl.tk/tcl/artifact?ln=2556-2557&name=9cf6780328312995|converts the internal representation] of <code>ensemblePtr->subcommandList</code> to a dictionary. If it so happens that <code>ensemblePtr->subcommandList</code> and <code>ensemblePtr->subcommandDict</code> are the same Tcl_Obj, the storage for the List internal representation is deallocated. A similar issue is [1670091]. - foundin initialized to: "trunk"
- is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- private_contact initialized to: "e476148cded301ffff84bcdc432536dc0c949e88"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "21. [namespace]"
- title initialized to:
ensemble: segmentation fault when -subcommand and -map values are the same object
- type initialized to: "Bug"
Ticket change [2362961bbc] (rid 158921) by pooryorick on 2017-11-25 16:41:36:
- closedate changed to: "2458083.19556701"
- closer changed to: "pooryorick"
- icomment: "Fixed in commit [046a5af026]."
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [9ca873754f] (rid 158969) by dgp on 2017-11-28 18:19:27:
- closedate changed to: "2458086.26351532"
- closer changed to: "dgp"
- icomment:
Is there a reason TclListCopy() did not figure in the solution here?
- login: "dgp"
- mimetype: "text/plain"
Ticket change [8a3aeaf7d8] (rid 158970) by dgp on 2017-11-28 18:19:52:
- closedate changed to: "2458086.26379911"
- icomment: "er, TclListObjCopy()"
- login: "dgp"
- mimetype: "text/plain"
Ticket change [744572fd67] (rid 158972) by sebres on 2017-11-28 21:28:23:
- closer changed to: "nobody"
- foundin changed to: ">= 8.5"
- icomment:
> Is there a reason TclListCopy() did not figure in the solution here? In my opinion this is anyway too hard to duplicate a list/dict in such obscure case (normally it would be enough to use construct as below to say it is in the dict instead of search in the dict): ``` if (!(i & 1) && i < subcmdc-1) { target = subcmdv[i+1]; } else { target = NULL; } ``` But unfortunately there is another obscure case (map used quasi as filtering): ``` proc ::two {} {return 2} proc ::three {} {return 3} set list {one ::two one ::three} namespace ensemble configure n -subcommands $lst -map $lst % n one 3 ``` But I've another own branch where ensembles map/list handling rewritten, and this case with duplication is fixed there. I'll try to rebase it here. Additionally I reopen this because currently all versions (supported ensembles) are affected. ATM fixed for core-8-branch only, I'll provide new one for 8.5 and if accepted reintegrate it for all versions (8.5 and higher). The test case is cherry-picked as is. - login: "sebres"
- mimetype: "text/plain"
- status changed to: "Open"
Ticket change [806a80e891] (rid 159047) by sebres on 2017-11-29 14:18:35:
- icomment:
Fixed in [f9e184a041] for 8.5 without duplication, +1 additional test-case to cover the last wins case (on dict's like {one ::two one ::three}, where "one" should be mapped to "::three"). And small code review to make the things simpler. If it is accepted I'll reintegrate it into 8.6 and higher (consider the move from tclNamesp.c to tclEnsemble.c). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Pending"
- icomment:
Ticket change [8208078e07] (rid 159159) by dgp on 2017-11-30 18:18:57:
- icomment:
I prefer the fix in [d3ba3a9f51] . It directly addresses the need to protect the pointer returned by Tcl_ListObjGetElements() and thus directly solves the problem instead of handling one particular set of circumstances known to cause the problem. And it's smaller. It does create and destroy one additional Tcl_Obj, but that's been engineered to be efficient already, and TclListObjCopy() only pays a large copying cost when it needs to, which is almost never, only for bug conditions like this.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [7f4f92e7ab] (rid 159160) by sebres on 2017-11-30 18:57:19:
- icomment:
> It does create and destroy one additional Tcl_Obj... And converts dict to the list (and of course copy this list), then back to the dict, and then again to the list... > And it's smaller. Yes, the change as is 2-3 lines shorter... But are we in the save the lines mode now?
- login: "sebres"
- mimetype: "text/plain"
- icomment:
Ticket change [41fbd745dc] (rid 159244) by pooryorick on 2017-12-04 10:18:42:
- icomment:
I like sebres' fix because I like the idea of avoiding that additional type conversion, and I like the code as "documentation" of a real corner the case where the same value has explicitly been put to use as both a list and a dictionary.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [79960313cc] (rid 159252) by dgp on 2017-12-04 18:37:42:
- icomment:
See what you think of the new fix. https://core.tcl.tk/tcl/info/f8daa294c6a88076
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [72c25ef87b] (rid 159253) by sebres on 2017-12-04 21:14:07:
- icomment:
I like the idea basically, but you've made a large performance regression on creating of each ensemble ("normal" case as well as "strange" case)... For example in "normal" case (where map != list) by N sub-commands for ensemble: Previously (original):<pre> - iterate over LIST for N elements; - search in target hash-table (also N times). - search for replacement in DICT (also N times); - set value in target hash-table; </pre> New ([f8daa294c6a88076]):<pre> - iterate over DICT for N elements; - iterate over LIST for N elements (N*N times); - search/create in target hash-table (also N*N times). - set value in target hash-table; - iterate over LIST for N elements (the second "if"); - search in target hash-table (also N times). </pre> E. g. by 100 sub-commands you've almost 10x overhead there:<pre> - 23.508 µs/# 39808 # 42538.6 #/sec 935.809 nett-ms + 268.819 µs/# 3698 # 3720.0 #/sec 994.092 nett-ms </pre> Therefore I don't think it would be better now... What exactly don't like you in my solution [f9e184a041]? Possibly goto's? - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [2ee78c0cc2] (rid 159258) by dgp on 2017-12-05 14:45:11:
- icomment:
I made another re-working and got a lot closer to what sebres contributed. I think we're close enough to agreement now to merge the fix forward. If we need more changes we can always make them. Thanks!
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [8c87e539c2] (rid 159259) by dgp on 2017-12-05 14:45:27:
- icomment:
I made another re-working and got a lot closer to what sebres contributed. I think we're close enough to agreement now to merge the fix forward. If we need more changes we can always make them. Thanks!
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [1435481618] (rid 159274) by dgp on 2017-12-05 17:25:20:
- assignee changed to: "dgp"
- closedate changed to: "2458093.22592804"
- closer changed to: "dgp"
- icomment:
Fix merged forward. In reflection would have been better to fix only 8.6+.
- login: "dgp"
- mimetype: "text/plain"
- status changed to: "Closed"