Tcl Source Code

Check-in [bf62ce24c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixes reentrant lock (UB), also locks only if it necessary (avoid extra lock)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | mistake
Files: files | file ages | folders
SHA3-256: bf62ce24c60c7b8af411fb6adb9fb1ae7501ee3583ac94547ce1998f20126e26
User & Date: sebres 2025-08-13 16:09:23.510
References
2025-08-13
16:11 Ticket [87b69745be] interp creation resets encoding directory search path status still Open with 3 other changes artifact: 1aa7e19a58 user: sebres
Context
2025-08-13
16:09
fixes reentrant lock (UB), also locks only if it necessary (avoid extra lock) Closed-Leaf check-in: bf62ce24c6 user: sebres tags: mistake
13:52
Merge core-9-0-branch Closed-Leaf check-in: 648341fdeb user: apnadkarni tags: bug-87b69745be
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/tclEncoding.c.
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007




1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022

int
Tcl_SetSystemEncoding(
    Tcl_Interp *interp,		/* Interp for error reporting, if not NULL. */
    const char *name)		/* The name of the desired encoding, or NULL/""
				 * to reset to default encoding. */
{
    Tcl_Encoding encoding;

    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;
	}




    }

    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;
}

/*
 *---------------------------------------------------------------------------







|

<
|
|
|
|
|
>
|
|
<
|
|
|
<
<
|
<
<
|
|
>
>
>
>

<
<



<
<







980
981
982
983
984
985
986
987
988

989
990
991
992
993
994
995
996

997
998
999


1000


1001
1002
1003
1004
1005
1006
1007


1008
1009
1010


1011
1012
1013
1014
1015
1016
1017

int
Tcl_SetSystemEncoding(
    Tcl_Interp *interp,		/* Interp for error reporting, if not NULL. */
    const char *name)		/* The name of the desired encoding, or NULL/""
				 * to reset to default encoding. */
{
    Tcl_Encoding encoding = NULL;


    if (name && *name) {
	encoding = Tcl_GetEncoding(interp, name); /* this increases refCount */
	if (encoding == NULL) {
	    return TCL_ERROR;
	}
    }

    /* Don't lock, change anything, bump epoch if it remains unchanged. */

    if ((encoding ? encoding : defaultEncoding) == systemEncoding) {
	if (encoding) {
	    Tcl_FreeEncoding(encoding); /* paired to Tcl_GetEncoding */


	}


	return TCL_OK;
    }
    Tcl_MutexLock(&encodingMutex);
    if (!encoding) {
	encoding = defaultEncoding; /* need increase its refCount */
	((Encoding *)encoding)->refCount++;
    }


    FreeEncoding(systemEncoding);
    systemEncoding = encoding;
    Tcl_MutexUnlock(&encodingMutex);


    Tcl_FSMountsChanged(NULL);

    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------