[Pkg-tcltk-devel] Bug#502304: Tcl_Main should quit (exiting nonzero) if appInitProc fails
Ian Jackskon
ijackson at chiark.greenend.org.uk
Wed Oct 15 12:21:26 UTC 2008
Package: tcl8.4
Version: 8.4.12-1.1
Tags: patch
This report is regarding the error behaviour of:
Tcl_Main(int argc, char *argv[], Tcl_AppInitProc *appInitProc)
with respect to appInitProc which has this type:
int Tcl_AppInit(Tcl_Interp *interp)
The documentation says that appInitProc may return TCL_OK or _ERROR.
The implication of TCL_ERROR is that the initialisation failed. Under
these conditions continuing to execute the program or shell is not
appropriate.
As a demonstration:
mariner:~> DISPLAY=: wish
Application initialization failed: couldn't connect to display ":"
% mariner:~>
mariner:~> cat >t.tcl
vwait variable
mariner:~> DISPLAY=: wish -f t.tcl
Application initialization failed: couldn't connect to display ":"
[hangs]
Similar behaviour will appear with any program which uses Tcl_Main and
has an appInitProc which can fail. (Obviously the test cases above
are simple tests, but a more complicated program involving vwait is
quite conceivable.)
The code in Tcl_Main seems to suggest that if the appInitProc were to
call Tcl_DeleteInterp, the execution would be safely abandoned. But
this is a quite unreasonable thing to expect the appInitProc hook to
do and is not documented. In any case if the appInitProc merely wants
to issue a warning and carry on it can do so itself. The exit code
should be reserved for ordinary (fatal) errors.
I think this patch will fix it but I haven't compiled or tested it.
--- generic/tclMain.c~ 2005-10-23 23:01:30.000000000 +0100
+++ generic/tclMain.c 2008-10-15 13:18:39.000000000 +0100
@@ -281,6 +281,8 @@
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp));
Tcl_WriteChars(errChannel, "\n", 1);
}
+ exitCode = 1;
+ goto done;
}
if (Tcl_InterpDeleted(interp)) {
goto done;
--
More information about the Pkg-tcltk-devel
mailing list