Skip to content

Commit

Permalink
Require rust >= 1.30 and drop libc_core_cvoid conditional
Browse files Browse the repository at this point in the history
Move the `c_void` re-export to the top-level `lib.rs`.
  • Loading branch information
joshtriplett authored and tgross35 committed Nov 16, 2024
1 parent 851ca51 commit 6560731
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 196 deletions.
8 changes: 0 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_cfg_target_vendor",
"libc_const_extern_fn",
"libc_const_extern_fn_unstable",
"libc_core_cvoid",
"libc_deny_warnings",
"libc_long_array",
"libc_non_exhaustive",
Expand Down Expand Up @@ -86,13 +85,6 @@ fn main() {
set_cfg("libc_deny_warnings");
}

// Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it.
// Otherwise, it defines an incompatible type to retaining
// backwards-compatibility.
if rustc_minor_ver >= 30 || rustc_dep_of_std {
set_cfg("libc_core_cvoid");
}

// Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor).
if rustc_minor_ver >= 33 || rustc_dep_of_std {
set_cfg("libc_packedN");
Expand Down
2 changes: 1 addition & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn do_ctest() {

fn ctest_cfg() -> ctest::TestGenerator {
let mut cfg = ctest::TestGenerator::new();
let libc_cfgs = ["libc_core_cvoid", "libc_packedN", "libc_thread_local"];
let libc_cfgs = ["libc_packedN", "libc_thread_local"];
for f in &libc_cfgs {
cfg.cfg(f, None);
}
Expand Down
22 changes: 2 additions & 20 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! More functions and definitions can be found in the more specific modules
//! according to the platform in question.
use c_void;

// PUB_TYPE

pub type c_schar = i8;
Expand Down Expand Up @@ -4490,23 +4492,3 @@ cfg_if! {
// Unknown target_arch
}
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
2 changes: 0 additions & 2 deletions src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,5 +576,3 @@ extern "C" {
#[link_name = "sys_poll"]
pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: i32) -> i32;
}

pub use ffi::c_void;
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ cfg_if! {
#[doc(hidden)]
#[allow(unused_imports)]
use core::clone::Clone;
#[cfg(libc_core_cvoid)]
#[allow(unused_imports)]
use core::ffi;
#[allow(unused_imports)]
use core::fmt;
#[allow(unused_imports)]
Expand All @@ -64,6 +61,8 @@ use core::num;
#[allow(unused_imports)]
use core::option::Option;

pub use core::ffi::c_void;

cfg_if! {
if #[cfg(windows)] {
mod fixed_width_ints;
Expand Down
22 changes: 2 additions & 20 deletions src/psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! by the linker. Crates that use these definitions must, somewhere in the
//! crate graph, include a stub provider crate such as the `psp` crate.
use c_void;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand All @@ -27,26 +29,6 @@ pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

pub type SceKernelVTimerHandler = unsafe extern "C" fn(
uid: SceUid,
arg1: *mut SceKernelSysClock,
Expand Down
20 changes: 0 additions & 20 deletions src/sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,3 @@ pub type c_ulong = u64;

pub const INT_MIN: c_int = -2147483648;
pub const INT_MAX: c_int = 2147483647;

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
22 changes: 2 additions & 20 deletions src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! [SOLID]: https://solid.kmckk.com/
use c_void;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down Expand Up @@ -871,26 +873,6 @@ extern "C" {
pub fn lseek(arg1: c_int, arg2: __off_t, arg3: c_int) -> __off_t;
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

cfg_if! {
if #[cfg(target_arch = "aarch64")] {
mod aarch64;
Expand Down
20 changes: 0 additions & 20 deletions src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,3 @@ pub type wchar_t = u32;

pub const INT_MIN: c_int = -2147483648;
pub const INT_MAX: c_int = 2147483647;

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
22 changes: 2 additions & 20 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! More functions and definitions can be found in the more specific modules
//! according to the platform in question.
use c_void;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down Expand Up @@ -1703,23 +1705,3 @@ cfg_if! {
// Unknown target_os
}
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
21 changes: 1 addition & 20 deletions src/vxworks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Interface to VxWorks C library
use c_void;
use core::mem::size_of;
use core::ptr::null_mut;

Expand Down Expand Up @@ -2003,26 +2004,6 @@ pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_
}
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

cfg_if! {
if #[cfg(target_arch = "aarch64")] {
mod aarch64;
Expand Down
4 changes: 2 additions & 2 deletions src/wasi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Send, Sync};
use core::iter::Iterator;

pub use ffi::c_void;
use super::{Send, Sync};
use c_void;

pub type c_char = i8;
pub type c_uchar = u8;
Expand Down
22 changes: 2 additions & 20 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Windows CRT definitions
use c_void;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down Expand Up @@ -568,26 +570,6 @@ extern "system" {
pub fn socket(af: ::c_int, socket_type: ::c_int, protocol: ::c_int) -> SOCKET;
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

cfg_if! {
if #[cfg(all(target_env = "gnu"))] {
mod gnu;
Expand Down
20 changes: 0 additions & 20 deletions src/xous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,3 @@ pub type wchar_t = u32;

pub const INT_MIN: c_int = -2147483648;
pub const INT_MAX: c_int = 2147483647;

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

0 comments on commit 6560731

Please sign in to comment.