summaryrefslogtreecommitdiffstats
path: root/win/winMain.c
diff options
context:
space:
mode:
authordavygrvy <davygrvy>2003-12-12 00:45:33 (GMT)
committerdavygrvy <davygrvy>2003-12-12 00:45:33 (GMT)
commit9d8614e821fb5dc8a5eedad902876c466247386f (patch)
tree1c976649e030b330ff57984387a733fec3931541 /win/winMain.c
parent02cb757780218ac7e5d286d14ddc9861d1374377 (diff)
downloadtk-9d8614e821fb5dc8a5eedad902876c466247386f.zip
tk-9d8614e821fb5dc8a5eedad902876c466247386f.tar.gz
tk-9d8614e821fb5dc8a5eedad902876c466247386f.tar.bz2
fixed bad commit from before. my mistake. This is 1.16 now.
Diffstat (limited to 'win/winMain.c')
-rw-r--r--win/winMain.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/win/winMain.c b/win/winMain.c
index 9fd2f36..ba203c4 100644
--- a/win/winMain.c
+++ b/win/winMain.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: winMain.c,v 1.17 2003/12/12 00:34:06 davygrvy Exp $
+ * RCS: @(#) $Id: winMain.c,v 1.18 2003/12/12 00:45:33 davygrvy Exp $
*/
#include <tk.h>
@@ -32,13 +32,15 @@
*/
static void setargv _ANSI_ARGS_((int *argcPtr, char ***argvPtr));
-static Tcl_PanicProc WishPanic;
+static void WishPanic _ANSI_ARGS_(TCL_VARARGS(CONST char *,format));
+static void AppInitExitHandler(ClientData clientData);
#ifdef TK_TEST
extern int Tktest_Init(Tcl_Interp *interp);
#endif /* TK_TEST */
static BOOL consoleRequired = TRUE;
+static char **argvSave = NULL;
/*
* The following #if block allows you to change the AppInit
@@ -111,6 +113,11 @@ WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
setargv(&argc, &argv);
/*
+ * Save this for later, so we can free it.
+ */
+ argvSave = argv;
+
+ /*
* Replace argv[0] with full pathname of executable, and forward
* slashes substituted for backslashes.
*/
@@ -164,6 +171,12 @@ Tcl_AppInit(interp)
Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
/*
+ * This exit handler will be used to free the
+ * resources allocated in this file.
+ */
+ Tcl_CreateExitHandler(AppInitExitHandler, NULL);
+
+ /*
* Initialize the console only if we are running as an interactive
* application.
*/
@@ -242,8 +255,36 @@ WishPanic TCL_VARARGS_DEF(CONST char *,arg1)
#ifdef _MSC_VER
DebugBreak();
#endif
- ExitProcess(EXIT_FAILURE);
+ ExitProcess(1);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * AppInitExitHandler --
+ *
+ * This function is called to cleanup the app init resources before
+ * Tcl is unloaded.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Frees the saved argv and deletes the async exit handler.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+AppInitExitHandler(
+ ClientData clientData)
+{
+ if (argvSave != NULL) {
+ ckfree((char *)argvSave);
+ argvSave = NULL;
+ }
}
+
/*
*-------------------------------------------------------------------------
*
@@ -299,7 +340,7 @@ setargv(argcPtr, argvPtr)
}
}
}
- argSpace = (char *) Tcl_Alloc(
+ argSpace = (char *) ckalloc(
(unsigned) (size * sizeof(char *) + strlen(cmdLine) + 1));
argv = (char **) argSpace;
argSpace += size * sizeof(char *);