Add optional casts to free() calls.  (Jack)
Set Tk variable argv0 to classname passed in to Tkapp_New.  (Fred)
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index bbada35..1be788b 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -26,6 +26,7 @@
 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */
 
 #include "Python.h"
+#include <ctype.h>
 
 #include <tcl.h>
 #include <tk.h>
@@ -49,9 +50,12 @@
 
 /*
 ** Additional cruft needed by Tcl/Tk on the Mac.
-** This is for Tcl 7.5 and Tk 4.1 (final releases).
+** This is for Tcl 7.5 and Tk 4.1 (patch release 1).
 */
 
+/* free() expects a char* */
+#define FREECAST (char *)
+
 #include <Events.h> /* For EventRecord */
 
 typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr));
@@ -62,6 +66,10 @@
 
 #endif /* macintosh */
 
+#ifndef FREECAST
+#define FREECAST
+#endif
+
 /**** Tkapp Object Declaration ****/
 
 staticforward PyTypeObject Tkapp_Type;
@@ -201,9 +209,9 @@
   for (i = 0; i < argc; i++)
     if (fv[i]) free (argv[i]);
   if (argv != argvStore)
-    free (argv);
+    free (FREECAST argv);
   if (fv != fvStore)
-    free (fv);
+    free (FREECAST fv);
 
   return res;
 }
@@ -239,7 +247,7 @@
 	PyTuple_SetItem (v, i, Split (self, argv[i]));
     }
 
-  free (argv);
+  free (FREECAST argv);
   return v;
 }
 
@@ -276,6 +284,7 @@
      int interactive;
 {
   TkappObject *v;
+  char *argv0;
   
   v = PyObject_NEW (TkappObject, &Tkapp_Type);
   if (v == NULL)
@@ -300,6 +309,16 @@
   else
     Tcl_SetVar (v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
 
+  /* This is used to get the application class for Tk 4.1 and up */
+  argv0 = (char*) malloc (strlen (className) + 1);
+  if (argv0 != NULL) {
+    strcpy (argv0, className);
+    if (isupper (argv0[0]))
+      argv0[0] = tolower (argv0[0]);
+    Tcl_SetVar (v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
+    free (argv0);
+  }
+
   if (Tcl_AppInit (v->interp) != TCL_OK)
     return (TkappObject *) Tkinter_Error (v);
 
@@ -677,7 +696,7 @@
   for (i = 0; i < argc; i++)
     PyTuple_SetItem (v, i, PyString_FromString (argv[i]));
 
-  free (argv);
+  free (FREECAST argv);
   return v;
 }