Overview
| Artifact ID: | fb80bd6e448bea32cc6454426bf1ca253a7c07ce352d3117aeef962031c5e6c7 |
|---|---|
| Ticket: | 29e8848eb9766b81413989ad8125b0c22d1d2c7e
calling an imported alias in a deletion trace on the alias causes Tcl to cycle on routine resolution |
| User & Date: | pooryorick on 2020-08-10 15:58:33 |
Changes
- comment changed to:
A command is typically available while its deletion is in progress: <code><verbatim> namespace eval ns1 { proc p1 {oldname newname op} { puts [list $oldname signing off!] } trace add command p1 delete [namespace which p1] rename p1 {} } </verbatim></code> Output: <code><verbatim> ::ns1::p1 signing off! </verbatim></code> However, in the case of an imported alias, the result is instead an infinite loop in command dispatch: <code><verbatim> namespace eval ns2 { namespace export * proc p1 {oldname newname op} { puts [list $oldname is being deleted!] } interp alias {} [namespace current]::p2 {} [namespace which p1] } namespace eval ns3 { namespace import ::ns2::p2 } proc ondelete {oldname newname op} { catch { ::ns3::p2 $oldname $newname $op } cres puts $cres } trace add command ::ns2::p2 delete [namespace which ondelete] rename ns2::p2 {} </verbatim></code> Output: <code><verbatim> too many nested evaluations (infinite loop?) </verbatim></code> What's happening here is that <code>tclNamesp.c:InvokeImportedNRCmd</code> extracts the command structure and passes it to <code>tclBasic.c:TclNREvalObjv</code>, along with the words of the original command, but then <code>tclBasic.c:EvalObjvCore</code> uses the <code>CMD_IS_DELETED</code> flag to decide to discard the command structure that was passed to it, and instead resolves the command name again, which leads back to <code>tclNamesp.c:InvokeImportedNRCmd</code> where the cyle repeats itself. <code>CMD_IS_DELETED</code> seems to be intended to mean "command deletion in progress", so perhaps the check for it can simply be removed from <code>tclBasic.c:EvalObjvCore</code>. A script-level workaround is to lookup up the alias and call it directly: <code><verbatim> proc ondelete {oldname newname op} { set alias [interp alias {} $oldname] {*}$alias $oldname $newname $op } </verbatim></code> - login: "pooryorick"
- mimetype: "text/plain"