diff --git a/port/shim/stddef.h b/port/shim/stddef.h index 6ca71639..8ab11307 100644 --- a/port/shim/stddef.h +++ b/port/shim/stddef.h @@ -25,15 +25,33 @@ #undef __need_NULL #undef __need_wint_t #include "hoststddef.h" +#elif defined(_WIN32) +/* + * C TUs on MinGW: keep the empty N64 include/stddef.h stub. MinGW's CRT + * headers leak size_t/ptrdiff_t transitively, and its own drags in + * the `#define errno (*_errno())` CRT macro, which collides with PR/os.h's + * `u8 errno;` struct field — so routing to the host header is not an option + * here. + */ +#include "include/stddef.h" #else /* - * C TUs: the N64 include/stddef.h is an empty stub (its active body defines - * neither size_t nor ptrdiff_t nor NULL). MinGW leaked those in transitively - * through its CRT headers, so the stub was harmless there; glibc/GCC defines - * them ONLY in the compiler's own , so a C TU on Linux that relies - * on (e.g. include/PR/ultratypes.h's non-N64 path) fails to - * compile. Route C TUs to the host header too — purely additive, the active - * N64 stub typedefs nothing that could clash. + * C TUs on Linux/macOS: the N64 include/stddef.h stub defines nothing, glibc + * only defines these in the compiler's shadowed builtin , and the + * MinGW hoststddef trick (bin/../include/stddef.h) does not exist on Linux. + * Provide the standard types straight from the always-predefined GCC/Clang + * builtins — no header, so nothing to collide with. C11 permits the benign + * identical redefinition if a real is ever reached another way. */ -#include "hoststddef.h" +#ifndef _PORT_SHIM_STDDEF_TYPES +#define _PORT_SHIM_STDDEF_TYPES +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; +#ifndef NULL +#define NULL ((void *)0) +#endif +#ifndef offsetof +#define offsetof(t, m) __builtin_offsetof(t, m) +#endif +#endif #endif