From 366bfc781b735cee1622ddb7a1e259b375a98cca Mon Sep 17 00:00:00 2001 From: Xin Yang Date: Fri, 23 May 2025 16:00:55 +0800 Subject: [PATCH] Derive arena constants from MALLOCX_ARENA_BITS Replaces the hardcoded values for `MALLCTL_ARENAS_ALL` and `MALLCTL_ARENAS_DESTROYED` with expressions derived from `MALLOCX_ARENA_BITS`. This prevents a potential crash (e.g., in stats printing) that would occur if `MALLOCX_ARENA_BITS` were changed while these macro values remained hardcoded. Signed-off-by: Xin Yang --- include/jemalloc/jemalloc_macros.h.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/jemalloc/jemalloc_macros.h.in b/include/jemalloc/jemalloc_macros.h.in index 06f47b8a..c0bef93d 100644 --- a/include/jemalloc/jemalloc_macros.h.in +++ b/include/jemalloc/jemalloc_macros.h.in @@ -44,12 +44,12 @@ * mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL, NULL, * 0); */ -#define MALLCTL_ARENAS_ALL 4096 +#define MALLCTL_ARENAS_ALL (1U << MALLOCX_ARENA_BITS) /* * Use as arena index in "stats.arenas..*" mallctl interfaces to select * destroyed arenas. */ -#define MALLCTL_ARENAS_DESTROYED 4097 +#define MALLCTL_ARENAS_DESTROYED ((1U << MALLOCX_ARENA_BITS) + 1) #if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW) # define JEMALLOC_CXX_THROW noexcept (true)