Skip to content

Commit d7a3541

Browse files
committed
Factor out platforms for which libc is empty
1 parent 4e5ef22 commit d7a3541

File tree

4 files changed

+51
-81
lines changed

4 files changed

+51
-81
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
libc
22
====
33

4-
A Rust library with native bindings to the types and functions commonly found on
5-
various systems, including libc.
4+
Rust wrapper over the system's `libc`.
65

76
[![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc)
87
[![Build status](https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/libc)

src/common.rs

Whitespace-only changes.

src/lib.rs

+50-50
Original file line numberDiff line numberDiff line change
@@ -98,38 +98,37 @@
9898
#[cfg(all(not(cross_platform_docs), feature = "use_std"))]
9999
extern crate std as core;
100100

101-
#[macro_use] mod macros;
102-
mod dox;
101+
#[macro_use]
102+
mod macros;
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"))))]
104+
// Targets for which `libc` should not fail to compile, but be completely empty
105+
// instead.
106+
//
107+
// FIXME: `libc` should just fail to compile for these targets.
108108
cfg_if! {
109-
if #[cfg(core_cvoid)] {
110-
pub use core::ffi::c_void;
109+
if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
110+
// libc is empty for wasm32-unknown-unknown ...
111111
} 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,
112+
mod dox;
113+
114+
cfg_if! {
115+
if #[cfg(core_cvoid)] {
116+
pub use core::ffi::c_void;
117+
} else {
118+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
119+
// more optimization opportunities around it recognizing things like
120+
// malloc/free.
121+
#[repr(u8)]
122+
pub enum c_void {
123+
// Two dummy variants so the #[repr] attribute can be used.
124+
#[doc(hidden)]
125+
__variant1,
126+
#[doc(hidden)]
127+
__variant2,
128+
}
129+
}
122130
}
123-
}
124-
}
125131

126-
cfg_if! {
127-
if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
128-
// empty ...
129-
} else if #[cfg(target_os = "switch")] {
130-
// On the Switch, we only define some useful universal types for
131-
// convenience. Those can be found in the switch.rs file.
132-
} else {
133132
pub type int8_t = i8;
134133
pub type int16_t = i16;
135134
pub type int32_t = i32;
@@ -284,6 +283,7 @@ cfg_if! {
284283

285284
// These are all inline functions on android, so they end up just being entirely
286285
// missing on that platform.
286+
287287
#[cfg(not(target_os = "android"))]
288288
extern {
289289
pub fn abs(i: c_int) -> c_int;
@@ -292,29 +292,29 @@ cfg_if! {
292292
pub fn rand() -> c_int;
293293
pub fn srand(seed: c_uint);
294294
}
295-
}
296-
}
297295

298-
cfg_if! {
299-
if #[cfg(windows)] {
300-
mod windows;
301-
pub use windows::*;
302-
} else if #[cfg(target_os = "redox")] {
303-
mod redox;
304-
pub use redox::*;
305-
} else if #[cfg(target_os = "cloudabi")] {
306-
mod cloudabi;
307-
pub use cloudabi::*;
308-
} else if #[cfg(target_os = "fuchsia")] {
309-
mod fuchsia;
310-
pub use fuchsia::*;
311-
} else if #[cfg(target_os = "switch")] {
312-
mod switch;
313-
pub use switch::*;
314-
} else if #[cfg(unix)] {
315-
mod unix;
316-
pub use unix::*;
317-
} else {
318-
// Unknown target_family
296+
cfg_if! {
297+
if #[cfg(windows)] {
298+
mod windows;
299+
pub use windows::*;
300+
} else if #[cfg(target_os = "redox")] {
301+
mod redox;
302+
pub use redox::*;
303+
} else if #[cfg(target_os = "cloudabi")] {
304+
mod cloudabi;
305+
pub use cloudabi::*;
306+
} else if #[cfg(target_os = "fuchsia")] {
307+
mod fuchsia;
308+
pub use fuchsia::*;
309+
} else if #[cfg(target_os = "switch")] {
310+
mod switch;
311+
pub use switch::*;
312+
} else if #[cfg(unix)] {
313+
mod unix;
314+
pub use unix::*;
315+
} else {
316+
// Unknown target_family
317+
}
318+
}
319319
}
320320
}

src/switch.rs

-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
//! Switch C type definitions
22
3-
pub type int8_t = i8;
4-
pub type int16_t = i16;
5-
pub type int32_t = i32;
6-
pub type int64_t = i64;
7-
pub type uint8_t = u8;
8-
pub type uint16_t = u16;
9-
pub type uint32_t = u32;
10-
pub type uint64_t = u64;
11-
12-
pub type c_schar = i8;
13-
pub type c_uchar = u8;
14-
pub type c_short = i16;
15-
pub type c_ushort = u16;
16-
pub type c_int = i32;
17-
pub type c_uint = u32;
18-
pub type c_float = f32;
19-
pub type c_double = f64;
20-
pub type c_longlong = i64;
21-
pub type c_ulonglong = u64;
22-
pub type intmax_t = i64;
23-
pub type uintmax_t = u64;
24-
25-
pub type size_t = usize;
26-
pub type ptrdiff_t = isize;
27-
pub type intptr_t = isize;
28-
pub type uintptr_t = usize;
29-
pub type ssize_t = isize;
30-
31-
// Arch specific
323
pub type off_t = i64;
334
pub type c_char = u8;
345
pub type c_long = i64;

0 commit comments

Comments
 (0)