Tcl Source Code

Artifact [7479f6a508]
Login

Artifact 7479f6a508a34f6e21b84294e1f6a3d16ddda2a6:

Attachment "966053.patch" to ticket [966053ffff] added by dgp 2004-06-04 03:28:26.
Index: generic/tclEncoding.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclEncoding.c,v
retrieving revision 1.22
diff -u -r1.22 tclEncoding.c
--- generic/tclEncoding.c	7 May 2004 20:01:23 -0000	1.22
+++ generic/tclEncoding.c	3 Jun 2004 20:26:32 -0000
@@ -236,7 +236,7 @@
 			    Tcl_EncodingState *statePtr, char *dst, int dstLen,
 			    int *srcReadPtr, int *dstWrotePtr,
 			    int *dstCharsPtr));
-static int		TclFindEncodings _ANSI_ARGS_((CONST char *argv0));
+static int		FindEncodings();
 
 
 /*
@@ -1142,7 +1142,7 @@
     /*
      * The value returned from TclpNameOfExecutable is a UTF string that
      * is possibly dirty depending on when it was initialized.
-     * TclFindEncodings will indicate whether we must "clean" the UTF (as
+     * FindEncodings will indicate whether we must "clean" the UTF (as
      * reported by the underlying system).  To assure that the UTF string
      * is a properly encoded native string for this system, convert the
      * UTF string to the default native encoding before the default
@@ -1151,7 +1151,7 @@
      */
     
     Tcl_UtfToExternalDString(NULL, name, -1, &buffer);
-    mustCleanUtf = TclFindEncodings(argv0);
+    mustCleanUtf = FindEncodings();
 
     /*
      * Now it is OK to convert the native string back to UTF and set
@@ -1174,7 +1174,7 @@
     return;
 	
     done:
-    (void) TclFindEncodings(argv0);
+    (void) FindEncodings();
 }
 
 /*
@@ -2942,7 +2942,7 @@
 /*
  *-------------------------------------------------------------------------
  *
- * TclFindEncodings --
+ * FindEncodings --
  *
  *	Find and load the encoding file for this operating system.
  *	Before this is called, Tcl makes assumptions about the
@@ -2959,10 +2959,8 @@
  *-------------------------------------------------------------------------
  */
 
-int
-TclFindEncodings(argv0)
-    CONST char *argv0;		/* Name of executable from argv[0] to main()
-				 * in native multi-byte encoding. */
+static int
+FindEncodings()
 {
     int mustCleanUtf = 0;
 
@@ -2974,7 +2972,6 @@
 
 	TclpInitLock();
 	if (encodingsInitialized == 0) {
-	    char *native;
 	    Tcl_Obj *pathPtr;
 	    Tcl_DString libPath, buffer;
 
@@ -2985,8 +2982,13 @@
 
 	    encodingsInitialized = 1;
 
-	    native = TclpFindExecutable(argv0);
-	    mustCleanUtf = TclpInitLibraryPath(native);
+	    /* 
+	     * NOTE: we can safely make direct use of tclNativeExecutableName
+	     * because we know all our callers ( Tcl_FindExecutable() is the
+	     * only one) have already called TclpFindExecutable().
+	     */
+
+	    mustCleanUtf = TclpInitLibraryPath(tclNativeExecutableName);
 
 	    /*
 	     * The library path was set in the TclpInitLibraryPath routine.
Index: generic/tclInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclInt.h,v
retrieving revision 1.162
diff -u -r1.162 tclInt.h
--- generic/tclInt.h	30 May 2004 12:18:25 -0000	1.162
+++ generic/tclInt.h	3 Jun 2004 20:26:33 -0000
@@ -1641,6 +1641,7 @@
 
 extern char *			tclExecutableName;
 extern char *			tclNativeExecutableName;
+extern int			tclFindExecutableSearchDone;
 extern char *			tclDefaultEncodingDir;
 extern char *			tclMemDumpFileName;
 extern TclPlatformType		tclPlatform;
Index: generic/tclUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclUtil.c,v
retrieving revision 1.44
diff -u -r1.44 tclUtil.c
--- generic/tclUtil.c	6 Apr 2004 22:25:55 -0000	1.44
+++ generic/tclUtil.c	3 Jun 2004 20:26:33 -0000
@@ -25,6 +25,7 @@
 
 char *tclExecutableName = NULL;
 char *tclNativeExecutableName = NULL;
+int tclFindExecutableSearchDone = 0;
 
 /*
  * The following values are used in the flags returned by Tcl_ScanElement
Index: unix/tclUnixFile.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixFile.c,v
retrieving revision 1.39
diff -u -r1.39 tclUnixFile.c
--- unix/tclUnixFile.c	6 Apr 2004 22:25:57 -0000	1.39
+++ unix/tclUnixFile.c	3 Jun 2004 20:26:33 -0000
@@ -54,9 +54,10 @@
     if (argv0 == NULL) {
 	return NULL;
     }
-    if (tclNativeExecutableName != NULL) {
+    if (tclFindExecutableSearchDone) {
 	return tclNativeExecutableName;
     }
+    tclFindExecutableSearchDone = 1;
 
     Tcl_DStringInit(&buffer);
 
Index: unix/tclUnixTest.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixTest.c,v
retrieving revision 1.17
diff -u -r1.17 tclUnixTest.c
--- unix/tclUnixTest.c	27 May 2004 13:18:55 -0000	1.17
+++ unix/tclUnixTest.c	3 Jun 2004 20:26:33 -0000
@@ -446,6 +446,7 @@
 {
     char *oldName;
     char *oldNativeName;
+    int oldDone;
 
     if (argc != 2) {
 	Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
@@ -455,9 +456,11 @@
 
     oldName       = tclExecutableName;
     oldNativeName = tclNativeExecutableName;
+    oldDone       = tclFindExecutableSearchDone;
 
     tclExecutableName       = NULL;
     tclNativeExecutableName = NULL;
+    tclFindExecutableSearchDone = 0;
 
     Tcl_FindExecutable(argv[1]);
     if (tclExecutableName != NULL) {
@@ -468,8 +471,9 @@
 	ckfree(tclNativeExecutableName);
     }
 
-    tclExecutableName       = oldName;
-    tclNativeExecutableName = oldNativeName;
+    tclExecutableName           = oldName;
+    tclNativeExecutableName     = oldNativeName;
+    tclFindExecutableSearchDone = oldDone;
 
     return TCL_OK;
 }