# TIP 512: No stub for Tcl_SetExitProc() Author: Jan Nijtmans <jan.nijtmans@gmail.com> State: Draft Type: Project Vote: Created: 25-June-2018 Post-History: Keywords: Tcl Tcl-Version: 8.7-----# AbstractThis TIP proposes to remove the stub entries for `Tcl_SetExitProc()`,`Tcl_SetPanicProc()`, `Tcl_FindExecutable()` and (for Tk) `Tk_MainEx()`.The normal exported symbols for those functions will be kept intact.# ContextThis TIP is inspired by Tcl commit ["Add custom exit procedure fortcltests executable"](http://core.tcl.tk/tcl/info/6f650b4271a1ef2e)(thanks to Poor Yorick!). This commit demonstrates exactly what's the problemwhen using `Tcl_SetExitProc()` in a stub-enabled extension.# RationaleWhen running test-cases in Windows (using mingw-64 or msvc, but using thewin/Makefile system not the nmake system), the tcltest executablecrashes after shutdown with some tests. The reason for this is thatthe additional test-code "tcltest" is compiled as stub-enabled extensionwhich is dynamically loaded into tclsh. So, there is no "tcltest"executable in this environment, all there is is tclsh86.exe andtcltest86.dll.If a stub-enabled extension registers an Exit-handler, the followinghappens at exit time. During the clean-up, Tcl unloads all extensions.When the clean-up is done, the last step is calling the registeredExit-handler. But ... since the exit handler function was locatedinside the dll, it's address space is gone already. This resultsin the mentioned crash.The same problem exists in `Tcl_SetPanicProc()`: If a stub-enabledextension registers a Panic proc which is located in its ownaddress space, the extension might be gone when the panicproc isfinally called.`Tcl_FindExecutable()` and `Tk_MainEx()` don't register functions,but those functions - too - are meant to be used at applicationlevel, not at extension level. Therefore those don't belong inthe stub table either.# SpecificationThe above mentioned functions are marked with _nostub_, and thetools/genStubs.tcl tooling is adapted to recognize this specialkeyword. It means that the function entry in the stub table ismarked as deprecated, but the normal function entry is leaf as-is.When Tcl is compiled with -DTCL\_NO\_DEPRECATED, the stub entries forthe above functions will no longer be available. The stub tableentries for those function will be filled with 0 instead.Starting with Tcl 9.0, those stub entries will be removed completely.In stead, those functions will be defined in tcl.h, as normalexported symbols, just like `Tcl_MainEx()` (for example).# ImplementationCurrently, the proposed implementation is available in [tip-512 branch](https://core.tcl.tk/tk/timeline?r=tip-512).# CopyrightThis document has been placed in the public domain.