relibc: move stddef header from C to cbindgen (integrate upstream 3be84f4b)
Cherry-pick upstream commit 3be84f4b (auronandace, 2026-06-24): - Delete hand-written include/stddef.h - Create src/header/stddef/ with cbindgen.toml + mod.rs - Create src/header/bits_wchar-t/ with cbindgen.toml + mod.rs - Create src/header/bits_size-t/ with cbindgen.toml + mod.rs - Create src/header/bits_null/ with cbindgen.toml + mod.rs - Update src/header/mod.rs: add bits_* modules, uncomment stddef The generated stddef.h now includes modular bits_* sub-headers: #include <bits/wchar-t.h> — wchar_t with _WCHAR_T guard + __WCHAR_TYPE__ #include <bits/size-t.h> — size_t from Rust usize via cbindgen [export] #include <bits/null.h> — NULL: nullptr (C++11), 0L (C++), (void*)0 (C) This fixes the wchar_t circular include issue structurally.
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
#include <stdint.h>
|
||||
|
||||
#define NULL 0
|
||||
|
||||
#ifndef __PTRDIFF_TYPE__
|
||||
#define __PTRDIFF_TYPE__ long int
|
||||
#endif
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
|
||||
typedef long unsigned int size_t;
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef int wchar_t;
|
||||
#endif
|
||||
|
||||
typedef struct { long long __ll; long double __ld; } max_align_t;
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
|
||||
#endif /* _STDDEF_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
# 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 other headers.
|
||||
include_guard = "_RELIBC_BITS_NULL_T_H"
|
||||
language = "C"
|
||||
no_includes = true
|
||||
after_includes = """
|
||||
// Null pointer constant.
|
||||
// Any pointer object whose representation has all bits set to zero, perhaps by
|
||||
// memset() to 0 or by calloc(), shall be treated as a null pointer.
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus >= 201103L
|
||||
#define NULL nullptr
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
"""
|
||||
@@ -0,0 +1,5 @@
|
||||
//! `NULL` from `stddef.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
|
||||
//!
|
||||
//! Implemented via ifdefs and defines in cbindgen.
|
||||
@@ -0,0 +1,11 @@
|
||||
# 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 other headers.
|
||||
include_guard = "_RELIBC_BITS_SIZE_T_H"
|
||||
language = "C"
|
||||
no_includes = true
|
||||
cpp_compat = true
|
||||
[export]
|
||||
include = ["size_t"]
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
@@ -0,0 +1,9 @@
|
||||
//! `size_t` from `stddef.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
|
||||
|
||||
use crate::platform::types::c_ulong;
|
||||
|
||||
/// Unsigned integer type of the result of the sizeof operator.
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type size_t = c_ulong;
|
||||
@@ -0,0 +1,21 @@
|
||||
# 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 = """
|
||||
// Integer type whose range of values can represent distinct codes for all
|
||||
// members of the largest extended character set specified among the supported
|
||||
// locales; the null character shall have the code value zero.
|
||||
#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
|
||||
@@ -0,0 +1,5 @@
|
||||
//! `wchar_t` from `stddef.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
|
||||
//!
|
||||
//! Implemented via ifdefs and defines in cbindgen.
|
||||
+6
-1
@@ -9,14 +9,19 @@ pub mod bits_eventfd;
|
||||
pub mod bits_iovec;
|
||||
#[path = "bits_locale-t/mod.rs"]
|
||||
pub mod bits_locale_t;
|
||||
pub mod bits_null;
|
||||
pub mod bits_pthread;
|
||||
#[path = "bits_safamily-t/mod.rs"]
|
||||
pub mod bits_safamily_t;
|
||||
#[path = "bits_sigset-t/mod.rs"]
|
||||
pub mod bits_sigset_t;
|
||||
#[path = "bits_size-t/mod.rs"]
|
||||
pub mod bits_size_t;
|
||||
#[path = "bits_socklen-t/mod.rs"]
|
||||
pub mod bits_socklen_t;
|
||||
pub mod bits_timespec;
|
||||
#[path = "bits_wchar-t/mod.rs"]
|
||||
pub mod bits_wchar_t;
|
||||
// complex.h implemented in C
|
||||
pub mod cpio;
|
||||
pub mod crypt;
|
||||
@@ -82,7 +87,7 @@ pub mod spawn;
|
||||
// stdarg.h implemented in C
|
||||
// stdatomic.h implemented in C
|
||||
// stdbool.h implemented in C
|
||||
// stddef.h implemented in C
|
||||
pub mod stddef;
|
||||
// stdint.h implemented in C
|
||||
pub mod stdio;
|
||||
pub mod stdlib;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html
|
||||
#
|
||||
# There are no spec quotations relating to includes
|
||||
include_guard = "_RELIBC_STDDEF_H"
|
||||
after_includes = """
|
||||
// wchar_t should come before NULL and size_t
|
||||
// according to comment in wchar cbindgen
|
||||
#include <bits/wchar-t.h>
|
||||
#include <bits/size-t.h>
|
||||
#include <bits/null.h>
|
||||
|
||||
#ifndef __PTRDIFF_TYPE__
|
||||
#define __PTRDIFF_TYPE__ long int
|
||||
#endif
|
||||
// Signed integer type of the result of subtracting two pointers.
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
|
||||
// Object type whose alignment is the greatest fundamental alignment.
|
||||
typedef struct { long long __ll; long double __ld; } max_align_t;
|
||||
|
||||
// Integer constant expression of type size_t, the value of which is the offset
|
||||
// in bytes to the structure member from the beginning of its structure.
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
"""
|
||||
language = "C"
|
||||
no_includes = true
|
||||
cpp_compat = true
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
@@ -0,0 +1,5 @@
|
||||
//! `stddef.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html>.
|
||||
//!
|
||||
//! Implemented via includes, typedefs and defines in cbindgen.
|
||||
Reference in New Issue
Block a user