#3636 command found in deleted namespace

obsolete: 8.4.15
Don Porter

I don't like the looks of this:

% namespace eval x {
proc die {} {namespace delete [namespace current]}
proc test {} {
set self [namespace which [lindex [info level 0] 0]]
set ns [namespace qualifiers $self]
puts "I am $self in namespace $ns which exists? [namespace exists $ns]"
% namespace eval x {
I am ::x::test in namespace ::x which exists? 0

Once a namespace is deleted, I'd expect us
not to find the commands in it anymore.


  • Don Porter

    Don Porter - 2007-02-08
  • Don Porter

    Don Porter - 2007-02-08

    Logged In: YES
    Originator: YES

    Here's a patch against
    core-8-4-branch that I'd like
    some opinions about.
    File Added: 1655294.patch

  • miguel sofer

    miguel sofer - 2007-09-10

    Logged In: YES
    Originator: NO

    Your expectations collide with what is coded, apparently by design. The namespace ::x does not die when [namespace delete ::x] returns, but rather when the last CallFrame using ::x is popped; the comments at tclNamesp.c line 588 describe that:

    * If the namespace is on the call frame stack, it is marked as "dying"
    * (NS_DYING is OR'd into its flags): the namespace can't be looked up
    * by name but its commands and variables are still usable by those
    * active call frames. When all active call frames referring to the
    * namespace have been popped from the Tcl stack, Tcl_PopCallFrame will
    * call this procedure again to delete everything in the namespace.
    * If no nsName objects refer to the namespace (i.e., if its refCount
    * is zero), its commands and variables are deleted and the storage for
    * its namespace structure is freed. Otherwise, if its refCount is
    * nonzero, the namespace's commands and variables are deleted but the
    * structure isn't freed. Instead, NS_DEAD is OR'd into the structure's
    * flags to allow the namespace resolution code to recognize that the
    * namespace is "deleted". The structure's storage is freed by
    * FreeNsNameInternalRep when its refCount reaches 0.

    Note that this might just be a bug in [namespace which], it seems to be otherwise respected:

    % namespace eval x {die; ::x::test}
    invalid command name "::x::test"

    This being said: the precise going-ons on namespace deletion, especially wrt to the interplay with active call frames and deletion traces, is not specified anywhere but in code comments. Hard to say how much is really by actual design, as opposed to a least-bad judgment at the time it was coded.

  • miguel sofer

    miguel sofer - 2009-05-01
    • priority: 5 --> 6
  • miguel sofer

    miguel sofer - 2009-05-03

    See also #2785893 and #2724403

  • miguel sofer

    miguel sofer - 2010-01-03

    see patch at [Bug 2724403], which redefines the ns deletion sequence and fixes this:
    "Patch attached with new ns deletion policy: everything goes at once!
    Flag bits NS_DYING and NS_DEAD are removed, nsPtr->activationCount is
    history too. References are now all kept in nsPtr->refCount: nsName objs,
    CallFrames, parent namespace."

  • Don Porter

    Don Porter - 2010-01-05

    I'm missing something?

    Bug 2724403 is Closed:Fixed, but I still
    see the demo script in this report producing
    the same arguably buggy results on the Tcl HEAD.

  • miguel sofer

    miguel sofer - 2010-01-05

    Uh ... I wasn't very clear on that. Bug 2724403 had two ways of being fixed: #1 was by altering the ns deletion sequence, #2 by giving coros a special treatment. That bug was fixed in HEAD using #2, which has no effect on the issue in this ticket. The patch attached to that bug report (and NOT applied) uses approach #1 and should fix the present issue too.

  • miguel sofer

    miguel sofer - 2011-04-12
    • assigned_to: msofer --> dgp
    • status: open --> pending
  • SourceForge Robot

    • status: pending --> closed
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

  • Don Porter

    Don Porter - 2012-03-29
    • assigned_to: dgp --> msofer
    • status: closed --> open

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks