Tcl Source Code

Artifact [5715412941]
Login

Artifact 5715412941c12e2f4d956487209baf0e14b8768b:

Attachment "empty.patch" to ticket [584123ffff] added by mdejong 2002-07-20 12:57:37.
2002-07-19  Mo DeJong  <[email protected]>

	* generic/threadSvCmd.c (Sv_tclEmptyStringRep, Sv_Init):
	Avoid linking to the tclEmptyStringRep variable defined
	in Tcl since this makes it very difficult to load
	the Thread package into an executable that has
	also loaded Tcl. The previous approach used a hack
	under Windows, we now use this same hack on all systems.

Index: generic/threadSvCmd.c
===================================================================
RCS file: /cvsroot/tcl/thread/generic/threadSvCmd.c,v
retrieving revision 1.19
diff -u -r1.19 threadSvCmd.c
--- generic/threadSvCmd.c	12 Jul 2002 11:44:12 -0000	1.19
+++ generic/threadSvCmd.c	20 Jul 2002 05:48:38 -0000
@@ -47,13 +47,12 @@
 static Tcl_ObjType* stringObjTypePtr;
 
 /*
- * For windows, we must use tricks to get this
- * pointer right. Look in Sv_Init for details.
+ * In order to be fully stub enabled, a small
+ * hack is needed to query the tclEmptyStringRep
+ * global symbol defined by Tcl. See Sv_Init.
  */
 
-#ifdef WIN32
- char* tclEmptyStringRep = NULL;
-#endif
+char *Sv_tclEmptyStringRep = NULL;
 
 /*
  * Global variables used within this file.
@@ -767,7 +766,7 @@
 
     if (objPtr->bytes == NULL) {
         dupPtr->bytes = NULL;
-    } else if (objPtr->bytes != tclEmptyStringRep) {
+    } else if (objPtr->bytes != Sv_tclEmptyStringRep) {
         /* A copy of TclInitStringRep macro */
         dupPtr->bytes = (char*)Tcl_Alloc((unsigned)objPtr->length + 1);
         if (objPtr->length > 0) {
@@ -1691,17 +1690,19 @@
                 Tcl_InitHashTable(&bucketPtr->handles, TCL_ONE_WORD_KEYS);
             }
             Tcl_CreateExitHandler((Tcl_ExitProc*)SvFinalize, NULL);
-#ifdef WIN32
             /*
-             * There is no other way to get tclEmptyStringRep
-             * pointer in Windows environment w/o this trick
+             * We use this trick to get the tclEmptyStringRep pointer
+             * defined by Tcl without directly referencing it. If we
+             * referenced the symbol directly, we could not link
+             * under Windows. It would also break under Linux if
+             * both Tcl and the Threads package were dynamically
+             * loaded into an application.
              */
             {
                 Tcl_Obj *dummy = Tcl_NewObj();
-                tclEmptyStringRep = dummy->bytes;
+                Sv_tclEmptyStringRep = dummy->bytes;
                 Tcl_DecrRefCount(dummy);
             }
-#endif
         }
         Tcl_MutexUnlock(&bucketsMutex);
     }