From d28a131ec58dae3ca300c9d56fdffe4e3131ddbc Mon Sep 17 00:00:00 2001 From: auronandace Date: Thu, 4 Jun 2026 11:17:36 +0100 Subject: [PATCH] split out wchar_t from stddef header --- include/stddef.h | 11 +---------- src/header/bits_wchar-t/cbindgen.toml | 18 ++++++++++++++++++ src/header/bits_wchar-t/mod.rs | 1 + src/header/inttypes/cbindgen.toml | 8 ++++---- src/header/mod.rs | 2 ++ 5 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/header/bits_wchar-t/cbindgen.toml create mode 100644 src/header/bits_wchar-t/mod.rs diff --git a/include/stddef.h b/include/stddef.h index 08d83c43a8..7397dc006d 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -3,16 +3,7 @@ // wchar_t should come before NULL and size_t // according to comment in wchar cbindgen -#ifndef _WCHAR_T -#define _WCHAR_T -#ifndef __cplusplus - #ifndef __WCHAR_TYPE__ - #define __WCHAR_TYPE__ int - #endif - typedef __WCHAR_TYPE__ wchar_t; -#endif // __cplusplus -#endif // _WCHAR_T - +#include #include #include diff --git a/src/header/bits_wchar-t/cbindgen.toml b/src/header/bits_wchar-t/cbindgen.toml new file mode 100644 index 0000000000..397c3fde12 --- /dev/null +++ b/src/header/bits_wchar-t/cbindgen.toml @@ -0,0 +1,18 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html +# +# This type is split out to prevent importing all of stddef.h into inttypes.h +include_guard = "_RELIBC_BITS_WCHAR_T_H" +after_includes = """ +#ifndef _WCHAR_T +#define _WCHAR_T +#ifndef __cplusplus + #ifndef __WCHAR_TYPE__ + #define __WCHAR_TYPE__ int + #endif + typedef __WCHAR_TYPE__ wchar_t; +#endif // __cplusplus +#endif // _WCHAR_T +""" +language = "C" +no_includes = true +cpp_compat = true diff --git a/src/header/bits_wchar-t/mod.rs b/src/header/bits_wchar-t/mod.rs new file mode 100644 index 0000000000..755d43c0cd --- /dev/null +++ b/src/header/bits_wchar-t/mod.rs @@ -0,0 +1 @@ +// `wchar_t` is defined in cbindgen diff --git a/src/header/inttypes/cbindgen.toml b/src/header/inttypes/cbindgen.toml index 522dbbb3df..928357354b 100644 --- a/src/header/inttypes/cbindgen.toml +++ b/src/header/inttypes/cbindgen.toml @@ -3,10 +3,10 @@ # Spec quotations relating to includes: # - "The header shall include the header." # - "wchar_t As described in ." -# -# TODO possibly split out wchar_t to avoid including all of stddef.h -# stddef.h also currently includes stdint.h but shouldn't according to the spec -sys_includes = ["stdint.h", "stddef.h"] +sys_includes = ["stdint.h"] +after_includes = """ +#include // for wchar_t from stddef.h +""" include_guard = "_RELIBC_INTTYPES_H" trailer = """ #ifndef _RELIBC_BITS_INTTYPES_H diff --git a/src/header/mod.rs b/src/header/mod.rs index 2d77aa9a1f..49b8fec3a0 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -58,6 +58,8 @@ pub mod bits_timeval; pub mod bits_uid_t; #[path = "bits_useconds-t/mod.rs"] pub mod bits_useconds_t; +#[path = "bits_wchar-t/mod.rs"] +pub mod bits_wchar_t; pub mod bits_winsize; // complex.h implemented in C (currently through openlibm) pub mod cpio;