543.md at [03040d0a7d]

Login

File tip/543.md artifact ad15ad11a4 part of check-in 03040d0a7d


# TIP 543: Eliminate `TCL_INTERP_DESTROYED` flag value
	Author:         Don Porter <[email protected]>
	State:          Final
	Type:           Project
	Tcl-Version:    9.0
	Vote:           Done
	Created:        10-May-2019
	Keywords:       Tcl, traces
	Post-History:
	Tcl-Branch:	tip-543-9
	Vote-Summary:	Accepted 9/0/0
	Votes-For:	DP, JD, MC, KW, SL, KK, FV, DF, JN
	Votes-Against:	none
	Votes-Present:	none
-----

# Abstract

This TIP proposes the elimination of the **TCL\_INTERP\_DESTROYED** flag.

# History

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](https://core.tcl-lang.org/tk/tktview/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](https://core.tcl-lang.org/tcl/tktview/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](https://core.tcl-lang.org/tcl/tktview/1337229)
and [1338280](https://core.tcl-lang.org/tcl/tktview/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](https://core.tcl-lang.org/tcl/tktview/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](https://core.tcl-lang.org/tcl/tktview/1714505).
Here is that TIP.

# Rationale

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**().

# Specification

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.

# Compatibility

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](https://core.tcl-lang.org/tcl/timeline?t=tip-543).
and [tip-543-9](https://core.tcl-lang.org/tcl/timeline?t=tip-543-9).

# Copyright

This document has been placed in the public domain.