TCL9: Tcl_SetExitProc() API was removed

The Tcl_Exit() replacement proc takes charge of calling exit()

So this function can be easily migrated to libc atexit() which will
now run during exit() not just before.  Which seems ok for the purpose
of restoring the termios state of the tty.

This solution seems compatible with TCL8 as well so all calls to this
removed API are removed.

Note this patch also removes the invalidation (of the callback so
the deefault use of Tcl_Exit() is restored) before returning from
this function.  atexit() usage can not be invalidated after
registration but that can be controlled with application flag
checked inside the callback function if needed.
I have observed scenarios where I need to issue 'reset' manually
after exiting magic, still understanding better the build types
and scenarios that triggers this.
This commit is contained in:
Darryl L. Miles 2024-10-21 09:15:47 +01:00 committed by Tim Edwards
parent 0ce8265570
commit 77a7afc8e2
1 changed files with 13 additions and 11 deletions

View File

@ -793,15 +793,21 @@ mainInitAfterArgs()
}
/*
* Tcl exit procedure hook for the Tcl_Exit() subroutine
* Tcl_SetExitProc() was removed in TCL9 and used to perform this function
* see: https://core.tcl-lang.org/tips/doc/trunk/tip/512.md
*
* clientData is an exit value if "exit" was specified from a script.
* Note this change will slightly alter the order, the termios restore will
* not longer be performed before exit() is called.
*
* The default Tcl_Exit() does manage calling exit(status) by default.
* This assumes TxResetTerminal() will only attempt a restore if state
* was saved.
* TxResetTerminal() does not do anything if TxTkConsole is set that appears
* to be the popup shell window.
*/
void tcl_exit_hook(ClientData clientData)
static void atexit_exit_hook(void)
{
TxResetTerminal();
exit(*(int *)(&clientData));
TxResetTerminal(TRUE);
}
/*
@ -830,7 +836,7 @@ mainInitFinal()
#ifdef MAGIC_WRAPPER
/* Reset terminal if exit is called inside a TCL script */
Tcl_SetExitProc(tcl_exit_hook);
atexit(atexit_exit_hook);
/* Read in system pre-startup file, if it exists. */
@ -1223,10 +1229,6 @@ mainInitFinal()
UndoFlush();
TxClearPoint();
#ifdef MAGIC_WRAPPER
Tcl_SetExitProc(NULL);
#endif
return 0;
}