Skip to content

Commit 95446f4

Browse files
committed
Copy definitions from core::ffi and centralize them
1 parent 478f19d commit 95446f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+87
-400
lines changed

src/fuchsia/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ use crate::prelude::*;
77

88
// PUB_TYPE
99

10-
pub type c_schar = i8;
11-
pub type c_uchar = u8;
12-
pub type c_short = i16;
13-
pub type c_ushort = u16;
14-
pub type c_int = i32;
15-
pub type c_uint = u32;
16-
pub type c_float = f32;
17-
pub type c_double = f64;
18-
pub type c_longlong = i64;
19-
pub type c_ulonglong = u64;
2010
pub type intmax_t = i64;
2111
pub type uintmax_t = u64;
2212

@@ -88,9 +78,6 @@ pub type fsblkcnt_t = c_ulonglong;
8878
pub type fsfilcnt_t = c_ulonglong;
8979
pub type rlim_t = c_ulonglong;
9080

91-
pub type c_long = i64;
92-
pub type c_ulong = u64;
93-
9481
// FIXME(fuchsia): why are these uninhabited types? that seems... wrong?
9582
// Presumably these should be `()` or an `extern type` (when that stabilizes).
9683
#[cfg_attr(feature = "extra_traits", derive(Debug))]

src/hermit.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,11 @@
22
33
use crate::prelude::*;
44

5-
pub type c_schar = i8;
6-
pub type c_uchar = u8;
7-
pub type c_short = i16;
8-
pub type c_ushort = u16;
9-
pub type c_int = i32;
10-
pub type c_uint = u32;
11-
pub type c_long = i64;
12-
pub type c_ulong = u64;
13-
pub type c_longlong = i64;
14-
pub type c_ulonglong = u64;
155
pub type intmax_t = i64;
166
pub type uintmax_t = u64;
177
pub type intptr_t = isize;
188
pub type uintptr_t = usize;
199

20-
pub type c_float = f32;
21-
pub type c_double = f64;
22-
2310
pub type size_t = usize;
2411
pub type ssize_t = isize;
2512
pub type ptrdiff_t = isize;

src/lib.rs

+24-56
Original file line numberDiff line numberDiff line change
@@ -38,130 +38,98 @@ cfg_if! {
3838

3939
pub use core::ffi::c_void;
4040

41-
cfg_if! {
42-
// This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
43-
if #[cfg(all(
44-
not(windows),
45-
// FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
46-
not(any(
47-
target_os = "macos",
48-
target_os = "ios",
49-
target_os = "tvos",
50-
target_os = "watchos",
51-
target_os = "visionos",
52-
)),
53-
any(
54-
target_arch = "aarch64",
55-
target_arch = "arm",
56-
target_arch = "csky",
57-
target_arch = "hexagon",
58-
target_arch = "msp430",
59-
target_arch = "powerpc",
60-
target_arch = "powerpc64",
61-
target_arch = "riscv64",
62-
target_arch = "riscv32",
63-
target_arch = "s390x",
64-
target_arch = "xtensa",
65-
)
66-
))] {
67-
pub type c_char = u8;
68-
} else {
69-
pub type c_char = i8;
70-
}
71-
}
72-
7341
cfg_if! {
7442
if #[cfg(windows)] {
75-
mod fixed_width_ints;
76-
pub use crate::fixed_width_ints::*;
43+
mod primitives;
44+
pub use crate::primitives::*;
7745

7846
mod windows;
7947
pub use crate::windows::*;
8048

8149
prelude!();
8250
} else if #[cfg(target_os = "fuchsia")] {
83-
mod fixed_width_ints;
84-
pub use crate::fixed_width_ints::*;
51+
mod primitives;
52+
pub use crate::primitives::*;
8553

8654
mod fuchsia;
8755
pub use crate::fuchsia::*;
8856

8957
prelude!();
9058
} else if #[cfg(target_os = "switch")] {
91-
mod fixed_width_ints;
92-
pub use fixed_width_ints::*;
59+
mod primitives;
60+
pub use primitives::*;
9361

9462
mod switch;
9563
pub use switch::*;
9664

9765
prelude!();
9866
} else if #[cfg(target_os = "vxworks")] {
99-
mod fixed_width_ints;
100-
pub use crate::fixed_width_ints::*;
67+
mod primitives;
68+
pub use crate::primitives::*;
10169

10270
mod vxworks;
10371
pub use crate::vxworks::*;
10472

10573
prelude!();
10674
} else if #[cfg(target_os = "solid_asp3")] {
107-
mod fixed_width_ints;
108-
pub use crate::fixed_width_ints::*;
75+
mod primitives;
76+
pub use crate::primitives::*;
10977

11078
mod solid;
11179
pub use crate::solid::*;
11280

11381
prelude!();
11482
} else if #[cfg(unix)] {
115-
mod fixed_width_ints;
116-
pub use crate::fixed_width_ints::*;
83+
mod primitives;
84+
pub use crate::primitives::*;
11785

11886
mod unix;
11987
pub use crate::unix::*;
12088

12189
prelude!();
12290
} else if #[cfg(target_os = "hermit")] {
123-
mod fixed_width_ints;
124-
pub use crate::fixed_width_ints::*;
91+
mod primitives;
92+
pub use crate::primitives::*;
12593

12694
mod hermit;
12795
pub use crate::hermit::*;
12896

12997
prelude!();
13098
} else if #[cfg(target_os = "teeos")] {
131-
mod fixed_width_ints;
132-
pub use fixed_width_ints::*;
99+
mod primitives;
100+
pub use primitives::*;
133101

134102
mod teeos;
135103
pub use teeos::*;
136104

137105
prelude!();
138106
} else if #[cfg(target_os = "trusty")] {
139-
mod fixed_width_ints;
140-
pub use crate::fixed_width_ints::*;
107+
mod primitives;
108+
pub use crate::primitives::*;
141109

142110
mod trusty;
143111
pub use crate::trusty::*;
144112

145113
prelude!();
146114
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
147-
mod fixed_width_ints;
148-
pub use crate::fixed_width_ints::*;
115+
mod primitives;
116+
pub use crate::primitives::*;
149117

150118
mod sgx;
151119
pub use crate::sgx::*;
152120

153121
prelude!();
154122
} else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
155-
mod fixed_width_ints;
156-
pub use crate::fixed_width_ints::*;
123+
mod primitives;
124+
pub use crate::primitives::*;
157125

158126
mod wasi;
159127
pub use crate::wasi::*;
160128

161129
prelude!();
162130
} else if #[cfg(target_os = "xous")] {
163-
mod fixed_width_ints;
164-
pub use crate::fixed_width_ints::*;
131+
mod primitives;
132+
pub use crate::primitives::*;
165133

166134
mod xous;
167135
pub use crate::xous::*;

src/fixed_width_ints.rs renamed to src/primitives.rs

+63-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,67 @@
1-
//! This module contains type aliases for C's fixed-width integer types .
1+
//! This module contains type aliases for C's platform-specific types
2+
//! and fixed-width integer types.
23
//!
3-
//! These aliases are deprecated: use the Rust types instead.
4+
//! The platform-specific types definitions were taken from rust-lang/rust in
5+
//! library/core/src/ffi/primitives.rs
6+
//!
7+
//! The fixed-width integer aliases are deprecated: use the Rust types instead.
8+
9+
pub type c_schar = i8;
10+
pub type c_uchar = u8;
11+
pub type c_short = i16;
12+
pub type c_ushort = u16;
13+
14+
pub type c_longlong = i64;
15+
pub type c_ulonglong = u64;
16+
17+
pub type c_float = f32;
18+
pub type c_double = f64;
19+
20+
cfg_if! {
21+
if #[cfg(all(
22+
not(windows),
23+
not(target_vendor = "apple"),
24+
any(
25+
target_arch = "aarch64",
26+
target_arch = "arm",
27+
target_arch = "csky",
28+
target_arch = "hexagon",
29+
target_arch = "msp430",
30+
target_arch = "powerpc",
31+
target_arch = "powerpc64",
32+
target_arch = "riscv32",
33+
target_arch = "riscv64",
34+
target_arch = "s390x",
35+
target_arch = "xtensa",
36+
)
37+
))] {
38+
pub type c_char = u8;
39+
} else {
40+
// On every other target, c_char is signed.
41+
pub type c_char = i8;
42+
}
43+
}
44+
45+
cfg_if! {
46+
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
47+
pub type c_int = i16;
48+
pub type c_uint = u16;
49+
} else {
50+
pub type c_int = i32;
51+
pub type c_uint = u32;
52+
}
53+
}
54+
55+
cfg_if! {
56+
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
57+
pub type c_long = i64;
58+
pub type c_ulong = u64;
59+
} else {
60+
// The minimal size of `long` in the C standard is 32 bits
61+
pub type c_long = i32;
62+
pub type c_ulong = u32;
63+
}
64+
}
465

566
#[deprecated(since = "0.2.55", note = "Use i8 instead.")]
667
pub type int8_t = i8;

src/sgx.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//! SGX C types definition
22
3-
pub type c_schar = i8;
4-
pub type c_uchar = u8;
5-
pub type c_short = i16;
6-
pub type c_ushort = u16;
7-
pub type c_int = i32;
8-
pub type c_uint = u32;
9-
pub type c_float = f32;
10-
pub type c_double = f64;
11-
pub type c_longlong = i64;
12-
pub type c_ulonglong = u64;
133
pub type intmax_t = i64;
144
pub type uintmax_t = u64;
155

@@ -19,8 +9,5 @@ pub type intptr_t = isize;
199
pub type uintptr_t = usize;
2010
pub type ssize_t = isize;
2111

22-
pub type c_long = i64;
23-
pub type c_ulong = u64;
24-
2512
pub const INT_MIN: c_int = -2147483648;
2613
pub const INT_MAX: c_int = 2147483647;

src/solid/aarch64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
pub type wchar_t = u32;
2-
pub type c_long = i64;
3-
pub type c_ulong = u64;

src/solid/arm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
pub type wchar_t = u32;
2-
pub type c_long = i32;
3-
pub type c_ulong = u32;

src/solid/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
55
use crate::prelude::*;
66

7-
pub type c_schar = i8;
8-
pub type c_uchar = u8;
9-
pub type c_short = i16;
10-
pub type c_ushort = u16;
11-
pub type c_int = i32;
12-
pub type c_uint = u32;
13-
pub type c_float = f32;
14-
pub type c_double = f64;
15-
pub type c_longlong = i64;
16-
pub type c_ulonglong = u64;
177
pub type intmax_t = i64;
188
pub type uintmax_t = u64;
199

src/switch.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//! Switch C type definitions
22
3-
pub type c_schar = i8;
4-
pub type c_uchar = u8;
5-
pub type c_short = i16;
6-
pub type c_ushort = u16;
7-
pub type c_int = i32;
8-
pub type c_uint = u32;
9-
pub type c_float = f32;
10-
pub type c_double = f64;
11-
pub type c_longlong = i64;
12-
pub type c_ulonglong = u64;
133
pub type intmax_t = i64;
144
pub type uintmax_t = u64;
155

@@ -20,8 +10,6 @@ pub type uintptr_t = usize;
2010
pub type ssize_t = isize;
2111

2212
pub type off_t = i64;
23-
pub type c_long = i64;
24-
pub type c_ulong = u64;
2513
pub type wchar_t = u32;
2614

2715
pub const INT_MIN: c_int = -2147483648;

src/teeos/mod.rs

-24
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,8 @@
77

88
use crate::prelude::*;
99

10-
pub type c_schar = i8;
11-
12-
pub type c_uchar = u8;
13-
14-
pub type c_short = i16;
15-
16-
pub type c_ushort = u16;
17-
18-
pub type c_int = i32;
19-
20-
pub type c_uint = u32;
21-
2210
pub type c_bool = i32;
2311

24-
pub type c_float = f32;
25-
26-
pub type c_double = f64;
27-
28-
pub type c_longlong = i64;
29-
30-
pub type c_ulonglong = u64;
31-
3212
pub type intmax_t = i64;
3313

3414
pub type uintmax_t = u64;
@@ -47,10 +27,6 @@ pub type pid_t = c_int;
4727

4828
pub type wchar_t = u32;
4929

50-
pub type c_long = i64;
51-
52-
pub type c_ulong = u64;
53-
5430
// long double in C means A float point value, which has 128bit length.
5531
// but some bit maybe not used, so the real length of long double could be 80(x86) or 128(power pc/IEEE)
5632
// this is different from f128(not stable and not included default) in Rust, so we use u128 for FFI(Rust to C).

0 commit comments

Comments
 (0)