Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 255c5ab17a0234652cbb9a41f08e7843f2a9096a8030bc2a386bc8fe3f249d5f
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 14:03:11
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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
        } 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>
    
  5. is_private changed to: "0"
  6. login: "pooryorick"
  7. priority changed to: "5 Medium"
  8. resolution changed to: "None"
  9. severity changed to: "Minor"
  10. status changed to: "Open"
  11. submitter changed to: "pooryorick"
  12. subsystem changed to: "- New Builtin Commands"
  13. title changed to:
    calling an imported alias in a deletion trace on the alias causes Tcl to cycle on routine resolution
    
  14. type changed to: "Bug"