From c94fa5b242a0d1a9a41fb47e1c65e76bace375dc Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 28 Jul 2023 07:50:18 +0000 Subject: "utf-8" is the new "identity": make it available always --- generic/tclEncoding.c | 5 ++++- generic/tclInt.h | 1 + generic/tclZipfs.c | 13 ++++--------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 83510cc..18e81f9 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -186,6 +186,7 @@ TCL_DECLARE_MUTEX(encodingMutex) static Tcl_Encoding defaultEncoding = NULL; static Tcl_Encoding systemEncoding = NULL; Tcl_Encoding tclIdentityEncoding = NULL; +Tcl_Encoding tclUtf8Encoding = NULL; /* * Names of encoding profiles and corresponding integer values. @@ -601,7 +602,7 @@ TclInitEncodingSubsystem(void) type.freeProc = NULL; type.nullSize = 1; type.clientData = INT2PTR(ENCODING_UTF); - Tcl_CreateEncoding(&type); + tclUtf8Encoding = Tcl_CreateEncoding(&type); type.clientData = NULL; type.encodingName = "cesu-8"; Tcl_CreateEncoding(&type); @@ -723,6 +724,8 @@ TclFinalizeEncodingSubsystem(void) defaultEncoding = NULL; FreeEncoding(tclIdentityEncoding); tclIdentityEncoding = NULL; + FreeEncoding(tclUtf8Encoding); + tclUtf8Encoding = NULL; hPtr = Tcl_FirstHashEntry(&encodingTable, &search); while (hPtr != NULL) { diff --git a/generic/tclInt.h b/generic/tclInt.h index 61ad487..9d71197 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2909,6 +2909,7 @@ MODULE_SCOPE TclPlatformType tclPlatform; */ MODULE_SCOPE Tcl_Encoding tclIdentityEncoding; +MODULE_SCOPE Tcl_Encoding tclUtf8Encoding; MODULE_SCOPE int TclEncodingProfileNameToId(Tcl_Interp *interp, const char *profileName, diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 3a63b18..cfb0cf7 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -273,15 +273,11 @@ static struct { * they are believed to not be UTF-8; only * written to from Tcl code in a trusted * interpreter, so not protected by mutex. */ - Tcl_Encoding utf8; /* The UTF-8 encoding that we prefer to use - * for the strings (especially filenames) - * embedded in a ZIP. Other encodings are used - * dynamically. */ int idCount; /* Counter for channel names */ Tcl_HashTable fileHash; /* File name to ZipEntry mapping */ Tcl_HashTable zipHash; /* Mount to ZipFile mapping */ } ZipFS = { - 0, 0, 0, DEFAULT_WRITE_MAX_SIZE, NULL, NULL, 0, + 0, 0, 0, DEFAULT_WRITE_MAX_SIZE, NULL, 0, {0,{0,0,0,0},0,0,0,0,0,0,0,0,0}, {0,{0,0,0,0},0,0,0,0,0,0,0,0,0} }; @@ -758,7 +754,7 @@ DecodeZipEntryText( while (1) { int srcRead, dstWrote; - int result = Tcl_ExternalToUtf(NULL, ZipFS.utf8, src, srcLen, flags, + int result = Tcl_ExternalToUtf(NULL, tclUtf8Encoding, src, srcLen, flags, &state, dst, dstLen, &srcRead, &dstWrote, NULL); int soFar = dst + dstWrote - Tcl_DStringValue(dstPtr); @@ -1875,7 +1871,6 @@ ZipfsSetup(void) ZipFS.fallbackEntryEncoding = (char *) ckalloc(strlen(ZIPFS_FALLBACK_ENCODING) + 1); strcpy(ZipFS.fallbackEntryEncoding, ZIPFS_FALLBACK_ENCODING); - ZipFS.utf8 = Tcl_GetEncoding(NULL, "utf-8"); ZipFS.initialized = 1; Tcl_CreateExitHandler(ZipfsExitHandler, NULL); } @@ -2555,7 +2550,7 @@ ZipAddFile( * crazy enough to embed NULs in filenames, they deserve what they get! */ - zpathExt = Tcl_UtfToExternalDString(ZipFS.utf8, zpathTcl, -1, &zpathDs); + zpathExt = Tcl_UtfToExternalDString(tclUtf8Encoding, zpathTcl, -1, &zpathDs); zpathlen = strlen(zpathExt); if (zpathlen + ZIP_CENTRAL_HEADER_LEN > bufsize) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( @@ -3224,7 +3219,7 @@ ZipFSMkZipOrImg( } z = (ZipEntry *) Tcl_GetHashValue(hPtr); - name = Tcl_UtfToExternalDString(ZipFS.utf8, z->name, -1, &ds); + name = Tcl_UtfToExternalDString(tclUtf8Encoding, z->name, -1, &ds); len = Tcl_DStringLength(&ds); SerializeCentralDirectoryEntry(start, end, (unsigned char *) buf, z, len); -- cgit v0.12