From 65607311804eb4db9cd24a25bc631b1f95870ebb Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 11 Jul 2022 20:42:11 -0700 Subject: [PATCH] Require rust >= 1.30 and drop libc_core_cvoid conditional Move the `c_void` re-export to the top-level `lib.rs`. --- build.rs | 8 -------- libc-test/build.rs | 2 +- src/fuchsia/mod.rs | 22 ++-------------------- src/hermit.rs | 2 -- src/lib.rs | 5 ++--- src/psp.rs | 22 ++-------------------- src/sgx.rs | 20 -------------------- src/solid/mod.rs | 22 ++-------------------- src/switch.rs | 20 -------------------- src/unix/mod.rs | 22 ++-------------------- src/vxworks/mod.rs | 21 +-------------------- src/wasi/mod.rs | 4 ++-- src/windows/mod.rs | 22 ++-------------------- src/xous.rs | 20 -------------------- 14 files changed, 16 insertions(+), 196 deletions(-) diff --git a/build.rs b/build.rs index 25342e58c0f14..183b47ffd70f3 100644 --- a/build.rs +++ b/build.rs @@ -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", @@ -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"); diff --git a/libc-test/build.rs b/libc-test/build.rs index 59f7cf092718f..fdb09d53da085 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -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); } diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 5495ce9549b10..9a0b8755c4659 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -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; @@ -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, - } - } -} diff --git a/src/hermit.rs b/src/hermit.rs index 77df54ae12d8d..c65a8dd82e818 100644 --- a/src/hermit.rs +++ b/src/hermit.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index ffeda95e8d505..1dba4d8248fea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] @@ -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; diff --git a/src/psp.rs b/src/psp.rs index a4ca029b6e0c1..3e1cdac2ceb82 100644 --- a/src/psp.rs +++ b/src/psp.rs @@ -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; @@ -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, diff --git a/src/sgx.rs b/src/sgx.rs index 7da6269399d9e..e37ccd79c3a55 100644 --- a/src/sgx.rs +++ b/src/sgx.rs @@ -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, - } - } -} diff --git a/src/solid/mod.rs b/src/solid/mod.rs index 2aca8d19abffd..da1ce150b0330 100644 --- a/src/solid/mod.rs +++ b/src/solid/mod.rs @@ -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; @@ -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; diff --git a/src/switch.rs b/src/switch.rs index 030ab20d7bd8e..4a8b16e15f568 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -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, - } - } -} diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 1556c12726eb0..af5925197d2ab 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -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; @@ -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, - } - } -} diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index daf3b013b48b3..18b102b906767 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1,5 +1,6 @@ //! Interface to VxWorks C library +use c_void; use core::mem::size_of; use core::ptr::null_mut; @@ -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; diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index 743f607379768..b157ab0d59b04 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -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; diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 63536a809a421..2270e7078c966 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -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; @@ -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; diff --git a/src/xous.rs b/src/xous.rs index e6c0c2573d07d..4073349306fb9 100644 --- a/src/xous.rs +++ b/src/xous.rs @@ -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, - } - } -}