From 93d6fc091fd5fb20846d60fb52c41cc967b4c963 Mon Sep 17 00:00:00 2001 From: auronandace Date: Fri, 3 Jul 2026 14:23:00 +0100 Subject: [PATCH] refactor sys_types_internal to reduce namespace pollution --- src/header/mod.rs | 2 +- src/header/spawn/spawn_attr.rs | 12 +++--- src/header/sys_types/cbindgen.toml | 42 +++++++++++++++---- src/header/sys_types/mod.rs | 25 +++++++++++ src/header/sys_types_extra/cbindgen.toml | 18 ++++++++ src/header/sys_types_extra/mod.rs | 26 ++++++++++++ src/header/sys_types_internal/cbindgen.toml | 42 ------------------- src/header/sys_types_internal/mod.rs | 46 --------------------- 8 files changed, 111 insertions(+), 102 deletions(-) create mode 100644 src/header/sys_types_extra/cbindgen.toml create mode 100644 src/header/sys_types_extra/mod.rs delete mode 100644 src/header/sys_types_internal/cbindgen.toml delete mode 100644 src/header/sys_types_internal/mod.rs diff --git a/src/header/mod.rs b/src/header/mod.rs index b7f42cf302..83265bc1ff 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -177,7 +177,7 @@ pub mod sys_random; pub mod sys_syslog; pub mod sys_types; #[allow(non_camel_case_types)] -pub mod sys_types_internal; +pub mod sys_types_extra; pub mod sys_uio; pub mod sys_un; pub mod sys_utsname; diff --git a/src/header/spawn/spawn_attr.rs b/src/header/spawn/spawn_attr.rs index 2e8715417d..2c541585eb 100644 --- a/src/header/spawn/spawn_attr.rs +++ b/src/header/spawn/spawn_attr.rs @@ -5,11 +5,13 @@ use core::{ use bitflags; -use crate::header::{ - bits_sigset_t::sigset_t, - errno::EINVAL, - sched::{SCHED_FIFO, SCHED_OTHER, SCHED_RR, sched_param}, - sys_types_internal::pid_t, +use crate::{ + header::{ + bits_sigset_t::sigset_t, + errno::EINVAL, + sched::{SCHED_FIFO, SCHED_OTHER, SCHED_RR, sched_param}, + }, + platform::types::pid_t, }; bitflags::bitflags! { diff --git a/src/header/sys_types/cbindgen.toml b/src/header/sys_types/cbindgen.toml index 46bfa12592..0f4f6a5b66 100644 --- a/src/header/sys_types/cbindgen.toml +++ b/src/header/sys_types/cbindgen.toml @@ -2,15 +2,41 @@ # # There are no spec quotations relating to includes # -# - sys/types/internal.h are fundamental C types -# - sys/types/internal.h brings in features.h for deprecated annotations for useconds_t -# - bits/pthread.h is separate for convenience -sys_includes = [ - # Import most necessary, internal types first - "sys/types/internal.h", - "bits/pthread.h", -] +# TODO figure out how to handle useconds namespace pollution +# +# bits/useconds-t.h brings in features.h for deprecated annotation +# bits/pthread.h is separate for convenience include_guard = "_RELIBC_SYS_TYPES_H" +after_includes = """ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // for size_t from stddef.h +#include +#include +#include // for blkcnt_t and blksize_t +#include // for fsblkcnt_t and fsfilcnt_t +#include +#include +#include +#include // from older POSIX + +// Non-POSIX extras musl has guarded +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +#include +#endif + +#include +""" no_includes = true language = "C" diff --git a/src/header/sys_types/mod.rs b/src/header/sys_types/mod.rs index 601f262aac..5858f61d0d 100644 --- a/src/header/sys_types/mod.rs +++ b/src/header/sys_types/mod.rs @@ -6,3 +6,28 @@ //! removed in the Open Group Base Specifications Issue 7, see //! //! for the old specification. + +#[expect(deprecated)] +pub use crate::header::bits_useconds_t::useconds_t; +pub use crate::header::{ + bits_clock_t::clock_t, + bits_clockid_t::clockid_t, + bits_dev_t::dev_t, + bits_gid_t::gid_t, + bits_id_t::id_t, + bits_ino_t::ino_t, + bits_key_t::key_t, + bits_mode_t::mode_t, + bits_nlink_t::nlink_t, + bits_off_t::off_t, + bits_pid_t::pid_t, + bits_reclen_t::reclen_t, + bits_size_t::size_t, + bits_ssize_t::ssize_t, + bits_suseconds_t::suseconds_t, + bits_sys_stat::{blkcnt_t, blksize_t}, + bits_sys_statvfs::{fsblkcnt_t, fsfilcnt_t}, + bits_time_t::time_t, + bits_timer_t::timer_t, + bits_uid_t::uid_t, +}; diff --git a/src/header/sys_types_extra/cbindgen.toml b/src/header/sys_types_extra/cbindgen.toml new file mode 100644 index 0000000000..a36be0c8c3 --- /dev/null +++ b/src/header/sys_types_extra/cbindgen.toml @@ -0,0 +1,18 @@ +include_guard = "_RELIBC_SYS_TYPES_EXTRA_H" +language = "C" +no_includes = true + +[export] +include = [ + "u_char", + "uchar", + "u_short", + "ushort", + "u_int", + "uint", + "u_long", + "ulong", + "quad_t", + "u_quad_t", + "caddr_t" +] diff --git a/src/header/sys_types_extra/mod.rs b/src/header/sys_types_extra/mod.rs new file mode 100644 index 0000000000..106eb599e9 --- /dev/null +++ b/src/header/sys_types_extra/mod.rs @@ -0,0 +1,26 @@ +//! Non-POSIX extras for `sys/types.h` implementation. + +use crate::platform::types::{c_char, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort}; + +/// Intended as a convenience type. +pub type u_char = c_uchar; +/// Sys V compatibility type. +pub type uchar = c_uchar; +/// Intended as a convenience type. +pub type u_short = c_ushort; +/// Sys V compatibility type. +pub type ushort = c_ushort; +/// Intended as a convenience type. +pub type u_int = c_uint; +/// Sys V compatibility type. +pub type uint = c_uint; +/// Intended as a convenience type. +pub type u_long = c_ulong; +/// Sys V compatibility type. +pub type ulong = c_ulong; +/// Always 64bit, always `long long`. +pub type quad_t = c_longlong; +/// Always 64bit, always `unsigned long long`. +pub type u_quad_t = c_ulonglong; +/// Legacy BSD type. +pub type caddr_t = *mut c_char; diff --git a/src/header/sys_types_internal/cbindgen.toml b/src/header/sys_types_internal/cbindgen.toml deleted file mode 100644 index 982ade0f05..0000000000 --- a/src/header/sys_types_internal/cbindgen.toml +++ /dev/null @@ -1,42 +0,0 @@ -# bits/useconds-t.h brings in features.h for deprecated annotation -after_includes = """ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // for size_t from stddef.h -#include -#include -#include // for blkcnt_t and blksize_t -#include // for fsblkcnt_t and fsfilcnt_t -#include -#include -#include -#include // from older POSIX -""" -include_guard = "_RELIBC_SYS_TYPES_INTERNAL_H" -language = "C" -no_includes = true - -[export] -include = [ - "u_char", - "uchar", - "u_short", - "ushort", - "u_int", - "uint", - "u_long", - "ulong", - "quad_t", - "u_quad_t", - "caddr_t" -] diff --git a/src/header/sys_types_internal/mod.rs b/src/header/sys_types_internal/mod.rs deleted file mode 100644 index a566002380..0000000000 --- a/src/header/sys_types_internal/mod.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! `sys/types.h` implementation. -//! -//! See . -//! -//! Note that the `useconds_t` type provided in the `sys/types.h` header was -//! removed in the Open Group Base Specifications Issue 7, see -//! -//! for the old specification. - -#[expect(deprecated)] -pub use crate::header::bits_useconds_t::useconds_t; -pub use crate::header::{ - bits_clock_t::clock_t, - bits_clockid_t::clockid_t, - bits_dev_t::dev_t, - bits_gid_t::gid_t, - bits_id_t::id_t, - bits_ino_t::ino_t, - bits_key_t::key_t, - bits_mode_t::mode_t, - bits_nlink_t::nlink_t, - bits_off_t::off_t, - bits_pid_t::pid_t, - bits_reclen_t::reclen_t, - bits_size_t::size_t, - bits_ssize_t::ssize_t, - bits_suseconds_t::suseconds_t, - bits_sys_stat::{blkcnt_t, blksize_t}, - bits_sys_statvfs::{fsblkcnt_t, fsfilcnt_t}, - bits_time_t::time_t, - bits_timer_t::timer_t, - bits_uid_t::uid_t, -}; -use crate::platform::types::{c_char, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort}; - -pub type u_char = c_uchar; -pub type uchar = c_uchar; -pub type u_short = c_ushort; -pub type ushort = c_ushort; -pub type u_int = c_uint; -pub type uint = c_uint; -pub type u_long = c_ulong; -pub type ulong = c_ulong; -pub type quad_t = c_longlong; -pub type u_quad_t = c_ulonglong; -pub type caddr_t = *mut c_char;