From c28fb81c1299e87584ea2ecd22107f3649d6d20b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 20 Oct 2023 08:24:47 +0000 Subject: Fix [9d216917e]: nmakehlp.c: remove unused include math.h --- win/nmakehlp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/win/nmakehlp.c b/win/nmakehlp.c index c8b39a7..b0799f8 100644 --- a/win/nmakehlp.c +++ b/win/nmakehlp.c @@ -19,7 +19,6 @@ #pragma comment (lib, "kernel32.lib") #endif #include -#include /* * This library is required for x64 builds with _some_ versions of MSVC @@ -272,7 +271,7 @@ CheckForCompilerFeature( if (!ok) { DWORD err = GetLastError(); int chars = snprintf(msg, sizeof(msg) - 1, - "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err); + "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS| FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars], @@ -406,7 +405,7 @@ CheckForLinkerFeature( if (!ok) { DWORD err = GetLastError(); int chars = snprintf(msg, sizeof(msg) - 1, - "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err); + "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS| FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars], -- cgit v0.12 From 0da684fdc5bb947113ddb2a6760ade2b688fe36b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 20 Oct 2023 09:35:20 +0000 Subject: (cherrypick) small part of: [26870862f0]: Wrong sentinel in Tcl_SetErrorCode usage; Handle any C++-compiler as well --- compat/zlib/contrib/minizip/crypt.h | 2 +- libtommath/bn_mp_div.c | 4 ++-- libtommath/bn_s_mp_balance_mul.c | 4 ++-- libtommath/bn_s_mp_toom_mul.c | 4 ++-- unix/dltest/pkgb.c | 2 +- unix/dltest/pkgooa.c | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compat/zlib/contrib/minizip/crypt.h b/compat/zlib/contrib/minizip/crypt.h index f4b93b7..8bde464 100644 --- a/compat/zlib/contrib/minizip/crypt.h +++ b/compat/zlib/contrib/minizip/crypt.h @@ -50,7 +50,7 @@ static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) (*(pkeys+1)) += (*(pkeys+0)) & 0xff; (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; { - register int keyshift = (int)((*(pkeys+1)) >> 24); + int keyshift = (int)((*(pkeys+1)) >> 24); (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); } return c; diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c index 71de55b..bca227d 100644 --- a/libtommath/bn_mp_div.c +++ b/libtommath/bn_mp_div.c @@ -31,7 +31,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) } /* init our temps */ - if ((err = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) { + if ((err = mp_init_multi(&ta, &tb, &tq, &q, (void *)NULL)) != MP_OKAY) { return err; } @@ -64,7 +64,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) d->sign = MP_IS_ZERO(d) ? MP_ZPOS : n; } LBL_ERR: - mp_clear_multi(&ta, &tb, &tq, &q, NULL); + mp_clear_multi(&ta, &tb, &tq, &q, (void *)NULL); return err; } diff --git a/libtommath/bn_s_mp_balance_mul.c b/libtommath/bn_s_mp_balance_mul.c index 7ece5d7..557cc1d 100644 --- a/libtommath/bn_s_mp_balance_mul.c +++ b/libtommath/bn_s_mp_balance_mul.c @@ -19,7 +19,7 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) if ((err = mp_init_size(&a0, bsize + 2)) != MP_OKAY) { return err; } - if ((err = mp_init_multi(&tmp, &r, NULL)) != MP_OKAY) { + if ((err = mp_init_multi(&tmp, &r, (void *)NULL)) != MP_OKAY) { mp_clear(&a0); return err; } @@ -75,7 +75,7 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) mp_exch(&r,c); LBL_ERR: - mp_clear_multi(&a0, &tmp, &r,NULL); + mp_clear_multi(&a0, &tmp, &r, (void *)NULL); return err; } #endif diff --git a/libtommath/bn_s_mp_toom_mul.c b/libtommath/bn_s_mp_toom_mul.c index 86901b0..c7db3a5 100644 --- a/libtommath/bn_s_mp_toom_mul.c +++ b/libtommath/bn_s_mp_toom_mul.c @@ -36,7 +36,7 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) mp_err err; /* init temps */ - if ((err = mp_init_multi(&S1, &S2, &T1, NULL)) != MP_OKAY) { + if ((err = mp_init_multi(&S1, &S2, &T1, (void *)NULL)) != MP_OKAY) { return err; } @@ -208,7 +208,7 @@ LBL_ERRa2: LBL_ERRa1: mp_clear(&a0); LBL_ERRa0: - mp_clear_multi(&S1, &S2, &T1, NULL); + mp_clear_multi(&S1, &S2, &T1, (void *)NULL); return err; } diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index b221518..75d1eac 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -56,7 +56,7 @@ Pkgb_SubObjCmd( || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { char buf[TCL_INTEGER_SPACE]; snprintf(buf, sizeof(buf), "%d", Tcl_GetErrorLine(interp)); - Tcl_AppendResult(interp, " in line: ", buf, NULL); + Tcl_AppendResult(interp, " in line: ", buf, (void *)NULL); return TCL_ERROR; } Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); diff --git a/unix/dltest/pkgooa.c b/unix/dltest/pkgooa.c index aed89fe..6a78692 100644 --- a/unix/dltest/pkgooa.c +++ b/unix/dltest/pkgooa.c @@ -108,18 +108,18 @@ Pkgooa_Init( } if (tclStubsPtr == NULL) { Tcl_AppendResult(interp, "Tcl stubs are not initialized, " - "did you compile using -DUSE_TCL_STUBS? ", NULL); + "did you compile using -DUSE_TCL_STUBS? ", (void *)NULL); return TCL_ERROR; } if (Tcl_OOInitStubs(interp) == NULL) { return TCL_ERROR; } if (tclOOStubsPtr == NULL) { - Tcl_AppendResult(interp, "TclOO stubs are not initialized", NULL); + Tcl_AppendResult(interp, "TclOO stubs are not initialized", (void *)NULL); return TCL_ERROR; } if (tclOOIntStubsPtr == NULL) { - Tcl_AppendResult(interp, "TclOO internal stubs are not initialized", NULL); + Tcl_AppendResult(interp, "TclOO internal stubs are not initialized", (void *)NULL); return TCL_ERROR; } -- cgit v0.12 From 6aa2bc6d5c78c18a1562bdae776914890037f24f Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 20 Oct 2023 16:53:14 +0000 Subject: Add test to trigger bug 33b2486199 --- tests/zipfs.test | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/zipfs.test b/tests/zipfs.test index c1cde5e..d8817f8 100644 --- a/tests/zipfs.test +++ b/tests/zipfs.test @@ -19,6 +19,7 @@ if {"::tcltest" ni [namespace children]} { source [file join [file dirname [info script]] tcltests.tcl] testConstraint zipfs [expr {[llength [info commands zipfs]]}] +testConstraint thread [expr {0 == [catch {package require Thread 2.8-}]}] set ziproot [zipfs root] @@ -1923,6 +1924,14 @@ namespace eval test_ns_zipfs { zipfs unmount $mt } -result "" + test bug-33b2486199 "zipfs unmounted on thread exit" -constraints { + thread + } -body { + set before [lsort [zipfs mount]] + thread::release [thread::create] + after 100; # Needed to allow the spawned thread to exit to trigger bug + string equal $before [lsort [zipfs mount]] + } -result 1 } -- cgit v0.12 From d5396e3590b3fbcab61454db55688bd81fe1a59d Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 20 Oct 2023 17:01:48 +0000 Subject: Potential fix --- generic/tclZipfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 6ef921a..c7a194a 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -6287,6 +6287,9 @@ ZipfsAppHookFindTclInit( void TclZipfsFinalize(void) { + if (!TclInExit()) + return; + /* * Finalization steps: * For every mounted archive, if it no longer has any open handles -- cgit v0.12 From a21682acad5156d66092b97a3072e5ace01234b0 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sat, 21 Oct 2023 04:14:33 +0000 Subject: Move zipfs finalization to TclFinalizeFilesystem --- generic/tclIO.c | 1 - generic/tclIOUtil.c | 1 + generic/tclZipfs.c | 58 ++++++++++++++++++++++++++--------------------------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index d79397b..0d047aa 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -706,7 +706,6 @@ TclFinalizeIOSubsystem(void) TclpFinalizeSockets(); TclpFinalizePipes(); - TclZipfsFinalize(); } /* diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 2cb22f5..7719f35 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -761,6 +761,7 @@ TclFinalizeFilesystem(void) * needed. */ + TclZipfsFinalize(); fsRecPtr = filesystemList; while (fsRecPtr != NULL) { FilesystemRecord *tmpFsRecPtr = fsRecPtr->nextPtr; diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index c7a194a..9372079 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -6285,18 +6285,25 @@ ZipfsAppHookFindTclInit( } #endif +/* + *------------------------------------------------------------------------ + * + * TclZipfsFinalize -- + * + * Frees all zipfs resources IRRESPECTIVE of open channels (there should + * not be any!) etc. To be called at process exit time (from + * Tcl_Finalize->TclFinalizeFilesystem) + * + * Results: + * None. + * + * Side effects: + * Frees up archives loaded into memory. + * + *------------------------------------------------------------------------ + */ void TclZipfsFinalize(void) { - if (!TclInExit()) - return; - - /* - * Finalization steps: - * For every mounted archive, if it no longer has any open handles - * clean up the mount and associated zip file entries. - * If there are no more mounted archives, clean up and free the - * ZipFS.fileHash and ZipFS.zipHash tables. - */ WriteLock(); if (!ZipFS.initialized) { Unlock(); @@ -6308,30 +6315,21 @@ void TclZipfsFinalize(void) for (hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &zipSearch); hPtr; hPtr = Tcl_NextHashEntry(&zipSearch)) { ZipFile *zf = (ZipFile *) Tcl_GetHashValue(hPtr); - if (zf->numOpen == 0) { - Tcl_DeleteHashEntry(hPtr); - CleanupMount(zf); - ZipFSCloseArchive(NULL, zf); - ckfree(zf); - } + Tcl_DeleteHashEntry(hPtr); + CleanupMount(zf); /* Frees file entries belonging to the archive */ + ZipFSCloseArchive(NULL, zf); + ckfree(zf); } - hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &zipSearch); - if (hPtr == NULL) { - hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &zipSearch); - if (hPtr == NULL) { - /* Both hash tables empty. Free all resources */ - Tcl_FSUnregister(&zipfsFilesystem); - Tcl_DeleteHashTable(&ZipFS.fileHash); - Tcl_DeleteHashTable(&ZipFS.zipHash); - if (ZipFS.fallbackEntryEncoding) { - ckfree(ZipFS.fallbackEntryEncoding); - ZipFS.fallbackEntryEncoding = NULL; - } - ZipFS.initialized = 0; - } + Tcl_FSUnregister(&zipfsFilesystem); + Tcl_DeleteHashTable(&ZipFS.fileHash); + Tcl_DeleteHashTable(&ZipFS.zipHash); + if (ZipFS.fallbackEntryEncoding) { + ckfree(ZipFS.fallbackEntryEncoding); + ZipFS.fallbackEntryEncoding = NULL; } + ZipFS.initialized = 0; Unlock(); } -- cgit v0.12