From e7f1b117d458e202498f0a3862761661c26ca7ae Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Wed, 18 Mar 2026 15:54:19 +0200 Subject: [PATCH] utils: Avoid overexpanding on 32 bit The 32bit compilers can't handle over expansion and run out of virtual memory. Signed-off-by: Pantelis Antoniou --- include/libfyaml/libfyaml-util.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/libfyaml/libfyaml-util.h b/include/libfyaml/libfyaml-util.h index b0c1126b..24e5709a 100644 --- a/include/libfyaml/libfyaml-util.h +++ b/include/libfyaml/libfyaml-util.h @@ -797,7 +797,11 @@ static inline char *fy_alloca_vsprintf_impl(const char *fmt, va_list ap) #define _E8(...) _E4(_E4(__VA_ARGS__)) #define _E16(...) _E8(_E8(__VA_ARGS__)) #define _E32(...) _E16(_E16(__VA_ARGS__)) +#if !defined(__SIZEOF_POINTER__) || __SIZEOF_POINTER__ >= 8 #define _E(...) _E32(_E32(__VA_ARGS__)) +#else +#define _E(...) _E16(_E16(__VA_ARGS__)) +#endif #define _FMT() #define _FP1(m) m _FMT() @@ -1054,12 +1058,12 @@ static inline char *fy_alloca_vsprintf_impl(const char *fmt, va_list ap) #define FY_CPP_EVAL2(...) FY_CPP_EVAL1(FY_CPP_EVAL1(__VA_ARGS__)) #define FY_CPP_EVAL4(...) FY_CPP_EVAL2(FY_CPP_EVAL2(__VA_ARGS__)) #define FY_CPP_EVAL8(...) FY_CPP_EVAL4(FY_CPP_EVAL4(__VA_ARGS__)) -#if !defined(__clang__) -// gcc is better, goes to 16 +#if !defined(__clang__) && (!defined(__SIZEOF_POINTER__) || __SIZEOF_POINTER__ >= 8) +// 64-bit gcc can afford the deeper expansion tree. #define FY_CPP_EVAL16(...) FY_CPP_EVAL8(FY_CPP_EVAL8(__VA_ARGS__)) #define FY_CPP_EVAL(...) FY_CPP_EVAL16(FY_CPP_EVAL16(__VA_ARGS__)) #else -// clang craps out at 8 +// clang and 32-bit builds use a shallower expansion tree to keep cc1 memory use in check. #define FY_CPP_EVAL(...) FY_CPP_EVAL8(FY_CPP_EVAL8(__VA_ARGS__)) #endif