From d28963d88ed93a92a9e5df674dd7e8a419927663 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Sat, 27 Jun 2026 14:22:45 +0300 Subject: [PATCH] Fix wchar.h circular include: define types before stdio.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit relibc's wchar.h included before defining wint_t and mbstate_t. The circular chain wchar.h → stdio.h → inttypes.h → wchar.h caused gnulib's wchar.h wrapper (used by m4, bison, etc.) to see 'unknown type name wint_t' and 'unknown type name mbstate_t'. Fix: Move stdio.h and time.h from sys_includes (which cbindgen emits before type definitions) into after_includes, after wchar_t, wint_t, and mbstate_t are defined. Also define mbstate_t manually in after_includes with a guard, and exclude it from cbindgen export to prevent duplicate definitions. --- src/header/wchar/cbindgen.toml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/header/wchar/cbindgen.toml b/src/header/wchar/cbindgen.toml index a31881baad..77b888b105 100644 --- a/src/header/wchar/cbindgen.toml +++ b/src/header/wchar/cbindgen.toml @@ -1,8 +1,4 @@ -sys_includes = [ - "stdio.h", - "time.h", - "features.h", -] +sys_includes = ["features.h"] after_includes = """ // int32_t, uint32_t, WCHAR_MIN, WCHAR_MAX #include @@ -25,6 +21,21 @@ after_includes = """ typedef __WINT_TYPE__ wint_t; #endif // _WINT_T +// Define mbstate_t before headers that may transitively re-include wchar.h. +// The circular chain wchar.h → stdio.h → inttypes.h → wchar.h (and also +// stdlib.h → wchar.h) would otherwise cause wint_t and mbstate_t to be +// undefined in gnulib's wchar.h wrapper, breaking m4, bison, and other +// gnulib-based packages. +#ifndef _RELIBC_MBSTATE_T +#define _RELIBC_MBSTATE_T +typedef struct {} mbstate_t; +#endif + +// Now include headers that depend on wchar_t/wint_t/mbstate_t. +// These must come after the type definitions to break circular includes. +#include +#include + // NULL, size_t, must come after wchar_t and wint_t #define __need_size_t #define __need_NULL @@ -38,6 +49,9 @@ style = "Type" no_includes = true cpp_compat = true +[export] +exclude = ["mbstate_t"] + [export.rename] "tm" = "struct tm"