Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define c_char at top-level and remove per-target c_char definitions #4202

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ fn test_apple(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -603,11 +600,6 @@ fn test_openbsd(target: &str) {
}
});

cfg.skip_type(move |ty| {
// `c_char_def` is always public but not always reexported.
ty == "c_char_def"
});

cfg.type_name(move |ty, is_struct, is_union| {
match ty {
// Just pass all these through, no need for a "struct" prefix
Expand Down Expand Up @@ -722,8 +714,6 @@ fn test_windows(target: &str) {
"ssize_t" if !gnu => true,
// FIXME: The size and alignment of this type are incorrect
"time_t" if gnu && i686 => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -934,8 +924,6 @@ fn test_solarish(target: &str) {

cfg.skip_type(move |ty| match ty {
"sighandler_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -1236,8 +1224,6 @@ fn test_netbsd(target: &str) {
match ty {
// FIXME: sighandler_t is crazy across platforms
"sighandler_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down Expand Up @@ -1455,8 +1441,6 @@ fn test_dragonflybsd(target: &str) {
match ty {
// sighandler_t is crazy across platforms
"sighandler_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down Expand Up @@ -1615,8 +1599,6 @@ fn test_wasi(target: &str) {
}
});

cfg.skip_type(|ty| ty == "c_char_def");

// These have a different and internal type in header files and are only
// used here to generate a pointer to them in bindings so skip these tests.
cfg.skip_static(|c| c.starts_with("_CLOCK_"));
Expand Down Expand Up @@ -1865,9 +1847,6 @@ fn test_android(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2619,9 +2598,6 @@ fn test_freebsd(target: &str) {
// `eventfd(2)` and things come with it are added in FreeBSD 13
"eventfd_t" if Some(13) > freebsd_ver => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2938,9 +2914,6 @@ fn test_emscripten(target: &str) {
// https://github.com/emscripten-core/emscripten/issues/5033
ty if ty.starts_with("epoll") => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

// LFS64 types have been removed in Emscripten 3.1.44
// https://github.com/emscripten-core/emscripten/pull/19812
t => t.ends_with("64") || t.ends_with("64_t"),
Expand Down Expand Up @@ -3217,9 +3190,6 @@ fn test_neutrino(target: &str) {
// Does not exist in Neutrino
"locale_t" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -3383,8 +3353,6 @@ fn test_vxworks(target: &str) {
// FIXME
cfg.skip_type(move |ty| match ty {
"stat64" | "sighandler_t" | "off64_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -3732,9 +3700,6 @@ fn test_linux(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

t => {
if musl {
// LFS64 types have been removed in musl 1.2.4+
Expand Down Expand Up @@ -3964,7 +3929,7 @@ fn test_linux(target: &str) {
}
// FIXME: Requires >= 5.4 kernel headers
if name == "PTP_CLOCK_GETCAPS2"
|| name == "PTP_ENABLE_PPS2"
|| name == "PTP_ENABLE_PPS2"
|| name == "PTP_EXTTS_REQUEST2"
|| name == "PTP_PEROUT_REQUEST2"
|| name == "PTP_PIN_GETFUNC2"
Expand Down Expand Up @@ -4683,8 +4648,6 @@ fn test_linux_like_apis(target: &str) {
})
.skip_type(move |ty| match ty {
"Elf64_Phdr" | "Elf32_Phdr" => false,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => true,
});
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_elf.rs");
Expand Down Expand Up @@ -4920,8 +4883,6 @@ fn test_haiku(target: &str) {
"pthread_condattr_t" => true,
"pthread_mutexattr_t" => true,
"pthread_rwlockattr_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down
1 change: 0 additions & 1 deletion src/fuchsia/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::off_t;
use crate::prelude::*;

pub type c_char = u8;
pub type __u64 = c_ulonglong;
pub type wchar_t = u32;
pub type nlink_t = c_ulong;
Expand Down
1 change: 0 additions & 1 deletion src/fuchsia/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::off_t;
use crate::prelude::*;

// From psABI Calling Convention for RV64
pub type c_char = u8;
pub type __u64 = c_ulonglong;
pub type wchar_t = i32;

Expand Down
1 change: 0 additions & 1 deletion src/fuchsia/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::off_t;
use crate::prelude::*;

pub type c_char = i8;
pub type wchar_t = i32;
pub type nlink_t = u64;
pub type blksize_t = c_long;
Expand Down
1 change: 0 additions & 1 deletion src/hermit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Hermit C type definitions

pub use crate::arch::c_char_def as c_char;
use crate::prelude::*;

pub type c_schar = i8;
Expand Down
64 changes: 29 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,35 @@ cfg_if! {

pub use core::ffi::c_void;

/// Type definitions that are coupled tighter to architecture than OS.
mod arch {
cfg_if! {
// This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
if #[cfg(all(
not(windows),
// FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
not(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
)),
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "csky",
target_arch = "hexagon",
target_arch = "msp430",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "riscv32",
target_arch = "s390x",
target_arch = "xtensa",
)
))] {
// To be reexported as `c_char`
// FIXME(ctest): just name these `c_char` once `ctest` learns that these don't get
// exported.
pub type c_char_def = u8;
} else {
pub type c_char_def = i8;
}
cfg_if! {
// This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
if #[cfg(all(
not(windows),
// FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
not(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
)),
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "csky",
target_arch = "hexagon",
target_arch = "msp430",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "riscv32",
target_arch = "s390x",
target_arch = "xtensa",
)
))] {
pub type c_char = u8;
} else {
pub type c_char = i8;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type ssize_t = isize;

pub type c_char = i8;
pub type c_long = i64;
pub type c_ulong = u64;

Expand Down
1 change: 0 additions & 1 deletion src/solid/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub type c_char = u8;
pub type wchar_t = u32;
pub type c_long = i64;
pub type c_ulong = u64;
1 change: 0 additions & 1 deletion src/solid/arm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub type c_char = u8;
pub type wchar_t = u32;
pub type c_long = i32;
pub type c_ulong = u32;
1 change: 0 additions & 1 deletion src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub type uintptr_t = usize;
pub type ssize_t = isize;

pub type off_t = i64;
pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type wchar_t = u32;
Expand Down
3 changes: 0 additions & 3 deletions src/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ pub type ssize_t = isize;

pub type pid_t = c_int;

// aarch64 specific
pub type c_char = u8;

pub type wchar_t = u32;

pub type c_long = i64;
Expand Down
1 change: 0 additions & 1 deletion src/trusty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub use crate::arch::c_char_def as c_char;
use crate::prelude::*;
pub type size_t = usize;
pub type ssize_t = isize;
Expand Down
1 change: 0 additions & 1 deletion src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type caddr_t = *mut c_char;
pub type clockid_t = c_longlong;
pub type blkcnt_t = c_long;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use crate::prelude::*;
use crate::{cmsghdr, off_t};

pub type c_char = i8;
pub type wchar_t = i32;
pub type clock_t = c_ulong;
pub type time_t = c_long;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::prelude::*;
use crate::{cmsghdr, off_t};

pub type dev_t = u32;
pub type c_char = i8;
pub type wchar_t = i32;
pub type clock_t = u64;
pub type ino_t = u64;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type clock_t = i32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/arm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type c_long = i32;
pub type c_ulong = u32;
pub type clock_t = u32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/powerpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type c_long = i32;
pub type c_ulong = u32;
pub type clock_t = u32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/powerpc64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type clock_t = u32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/riscv64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type clock_t = i32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/x86.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = i8;
pub type c_long = i32;
pub type c_ulong = u32;
pub type clock_t = c_ulong;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;

pub type c_char = i8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type clock_t = i32;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/netbsdlike/netbsd/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::PT_FIRSTMACH;

pub type c_long = i64;
pub type c_ulong = u64;
pub type c_char = u8;
pub type greg_t = u64;
pub type __cpu_simple_lock_nv_t = c_uchar;

Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/netbsdlike/netbsd/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::PT_FIRSTMACH;

pub type c_long = i32;
pub type c_ulong = u32;
pub type c_char = u8;
pub type __cpu_simple_lock_nv_t = c_int;

pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_longlong>() - 1;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/netbsdlike/netbsd/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::PT_FIRSTMACH;

pub type c_long = i32;
pub type c_ulong = u32;
pub type c_char = i8;
pub type __cpu_simple_lock_nv_t = c_int;

pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_longlong>() - 1;
Expand Down
1 change: 0 additions & 1 deletion src/unix/bsd/netbsdlike/netbsd/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::PT_FIRSTMACH;

pub type c_long = i32;
pub type c_ulong = u32;
pub type c_char = u8;
pub type __cpu_simple_lock_nv_t = c_int;

pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_double>() - 1;
Expand Down
Loading
Loading