Threaded allocator cannot be disabled in Tcl 9: -DUSE_THREAD_ALLOC=0 and nmake OPTS=tclalloc ignored
CFLAGS="-O2 -DUSE_THREAD_ALLOC=0" ../unix/configure && make nm tclThreadAlloc.o | grep ' T TclpAlloc' # found: zippy is compiled in nm tclAlloc.o | grep ' T ' # empty
Expected: tclThreadAlloc.c compiles the stub, and TclpAlloc comes from tclAlloc.c (system malloc()).
Cause: generic/tclInt.h has
#if TCL_THREADS && !defined(USE_THREAD_ALLOC) # define USE_THREAD_ALLOC 1 #endif
and every user (tclInt.h, tclAlloc.c, tclThreadAlloc.c, tclBasic.c, tclEvent.c, tclThread.c, unix/tclUnixThrd.c, win/tclWinThrd.c) tests defined(USE_THREAD_ALLOC), not its value. So -DUSE_THREAD_ALLOC=0 means "on", and leaving it undefined also means "on". The default was added in [f2c996cdb8] (2018), when configure stopped defining USE_THREAD_ALLOC=1.
The same applies to the Windows build: nmake -f makefile.vc OPTS=tclalloc sets USE_THREAD_ALLOC = 0 in win/rules.vc, but /DUSE_THREAD_ALLOC is passed only when TCL_VERSION < 87, so for Tcl 9 nothing reaches the compiler and tclInt.h turns the allocator on (found by reading rules.vc, not tested on Windows). In 8.6 OPTS=tclalloc does work.
In 8.6 on Unix, configure always adds -DUSE_THREAD_ALLOC=1 for threaded builds, which is the old RFE [1079199fff]; the workaround there (removing it from Makefile and tclConfig.sh) does not apply to 9.x, where there is nothing to remove.
Seen with 9.0.5 and main (9.1). Possible fix: in tclInt.h, #undef USE_THREAD_ALLOC when it is defined as 0, and let rules.vc pass /DUSE_THREAD_ALLOC=0 for OPTS=tclalloc.
26d3effbc6Fix [31294d48ef]: Threaded allocator cannot be disabled in Tcl 9: -DUSE_THREAD_ALLOC=0 and nmake OPTS=tclalloc ignored check-in2026-10-20 21:11:418a323cc288Fix [31294d48ef]: Threaded allocator cannot be disabled in Tcl 9: -DUSE_THREAD_ALLOC=0 and nmake OPTS=tclalloc ignored check-in2026-10-20 21:08:598fd0f583a9Fix [31294d48ef]: the threaded allocator could not be disabled in Tcl 9: -DUSE_THREAD_ALLOC=0 was treated as defined, and nmake OPTS=tclalloc passed nothing. Undefine USE_THREAD_ALLOC when it is 0, and pass /DUSE_THREAD_ALLOC=0 for OPTS=tclalloc. check-in2026-10-17 12:57:12
Proposed fix in branch thread-alloc-off-switch: tclInt.h undefines USE_THREAD_ALLOC when it is defined as 0, and win/rules.vc passes /DUSE_THREAD_ALLOC=0 for OPTS=tclalloc with Tcl 9. Both a Unix build with CFLAGS=-DUSE_THREAD_ALLOC=0 and an nmake build with OPTS=tclalloc now get TclpAlloc from tclAlloc.c, and pass the tests.
This apparently was an oversight, it should be possible to override this.
+1. Patch looks good to me. Can be merged.
Merged to [trunk] and [core-9-0-branch].
Please don't forget the changes.md/changes entries