Skip to content

Commit

Permalink
Merge pull request #4214 from tgross35/backport-c_char-top-level
Browse files Browse the repository at this point in the history
[0.2] Define c_char at top-level and remove per-target c_char definitions
  • Loading branch information
tgross35 authored Dec 23, 2024
2 parents 0ead24f + 37ac889 commit 30309eb
Show file tree
Hide file tree
Showing 103 changed files with 30 additions and 179 deletions.
41 changes: 1 addition & 40 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,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 @@ -647,11 +644,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 @@ -766,8 +758,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 @@ -985,8 +975,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 @@ -1290,8 +1278,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 @@ -1511,8 +1497,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 @@ -1674,8 +1658,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 @@ -1924,9 +1906,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 @@ -2689,9 +2668,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 @@ -3012,9 +2988,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 @@ -3286,9 +3259,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 @@ -3455,8 +3425,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 @@ -3804,9 +3772,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 @@ -4036,7 +4001,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 @@ -4759,8 +4724,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 @@ -4996,8 +4959,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 @@ -41,41 +41,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/psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type ssize_t = isize;

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

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
Loading

0 comments on commit 30309eb

Please sign in to comment.