Artifacts Associated With Ticket a4494e28ed
Ticket change [bfa13115b7] (rid 136746) by pooryorick on 2014-02-05 03:11:33:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
In Tcl 8.6.1, the code below produces the following message, and the interpreter aborts: DeleteImportedCmd: did not find cmd in real cmd's list of import references ### begin code ### #! /bin/env tclsh proc alias {alias target} { set fulltarget [uplevel [list namespace which $target]] namespace eval [namespace qualifiers $fulltarget] \ [list namespace export [namespace tail $fulltarget]] set newcmd [namespace eval [info cmdcount] [string map [ list @{alias} [list $alias] @{fulltarget} [list $fulltarget] ] { namespace import @{fulltarget} rename [namespace tail @{fulltarget}] @{alias} ::namespace export @{alias} ::namespace which @{alias} }]] uplevel [list namespace import $newcmd] uplevel [list trace add command $fulltarget delete [list apply [list {stash args} { namespace delete [namespace qualifiers $stash] }] $newcmd]] } proc proc1 args {} alias newproc proc1 proc proc1 {} {} - foundin initialized to: "8.6.1"
- is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- private_contact initialized to: "8254af92ef5a06fe918df67f141b815e71ed987e"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "21. [namespace]"
- title initialized to:
alias trace did not find command in real command list of import references
- type initialized to: "Bug"
Ticket change [c90e7e5ba8] (rid 136747) by dkf on 2014-02-05 13:13:23:
- assignee changed to: "miguel"
- icomment: "I can reproduce with 8.5 (8.5.9) as well."
- login: "dkf"
- mimetype: "text/html"
- priority changed to: "9 Immediate"
- severity changed to: "Severe"
- username: "dkf"
Ticket change [e5e34e0296] (rid 136748) by dgp on 2014-02-05 23:21:53:
- icomment:
With the obvious conversion replacing [apply] with another helper proc, the same trouble is in Tcl 8.4(.8)
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [17ea9a0911] (rid 136749) by miguel on 2014-02-06 13:20:50:
- icomment:
Still trying to find out WTF. In the meantime, in the "don't do that" tradition, a simpler [alias] that does not have this problem - by deleting the temporary namespace tmpns immediately instead of setting a delete trace. I would actually consider having a permanent namespace for use as scratchpad - mimicking the /tmp directory. proc alias {alias target} { set fulltarget [uplevel 1 [list namespace which $target]] set tailtarget [namespace tail $fulltarget] set tmpns [info cmdcount] namespace eval [namespace qualifiers $fulltarget] \ [list namespace export $tailtarget] namespace eval $tmpns \ [list namespace import $fulltarget] uplevel 1 [list rename \ [namespace which ${tmpns}::$tailtarget] \ $alias] namespace delete $tmpns } - login: "miguel"
- mimetype: "text/plain"
- icomment:
Ticket change [053c66d7bc] (rid 136750) by miguel on 2014-02-06 15:15:33:
- assignee changed to: "dgp"
- icomment:
This is pretty involved - the required mechanics for deleting an imported command ALSO from a delete trace on the target are not in place, and it doesn't look trivial to implement. The trouble is (refs from checkout4aa075565662, today's top of core-8-5-branch): 1. when the target is replaced via Tcl_CreateObjCommand, the importRefPtr is saved and set to NULL (tclBasic.c line 1891) 2. the target is deleted, it's delete traces run causing the imported command to be deleted 3. the imported command looks for a ref to itself in the target's importRefPtr, panics when it doesn't find itself I do not see how to fix this. It is a conseuqence of what I consider to be a misfeature. Redefining a command maintains the exports - so that imported commands are NOT a link to the original implementation (what I would propose is the correct thing), but rather to the current implementation ... ASSUMING it wasn't EXPLICITLY deleted and then recreated, in which case the import ceases to exist. A weird bastard between an interp-alias and (what I believe should be) an import. IOW, redefining a command is different from deleting/recreating it in terms of exports - but delete traces have no way to know about this difference. Maybe the solution should be that delete traces not be run when the command is being recreated?
- login: "miguel"
- mimetype: "text/plain"
Ticket change [c981c459eb] (rid 136752) by dgp on 2014-02-06 15:37:07:
- icomment:
Simplified demo: namespace eval ::demo { proc foo args {} namespace export foo namespace eval ::x [list namespace import [namespace which foo]] trace add command foo delete {namespace delete ::x;#} proc foo {} {} } - login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [a3a31126c2] (rid 136753) by dgp on 2014-02-06 15:50:06:
- icomment:
The "Don't Do That" workaround is to place the command delete trace on the import, and not the original. namespace eval ::demo { proc foo args {} namespace export foo namespace eval ::x [list namespace import [namespace which foo]] # trace add command foo delete {namespace delete ::x;#} namespace eval ::x {trace add command foo delete {namespace delete ::x;#}} proc foo {} {} } - login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [21847aa808] (rid 136754) by dgp on 2014-02-06 16:01:40:
- icomment:
miguel is correct that the panic is rooted in the failure to cleanly define just what a [namespace import] is really importing and the bizarre DWIM rules that have grown up in the absence of that clean spec. You can sensibly define import by name, or import by token, but existing [namespace import] never made up its mind.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [c1d9a9b083] (rid 136755) by dgp on 2014-02-06 16:09:21:
- icomment:
dgp I think I see a clever fix dgp there's a fine line between clever and stupid
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [f1c5fdd0bd] (rid 136775) by dgp on 2014-02-06 22:16:51:
- icomment:
While exploring the clever stupid solution, I landed on the boring effective solution instead.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [e1b9d44716] (rid 136776) by msofer on 2014-02-06 22:34:50:
- icomment: "... but this margin is too small?"
- login: "msofer"
- mimetype: "text/plain"
Ticket change [dbdff2886c] (rid 136777) by dgp on 2014-02-06 22:46:52:
- closedate changed to: "2456695.44922139"
- closer changed to: "dgp"
- icomment: "Fixed on active branches."
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- subsystem changed to: "45. Parsing and Eval"