Skip to content

Commit

Permalink
Auto merge of #1086 - IsaacWoods:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Revisit work on cvoid

At the recommendation of @SimonSapin [here](rust-lang/rust#53856 (comment)), I have revisited the build script to check whether `core::ffi::c_void` resolves, instead of relying on a particular `rustc` version. This allows use on `1.30.x` builds with `core::ffi::c_void`.

I also noticed that `c_void` is defined twice in this crate, once in `lib.rs` and again in `switch.rs`. This instead defines `c_void` for every target except `wasm32`. As far as I can tell, this shouldn't actually change functionality on any existing targets.
  • Loading branch information
bors committed Oct 4, 2018
2 parents 3a04c32 + 90d8614 commit bd42d06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
40 changes: 22 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,35 @@ extern crate std as core;
#[macro_use] mod macros;
mod dox;

/*
* `c_void` should be defined for all targets except wasm.
*/
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
cfg_if! {
if #[cfg(core_cvoid)] {
pub use core::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)]
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_arch = "wasm32", not(target_os = "emscripten")))] {
// empty ...
} else if #[cfg(target_os = "switch")] {
// On the Switch, we only define some useful universal types for
// convenience. Those can be found in the switch.rs file.
} else {
cfg_if! {
if #[cfg(core_cvoid)] {
pub use core::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)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

pub type int8_t = i8;
pub type int16_t = i16;
pub type int32_t = i32;
Expand Down
18 changes: 0 additions & 18 deletions src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,3 @@ pub type c_char = u8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type wchar_t = u32;

cfg_if! {
if #[cfg(core_cvoid)] {
pub use core::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)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}

0 comments on commit bd42d06

Please sign in to comment.