Skip to content

Commit 34497e1

Browse files
phekitgross35
authored andcommitted
Copy definitions from core::ffi and centralize them
(backport <#4256>) (cherry picked from commit 95446f4) [ include lib.rs changes for psp, which isn't part of the original commit - Trevor ]
1 parent b2823f3 commit 34497e1

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

+89
-402
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

+26-58
Original file line numberDiff line numberDiff line change
@@ -41,138 +41,106 @@ cfg_if! {
4141

4242
pub use core::ffi::c_void;
4343

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

8149
mod windows;
8250
pub use crate::windows::*;
8351

8452
prelude!();
8553
} else if #[cfg(target_os = "fuchsia")] {
86-
mod fixed_width_ints;
87-
pub use crate::fixed_width_ints::*;
54+
mod primitives;
55+
pub use crate::primitives::*;
8856

8957
mod fuchsia;
9058
pub use crate::fuchsia::*;
9159

9260
prelude!();
9361
} else if #[cfg(target_os = "switch")] {
94-
mod fixed_width_ints;
95-
pub use fixed_width_ints::*;
62+
mod primitives;
63+
pub use primitives::*;
9664

9765
mod switch;
9866
pub use switch::*;
9967

10068
prelude!();
10169
} else if #[cfg(target_os = "psp")] {
102-
mod fixed_width_ints;
103-
pub use crate::fixed_width_ints::*;
70+
mod primitives;
71+
pub use primitives::*;
10472

10573
mod psp;
10674
pub use crate::psp::*;
10775

10876
prelude!();
10977
} else if #[cfg(target_os = "vxworks")] {
110-
mod fixed_width_ints;
111-
pub use crate::fixed_width_ints::*;
78+
mod primitives;
79+
pub use crate::primitives::*;
11280

11381
mod vxworks;
11482
pub use crate::vxworks::*;
11583

11684
prelude!();
11785
} else if #[cfg(target_os = "solid_asp3")] {
118-
mod fixed_width_ints;
119-
pub use crate::fixed_width_ints::*;
86+
mod primitives;
87+
pub use crate::primitives::*;
12088

12189
mod solid;
12290
pub use crate::solid::*;
12391

12492
prelude!();
12593
} else if #[cfg(unix)] {
126-
mod fixed_width_ints;
127-
pub use crate::fixed_width_ints::*;
94+
mod primitives;
95+
pub use crate::primitives::*;
12896

12997
mod unix;
13098
pub use crate::unix::*;
13199

132100
prelude!();
133101
} else if #[cfg(target_os = "hermit")] {
134-
mod fixed_width_ints;
135-
pub use crate::fixed_width_ints::*;
102+
mod primitives;
103+
pub use crate::primitives::*;
136104

137105
mod hermit;
138106
pub use crate::hermit::*;
139107

140108
prelude!();
141109
} else if #[cfg(target_os = "teeos")] {
142-
mod fixed_width_ints;
143-
pub use fixed_width_ints::*;
110+
mod primitives;
111+
pub use primitives::*;
144112

145113
mod teeos;
146114
pub use teeos::*;
147115

148116
prelude!();
149117
} else if #[cfg(target_os = "trusty")] {
150-
mod fixed_width_ints;
151-
pub use crate::fixed_width_ints::*;
118+
mod primitives;
119+
pub use crate::primitives::*;
152120

153121
mod trusty;
154122
pub use crate::trusty::*;
155123

156124
prelude!();
157125
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
158-
mod fixed_width_ints;
159-
pub use crate::fixed_width_ints::*;
126+
mod primitives;
127+
pub use crate::primitives::*;
160128

161129
mod sgx;
162130
pub use crate::sgx::*;
163131

164132
prelude!();
165133
} else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
166-
mod fixed_width_ints;
167-
pub use crate::fixed_width_ints::*;
134+
mod primitives;
135+
pub use crate::primitives::*;
168136

169137
mod wasi;
170138
pub use crate::wasi::*;
171139

172140
prelude!();
173141
} else if #[cfg(target_os = "xous")] {
174-
mod fixed_width_ints;
175-
pub use crate::fixed_width_ints::*;
142+
mod primitives;
143+
pub use crate::primitives::*;
176144

177145
mod xous;
178146
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;

0 commit comments

Comments
 (0)