| 
20 | 20 |  * modules.  | 
21 | 21 |  */  | 
22 | 22 | #if defined(__MVS__) && __has_include_next(<stddef.h>)  | 
23 |  | -#include <__stddef_header_macro.h>  | 
24 | 23 | #undef __need_ptrdiff_t  | 
25 | 24 | #undef __need_size_t  | 
26 | 25 | #undef __need_rsize_t  | 
 | 
31 | 30 | #undef __need_max_align_t  | 
32 | 31 | #undef __need_offsetof  | 
33 | 32 | #undef __need_wint_t  | 
 | 33 | +#include <__stddef_header_macro.h>  | 
34 | 34 | #include_next <stddef.h>  | 
35 | 35 | 
 
  | 
36 | 36 | #else  | 
 | 
40 | 40 |     !defined(__need_NULL) && !defined(__need_nullptr_t) &&                     \  | 
41 | 41 |     !defined(__need_unreachable) && !defined(__need_max_align_t) &&            \  | 
42 | 42 |     !defined(__need_offsetof) && !defined(__need_wint_t)  | 
43 |  | -#include <__stddef_header_macro.h>  | 
44 | 43 | #define __need_ptrdiff_t  | 
45 | 44 | #define __need_size_t  | 
46 | 45 | /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is  | 
 | 
49 | 48 | #define __need_rsize_t  | 
50 | 49 | #endif  | 
51 | 50 | #define __need_wchar_t  | 
 | 51 | +#if !defined(__STDDEF_H) || __has_feature(modules)  | 
 | 52 | +/*  | 
 | 53 | + * __stddef_null.h is special when building without modules: if __need_NULL is  | 
 | 54 | + * set, then it will unconditionally redefine NULL. To avoid stepping on client  | 
 | 55 | + * definitions of NULL, __need_NULL should only be set the first time this  | 
 | 56 | + * header is included, that is when __STDDEF_H is not defined. However, when  | 
 | 57 | + * building with modules, this header is a textual header and needs to  | 
 | 58 | + * unconditionally include __stdef_null.h to support multiple submodules  | 
 | 59 | + * exporting _Builtin_stddef.null. Take module SM with submodules A and B, whose  | 
 | 60 | + * headers both include stddef.h When SM.A builds, __STDDEF_H will be defined.  | 
 | 61 | + * When SM.B builds, the definition from SM.A will leak when building without  | 
 | 62 | + * local submodule visibility. stddef.h wouldn't include __stddef_null.h, and  | 
 | 63 | + * SM.B wouldn't import _Builtin_stddef.null, and SM.B's `export *` wouldn't  | 
 | 64 | + * export NULL as expected. When building with modules, always include  | 
 | 65 | + * __stddef_null.h so that everything works as expected.  | 
 | 66 | + */  | 
52 | 67 | #define __need_NULL  | 
 | 68 | +#endif  | 
53 | 69 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||              \  | 
54 | 70 |     defined(__cplusplus)  | 
55 | 71 | #define __need_nullptr_t  | 
 | 
65 | 81 | /* wint_t is provided by <wchar.h> and not <stddef.h>. It's here  | 
66 | 82 |  * for compatibility, but must be explicitly requested. Therefore  | 
67 | 83 |  * __need_wint_t is intentionally not defined here. */  | 
 | 84 | +#include <__stddef_header_macro.h>  | 
68 | 85 | #endif  | 
69 | 86 | 
 
  | 
70 | 87 | #if defined(__need_ptrdiff_t)  | 
 | 
0 commit comments