summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-05-23 15:37:15 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-05-23 15:37:15 (GMT)
commitb230de2a4d3e8748a542c21d0dfde9e357ac0b0a (patch)
tree7bc0db9c2639cc8032e5b0b99cec5bc2983824d8 /generic/tclUtil.c
parent5862bbf9a4dc0cd16bda094a60e69432d0012f9b (diff)
parentd3a254e3c86d510b3ed3ebf163ceabffb17ddafd (diff)
downloadtcl-b230de2a4d3e8748a542c21d0dfde9e357ac0b0a.zip
tcl-b230de2a4d3e8748a542c21d0dfde9e357ac0b0a.tar.gz
tcl-b230de2a4d3e8748a542c21d0dfde9e357ac0b0a.tar.bz2
Fix [3fc3287497]: TclGetProcessGlobalValue encodes information twice on Windows
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 3043fed..fc9cbfe 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -4128,6 +4128,7 @@ TclSetProcessGlobalValue(
Tcl_HashTable *cacheMap;
Tcl_HashEntry *hPtr;
int dummy;
+ Tcl_DString ds;
Tcl_MutexLock(&pgvPtr->mutex);
@@ -4143,8 +4144,12 @@ TclSetProcessGlobalValue(
}
bytes = TclGetString(newValue);
pgvPtr->numBytes = newValue->length;
+ Tcl_UtfToExternalDStringEx(NULL, encoding, bytes, pgvPtr->numBytes,
+ TCL_ENCODING_PROFILE_TCL8, &ds, NULL);
+ pgvPtr->numBytes = Tcl_DStringLength(&ds);
pgvPtr->value = (char *)Tcl_Alloc(pgvPtr->numBytes + 1);
- memcpy(pgvPtr->value, bytes, pgvPtr->numBytes + 1);
+ memcpy(pgvPtr->value, Tcl_DStringValue(&ds), pgvPtr->numBytes + 1);
+ Tcl_DStringFree(&ds);
if (pgvPtr->encoding) {
Tcl_FreeEncoding(pgvPtr->encoding);
}
@@ -4186,6 +4191,7 @@ TclGetProcessGlobalValue(
Tcl_HashTable *cacheMap;
Tcl_HashEntry *hPtr;
Tcl_Size epoch = pgvPtr->epoch;
+ Tcl_DString newValue;
if (pgvPtr->encoding) {
Tcl_Encoding current = Tcl_GetEncoding(NULL, NULL);
@@ -4197,7 +4203,7 @@ TclGetProcessGlobalValue(
* system encoding.
*/
- Tcl_DString native, newValue;
+ Tcl_DString native;
Tcl_MutexLock(&pgvPtr->mutex);
epoch = ++pgvPtr->epoch;
@@ -4248,10 +4254,13 @@ TclGetProcessGlobalValue(
}
/*
- * Store a copy of the shared value in our epoch-indexed cache.
+ * Store a copy of the shared value (but then in utf-8)
+ * in our epoch-indexed cache.
*/
- value = Tcl_NewStringObj(pgvPtr->value, pgvPtr->numBytes);
+ Tcl_ExternalToUtfDString(NULL, pgvPtr->value, pgvPtr->numBytes, &newValue);
+ value = Tcl_NewStringObj(Tcl_DStringValue(&newValue), Tcl_DStringLength(&newValue));
+ Tcl_DStringFree(&newValue);
hPtr = Tcl_CreateHashEntry(cacheMap,
INT2PTR(pgvPtr->epoch), &dummy);
Tcl_MutexUnlock(&pgvPtr->mutex);