Skip to content

Commit bd42d06

Browse files
committed
Auto merge of #1086 - IsaacWoods:master, r=alexcrichton
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.
2 parents 3a04c32 + 90d8614 commit bd42d06

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

src/lib.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,35 @@ extern crate std as core;
101101
#[macro_use] mod macros;
102102
mod dox;
103103

104+
/*
105+
* `c_void` should be defined for all targets except wasm.
106+
*/
107+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
108+
cfg_if! {
109+
if #[cfg(core_cvoid)] {
110+
pub use core::ffi::c_void;
111+
} else {
112+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
113+
// more optimization opportunities around it recognizing things like
114+
// malloc/free.
115+
#[repr(u8)]
116+
pub enum c_void {
117+
// Two dummy variants so the #[repr] attribute can be used.
118+
#[doc(hidden)]
119+
__variant1,
120+
#[doc(hidden)]
121+
__variant2,
122+
}
123+
}
124+
}
125+
104126
cfg_if! {
105127
if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
106128
// empty ...
107129
} else if #[cfg(target_os = "switch")] {
108130
// On the Switch, we only define some useful universal types for
109131
// convenience. Those can be found in the switch.rs file.
110132
} else {
111-
cfg_if! {
112-
if #[cfg(core_cvoid)] {
113-
pub use core::ffi::c_void;
114-
} else {
115-
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
116-
// more optimization opportunities around it recognizing things like
117-
// malloc/free.
118-
#[repr(u8)]
119-
pub enum c_void {
120-
// Two dummy variants so the #[repr] attribute can be used.
121-
#[doc(hidden)]
122-
__variant1,
123-
#[doc(hidden)]
124-
__variant2,
125-
}
126-
}
127-
}
128-
129133
pub type int8_t = i8;
130134
pub type int16_t = i16;
131135
pub type int32_t = i32;

src/switch.rs

-18
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,3 @@ pub type c_char = u8;
3434
pub type c_long = i64;
3535
pub type c_ulong = u64;
3636
pub type wchar_t = u32;
37-
38-
cfg_if! {
39-
if #[cfg(core_cvoid)] {
40-
pub use core::ffi::c_void;
41-
} else {
42-
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
43-
// enable more optimization opportunities around it recognizing things
44-
// like malloc/free.
45-
#[repr(u8)]
46-
pub enum c_void {
47-
// Two dummy variants so the #[repr] attribute can be used.
48-
#[doc(hidden)]
49-
__variant1,
50-
#[doc(hidden)]
51-
__variant2,
52-
}
53-
}
54-
}

0 commit comments

Comments
 (0)