summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index ce5fda4..d3914da 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -969,9 +969,11 @@ Tcl_GetEncodingNulLength(
* unless interp was NULL.
*
* Side effects:
- * The reference count of the new system encoding is incremented. The
- * reference count of the old system encoding is decremented and it may
- * be freed. All VFS cached information is invalidated.
+ * If the passed encoding is the same as the current system
+ * encoding, the call is effectively a no-op. Otherwise, the reference
+ * count of the new system encoding is incremented. The reference count
+ * of the old system encoding is decremented and it may be freed. All
+ * VFS cached information is invalidated.
*
*------------------------------------------------------------------------
*/
@@ -983,25 +985,34 @@ Tcl_SetSystemEncoding(
* to reset to default encoding. */
{
Tcl_Encoding encoding;
- Encoding *encodingPtr;
- if (!name || !*name) {
- Tcl_MutexLock(&encodingMutex);
- encoding = defaultEncoding;
- encodingPtr = (Encoding *) encoding;
- encodingPtr->refCount++;
- Tcl_MutexUnlock(&encodingMutex);
+ Tcl_MutexLock(&encodingMutex);
+ if (name == NULL || name[0] == '\0') {
+ if (defaultEncoding == systemEncoding) {
+ Tcl_MutexUnlock(&encodingMutex);
+ return TCL_OK;
+ }
+ encoding = defaultEncoding;
+ ((Encoding *)encoding)->refCount += 1;
} else {
encoding = Tcl_GetEncoding(interp, name);
+ if (encoding == systemEncoding) {
+ FreeEncoding(encoding);
+ Tcl_MutexUnlock(&encodingMutex);
+ return TCL_OK;
+ }
if (encoding == NULL) {
+ Tcl_MutexUnlock(&encodingMutex);
return TCL_ERROR;
}
}
- Tcl_MutexLock(&encodingMutex);
+ assert(encoding != systemEncoding);
FreeEncoding(systemEncoding);
systemEncoding = encoding;
Tcl_MutexUnlock(&encodingMutex);
+
+ /* Checks above ensure this is only called when system encoding changes */
Tcl_FSMountsChanged(NULL);
return TCL_OK;