Move FMTd32-family printf macros to OS layer

Move macros defining the FMT module to OS layer.
This commit is contained in:
guangli-dai 2026-07-28 14:39:30 -07:00 committed by Guangli Dai
parent 21ddfb1e8e
commit 1ec505b751
5 changed files with 78 additions and 30 deletions

View file

@ -3,36 +3,15 @@
#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/jemalloc_internal_types.h"
#ifdef _WIN32
# ifdef _WIN64
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX "ll"
# else
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX ""
# endif
# define FMTd32 "d"
# define FMTu32 "u"
# define FMTx32 "x"
# define FMTd64 FMT64_PREFIX "d"
# define FMTu64 FMT64_PREFIX "u"
# define FMTx64 FMT64_PREFIX "x"
# define FMTdPTR FMTPTR_PREFIX "d"
# define FMTuPTR FMTPTR_PREFIX "u"
# define FMTxPTR FMTPTR_PREFIX "x"
#else
# include <inttypes.h>
# define FMTd32 PRId32
# define FMTu32 PRIu32
# define FMTx32 PRIx32
# define FMTd64 PRId64
# define FMTu64 PRIu64
# define FMTx64 PRIx64
# define FMTdPTR PRIdPTR
# define FMTuPTR PRIuPTR
# define FMTxPTR PRIxPTR
#endif
/*
* os/fmt.h directly (not the os.h umbrella): this header is itself included
* from os/posix/error.h (for malloc_snprintf's declaration), so pulling in
* the full os.h here would risk the same circular-include hazard os/error.h
* avoids by not going through the umbrella either. os/fmt.h is a leaf module
* (macros only, no dependency back on malloc_io.h or anything else), so
* including it alone is safe.
*/
#include "jemalloc/internal/os/fmt.h"
/* Size of stack-allocated buffer passed to buferror(). */
#define BUFERROR_BUF 64

View file

@ -56,4 +56,11 @@
*/
#include "jemalloc/internal/os/error.h"
/*
* Printf format-specifier macros. malloc_io.h includes os/fmt.h directly
* (not via this umbrella) for the same early-reachability reason as
* os/error.h above. Included here too for discoverability.
*/
#include "jemalloc/internal/os/fmt.h"
#endif /* JEMALLOC_INTERNAL_OS_H */

View file

@ -0,0 +1,25 @@
#ifndef JEMALLOC_INTERNAL_OS_FMT_H
#define JEMALLOC_INTERNAL_OS_FMT_H
#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/os/detect.h"
/*
* Printf format-specifier macros for fixed-width and pointer-sized integers
* (FMTd32/FMTu32/FMTx32/FMTd64/FMTu64/FMTx64/FMTdPTR/FMTuPTR/FMTxPTR).
* Default: posix/ (<inttypes.h>'s PRId32 etc). Override: Windows (MSVC's
* CRT historically didn't support the C99 <inttypes.h> macros the same way,
* so these are hand-rolled from an ll/I64-style prefix instead).
*
* Unlike other modules, this one defines only macros, no functions.
*/
#if defined(_WIN32)
# include "jemalloc/internal/os/windows/fmt.h"
#elif defined(JEMALLOC_OS_POSIX)
# include "jemalloc/internal/os/posix/fmt.h"
#else
# error "OS layer: no fmt backend for this platform; add os/<os>/fmt.h"
#endif
#endif /* JEMALLOC_INTERNAL_OS_FMT_H */

View file

@ -0,0 +1,16 @@
#ifndef JEMALLOC_INTERNAL_OS_POSIX_FMT_H
#define JEMALLOC_INTERNAL_OS_POSIX_FMT_H
#include <inttypes.h>
#define FMTd32 PRId32
#define FMTu32 PRIu32
#define FMTx32 PRIx32
#define FMTd64 PRId64
#define FMTu64 PRIu64
#define FMTx64 PRIx64
#define FMTdPTR PRIdPTR
#define FMTuPTR PRIuPTR
#define FMTxPTR PRIxPTR
#endif /* JEMALLOC_INTERNAL_OS_POSIX_FMT_H */

View file

@ -0,0 +1,21 @@
#ifndef JEMALLOC_INTERNAL_OS_WINDOWS_FMT_H
#define JEMALLOC_INTERNAL_OS_WINDOWS_FMT_H
#ifdef _WIN64
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX "ll"
#else
# define FMT64_PREFIX "ll"
# define FMTPTR_PREFIX ""
#endif
#define FMTd32 "d"
#define FMTu32 "u"
#define FMTx32 "x"
#define FMTd64 FMT64_PREFIX "d"
#define FMTu64 FMT64_PREFIX "u"
#define FMTx64 FMT64_PREFIX "x"
#define FMTdPTR FMTPTR_PREFIX "d"
#define FMTuPTR FMTPTR_PREFIX "u"
#define FMTxPTR FMTPTR_PREFIX "x"
#endif /* JEMALLOC_INTERNAL_OS_WINDOWS_FMT_H */