diff options
| author | apnadkarni <apnmbx-wits@yahoo.com> | 2025-08-06 02:17:47 (GMT) |
|---|---|---|
| committer | apnadkarni <apnmbx-wits@yahoo.com> | 2025-08-06 02:17:47 (GMT) |
| commit | e1d9fc8bc199e1673586a9a4768a775e5ecf3c64 (patch) | |
| tree | e10a51dbfa8ab10638568a6557388b9c2a93c91d /generic/tclEncoding.c | |
| parent | eb1fba12e2552be1c75e7c53bf69ff88cbe28b05 (diff) | |
| download | tcl-e1d9fc8bc199e1673586a9a4768a775e5ecf3c64.zip tcl-e1d9fc8bc199e1673586a9a4768a775e5ecf3c64.tar.gz tcl-e1d9fc8bc199e1673586a9a4768a775e5ecf3c64.tar.bz2 | |
Only update file system epoch if system encoding changes
Diffstat (limited to 'generic/tclEncoding.c')
| -rw-r--r-- | generic/tclEncoding.c | 33 |
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; |
