TIP 543: Eliminate TCL_INTERP_DESTROYED flag value

Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.
Author:         Don Porter <dgp@users.sourceforge.net>
State:          Draft
Type:           Project
Tcl-Version:    9.0
Vote:           Pending
Created:        10-May-2019
Keywords:       Tcl, traces


This TIP proposes the elimination of the TCL_INTERP_DESTROYED flag.


Variable traces arrived no later than release Tcl 5.0 (1991). Early on, no later than release Tcl 6.1 (1991), a flag value TCL_INTERP_DESTROYED was defined to pass to each trace-handling Tcl_VarTraceProc routine to signal that deletion of the interpreter was underway. This was a sign that script evaluation should not be attempted with the interpreter.

The routine Tcl_InterpDeleted() arrived in release Tcl 7.5 (1996). It is a supported, public mechanism to determine whether the deletion of any interpreter has begun, exactly the same status the TCL_INTERP_DESTROYED flag is intended to signal. At that time, there was no longer any need for the flag to achieve the needed function. Any Tcl_VarTraceProc routine may call Tcl_InterpDeleted() to test any interp to see if script evaulation should not be attempted.

Namespaces were added in release Tcl 8.0 (1997). With their addition, the setting of TCL_INTERP_DESTROYED became buggy during namespace destructions, sometimes set when it should not be, sometimes cleared when it should not be. A segfault arising from this was reported in Tk ticket 605121 (2002), leading to a bug fix.

A new facility for tracing operations on commands with Tcl_TraceCommand() and friends arrived in release Tcl 8.4 (2002). These routines were documented to also use the TCL_INTERP_DESTROYED flag. That documentation was false. The false claim was noted in ticket 2039178 (2008) and corrected in 2014, replacing claims about TCL_INTERP_DESTROYED with advice on the need to make calls to Tcl_InterpDeleted().

A fix for Tcl tickets 1337229 and 1338280 (2005) included a refactoring of namespace variable destruction into a new internal routine TclDeleteNamesapceVars(). The new routine was created improperly failing to pass TCL_INTERP_DESTROYED when it should. This defect was eventually noticed as a memory leak reported in ticket 1706140. (2007)

At that point Tcl internals were all converted to stop making use of the TCL_INTERP_DESTROYED flag, and an RFE note to TIP its elimination was recorded in ticket 1714505. Here is that TIP.


The support of the TCL_INTERP_DESTROYED flag was buggy over longer periods of time than it was correct. It is unnecessary. We are better off without it, converting all users to use of Tcl_InterpDeleted().


In Tcl 9, remove the flag value TCL_INTERP_DESTROYED from code and documentation.

In Tcl 8.7, mark the use of the flag as deprecated in code and documentation.


Existing Tcl_VarTraceProc that use the TCL_INTERP_DESTROYED flag will need to be converted to use Tcl_InterpDeleted() to work with Tcl 9. Tk 8.7 has now been so converted.

Reference Implementation

See branches tip-543. and tip-543-9.


This document has been placed in the public domain.