Tcl Source Code

View Ticket
Login
Ticket UUID: 31294d48efe6ead48dcd44677774b026045d5cb6
Title: Threaded allocator cannot be disabled in Tcl 9: -DUSE_THREAD_ALLOC=0 and nmake OPTS=tclalloc ignored
Type: Bug Created on: 2026-10-17 10:51:11
Submitter: serhiy.storchaka Assigned to: aku
Subsystem: 41. Memory Allocation Severity: Minor
Priority: 5 Medium Last modified: 2026-10-20 21:26:21
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2026-10-20 21:26:21
Version: 9.0.5, 9.1.0
Description:

In Tcl 9 there is no way to build without the threaded ("zippy") allocator, other than PURIFY or TCL_MEM_DEBUG. Asking for it explicitly is silently 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.

User Comments:
serhiy.storchaka added on 2026-10-17 13:04:57:

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.


jan.nijtmans added on 2026-10-20 20:42:12:

This apparently was an oversight, it should be possible to override this.

+1. Patch looks good to me. Can be merged.


serhiy.storchaka added on 2026-10-20 21:14:09:

Merged to [8a323cc288|trunk] and [26d3effbc6|core-9-0-branch].


jan.nijtmans added on 2026-10-20 21:26:21:

Please don't forget the changes.md/changes entries