Skip to content

Commit 7e5ee35

Browse files
committed
refactor: Use core FFI types instead of re-defining them
1 parent aaa118c commit 7e5ee35

Some content is hidden

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

86 files changed

+4
-375
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: 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

+4-33
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,10 @@ cfg_if! {
3636
}
3737
}
3838

39-
pub use core::ffi::c_void;
40-
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-
}
39+
pub use core::ffi::{
40+
c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint,
41+
c_ulong, c_ulonglong, c_ushort, c_void,
42+
};
7243

7344
cfg_if! {
7445
if #[cfg(windows)] {

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).

src/trusty.rs

-23
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ pub type ssize_t = isize;
44

55
pub type off_t = i64;
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-
14-
cfg_if! {
15-
if #[cfg(target_pointer_width = "32")] {
16-
pub type c_long = i32;
17-
pub type c_ulong = u32;
18-
} else if #[cfg(target_pointer_width = "64")] {
19-
pub type c_long = i64;
20-
pub type c_ulong = u64;
21-
}
22-
}
23-
24-
pub type c_longlong = i64;
25-
pub type c_ulonglong = u64;
26-
277
pub type c_uint8_t = u8;
288
pub type c_uint16_t = u16;
299
pub type c_uint32_t = u32;
@@ -37,9 +17,6 @@ pub type c_int64_t = i64;
3717
pub type intptr_t = isize;
3818
pub type uintptr_t = usize;
3919

40-
pub type c_float = f32;
41-
pub type c_double = f64;
42-
4320
pub type time_t = c_long;
4421

4522
pub type clockid_t = c_int;

src/unix/aix/powerpc64.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::off_t;
22
use crate::prelude::*;
33

4-
pub type c_long = i64;
5-
pub type c_ulong = u64;
6-
74
s! {
85
pub struct sigset_t {
96
pub ss_set: [c_ulong; 4],

src/unix/bsd/apple/b32/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
use crate::prelude::*;
44

5-
pub type c_long = i32;
6-
pub type c_ulong = u32;
75
pub type boolean_t = c_int;
86

97
s! {

src/unix/bsd/apple/b64/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
33
use crate::prelude::*;
44

5-
pub type c_long = i64;
6-
pub type c_ulong = u64;
7-
85
s! {
96
pub struct timeval32 {
107
pub tv_sec: i32,

src/unix/bsd/freebsdlike/dragonfly/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ pub type nlink_t = u32;
1010
pub type blksize_t = i64;
1111
pub type clockid_t = c_ulong;
1212

13-
pub type c_long = i64;
14-
pub type c_ulong = u64;
1513
pub type time_t = i64;
1614
pub type suseconds_t = i64;
1715

src/unix/bsd/freebsdlike/freebsd/aarch64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type clock_t = i32;
64
pub type wchar_t = u32;
75
pub type time_t = i64;

src/unix/bsd/freebsdlike/freebsd/arm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i32;
4-
pub type c_ulong = u32;
53
pub type clock_t = u32;
64
pub type wchar_t = u32;
75
pub type time_t = i64;

src/unix/bsd/freebsdlike/freebsd/powerpc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i32;
4-
pub type c_ulong = u32;
53
pub type clock_t = u32;
64
pub type wchar_t = i32;
75
pub type time_t = i64;

src/unix/bsd/freebsdlike/freebsd/powerpc64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type clock_t = u32;
64
pub type wchar_t = i32;
75
pub type time_t = i64;

src/unix/bsd/freebsdlike/freebsd/riscv64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type clock_t = i32;
64
pub type wchar_t = c_int;
75
pub type time_t = i64;

src/unix/bsd/freebsdlike/freebsd/x86.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i32;
4-
pub type c_ulong = u32;
53
pub type clock_t = c_ulong;
64
pub type wchar_t = i32;
75
pub type time_t = i32;

src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type clock_t = i32;
64
pub type wchar_t = i32;
75
pub type time_t = i64;

src/unix/bsd/netbsdlike/netbsd/aarch64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::prelude::*;
22
use crate::PT_FIRSTMACH;
33

4-
pub type c_long = i64;
5-
pub type c_ulong = u64;
64
pub type greg_t = u64;
75
pub type __cpu_simple_lock_nv_t = c_uchar;
86

src/unix/bsd/netbsdlike/netbsd/arm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::prelude::*;
22
use crate::PT_FIRSTMACH;
33

4-
pub type c_long = i32;
5-
pub type c_ulong = u32;
64
pub type __cpu_simple_lock_nv_t = c_int;
75

86
pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_longlong>() - 1;

src/unix/bsd/netbsdlike/netbsd/mips.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::prelude::*;
22
use crate::PT_FIRSTMACH;
33

4-
pub type c_long = i32;
5-
pub type c_ulong = u32;
64
pub type __cpu_simple_lock_nv_t = c_int;
75

86
pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_longlong>() - 1;

src/unix/bsd/netbsdlike/netbsd/powerpc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::prelude::*;
22
use crate::PT_FIRSTMACH;
33

4-
pub type c_long = i32;
5-
pub type c_ulong = u32;
64
pub type __cpu_simple_lock_nv_t = c_int;
75

86
pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_double>() - 1;

src/unix/bsd/netbsdlike/netbsd/riscv64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use PT_FIRSTMACH;
22

33
use crate::prelude::*;
44

5-
pub type c_long = i64;
6-
pub type c_ulong = u64;
75
pub type __greg_t = u64;
86
pub type __cpu_simple_lock_nv_t = c_int;
97
pub type __gregset = [__greg_t; _NGREG];

src/unix/bsd/netbsdlike/netbsd/sparc64.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type __cpu_simple_lock_nv_t = c_uchar;
64

75
// should be pub(crate), but that requires Rust 1.18.0

0 commit comments

Comments
 (0)