Author: Don Porter <email@example.com> State: Final Type: Project Vote: Done Created: 30-Mar-2018 Post-History: Tcl-Version: 8.7 Tcl-Branch: tip-506 Vote-Summary: Accepted 5/0/1 Votes-For: DKF, KBK, JN, DGP, SL Votes-Against: none Votes-Present: BG, FV
Stop having all extensions and applications use macros to access the refCount field of the Tcl_Obj struct.
In all of recorded Tcl development history (since version 8.0p2 in 1998), the "routines" Tcl_IncrRefCount, Tcl_DecrRefCount, and Tcl_IsShared have been defined as macros, built on top of the premise that the caller has direct access to the objPtr->refCount field and the TclFreeObj routine, which is in public stubs even though it has a name suggesting a private routine and users of the Tcl C interface are instructed not to call it other than through the Tcl_DecrRefCount macro.
Like all encapsulation-breaking, the effect is to more strongly couple together modules of code so that they are inhibited from freely evolving as independently as they otherwise could. Simply defining these routines as actual routines would take away that brittle coupling, and the Tcl 8 → Tcl 9 transition is the opportunity to do it.
The disadvantages of the existing implementation are clear, so why do we have it? I must presume there is at least a strong myth in place that the macros are necessary to achieve acceptable performance. Perhaps that is true. It is a concern to take seriously, but we should demand evidence. This proposal and its draft implementation are a chance to consider the actual merit of those claims beyond keeping up a cargo cult habit.
Remove the macros Tcl_IncrRefCount, Tcl_DecrRefCount, and Tcl_IsShared from the tcl.h file. Create routines in the public stub table to replace them. Mark TclFreeObj as deprecated in the public stub table, and remove it from the Tcl 9 branch.
The removal of TclFreeObj is is a hard binary incompatibility. It is properly proposed as a change for Tcl 9, where all extensions and applications will require a re-compile anyway.
On the tip-506 branch.
This document has been placed in the public domain.