Skip to content

Commit fa08d45

Browse files
authored
Merge pull request #11 from Finomnis/core_ffi_types
Use newly stabilized ::core::ffi types
2 parents 38a3bcd + 41cdeab commit fa08d45

File tree

3 files changed

+22
-87
lines changed

3 files changed

+22
-87
lines changed

Cargo.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,3 @@ repository = "https://github.com/thejpster/tinyrlibc"
1212

1313
[build-dependencies]
1414
cc = "1.0"
15-
16-
[features]
17-
# Set this feature to assume a C `long` is 64-bits (i.e. the C compiler uses
18-
# the LP64 model, rather than the LLP64, ILP32 or LP32 models). See
19-
# https://en.cppreference.com/w/cpp/language/types for more details.
20-
lp64 = []
21-
# Set this feature to assume a C `int` is 16-bits (i.e. the C compiler uses
22-
# the LP32 model, rather than the LP64, LLP64 or ILP32 models). See
23-
# https://en.cppreference.com/w/cpp/language/types for more details.
24-
lp32 = []

src/lib.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,43 +51,23 @@ pub use self::itoa::itoa;
5151

5252
mod snprintf;
5353

54-
/// `long long int` is always 64-bits long.
55-
pub type CLongLong = i64;
54+
/// `long long int`
55+
pub type CLongLong = ::core::ffi::c_longlong;
5656

57-
/// `unsigned long long int` is always 64-bits long.
58-
pub type CULongLong = i64;
57+
/// `unsigned long long int`
58+
pub type CULongLong = ::core::ffi::c_ulonglong;
5959

60-
#[cfg(feature = "lp64")]
61-
/// The `lp64` feature means we assume `long int` is 64-bits.
62-
pub type CLong = i64;
60+
/// `long int`
61+
pub type CLong = ::core::ffi::c_long;
6362

64-
#[cfg(feature = "lp64")]
65-
/// The `lp64` feature means we assume `unsigned long int` is 64-bits.
66-
pub type CULong = u64;
63+
/// `unsigned long int`
64+
pub type CULong = ::core::ffi::c_ulong;
6765

68-
#[cfg(not(feature = "lp64"))]
69-
/// We assume `long int` is 32-bits.
70-
pub type CLong = i32;
66+
/// `int`
67+
pub type CInt = ::core::ffi::c_int;
7168

72-
#[cfg(not(feature = "lp64"))]
73-
/// We assume `unsigned long int` is 32-bits.
74-
pub type CULong = u32;
75-
76-
#[cfg(feature = "lp32")]
77-
/// The `lp32` feature means we assume `int` is 16-bits.
78-
pub type CInt = i16;
79-
80-
#[cfg(feature = "lp32")]
81-
/// The `lp32` feature means we assume `unsigned int` is 16-bits.
82-
pub type CUInt = u16;
83-
84-
#[cfg(not(feature = "lp32"))]
85-
/// We assume `int` is 32-bits.
86-
pub type CInt = i32;
87-
88-
#[cfg(not(feature = "lp32"))]
89-
/// We assume `unsigned int` is 32-bits.
90-
pub type CUInt = u32;
69+
/// `unsigned int`
70+
pub type CUInt = ::core::ffi::c_uint;
9171

9272
/// Represents an 8-bit `char`. Rust does not (and will never) support
9373
/// platforms where `char` is not 8-bits long.

src/snprintf.rs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod test {
99
fn snprintf(buf: *mut CChar, len: usize, fmt: *const CChar, ...) -> i32;
1010
}
1111

12-
use crate::{strcmp::strcmp, CChar};
12+
use crate::{strcmp::strcmp, CChar, CInt, CLong, CLongLong, CUInt, CULong, CULongLong};
1313

1414
#[test]
1515
fn plain_string() {
@@ -66,7 +66,6 @@ mod test {
6666
}
6767

6868
#[test]
69-
#[cfg(feature = "lp64")]
7069
fn numbers() {
7170
let mut buf = [b'\0'; 64];
7271
assert_eq!(
@@ -75,49 +74,15 @@ mod test {
7574
buf.as_mut_ptr(),
7675
buf.len(),
7776
"%u %lu %llu %d %ld %lld %x %lx %llX\0".as_ptr(),
78-
100u32,
79-
100u64,
80-
100u64,
81-
-100i32,
82-
-100i64,
83-
-100i64,
84-
0xcafe1234u32,
85-
0xcafe1234u64,
86-
0xcafe1234u64,
87-
)
88-
},
89-
53
90-
);
91-
assert_eq!(
92-
unsafe {
93-
strcmp(
94-
buf.as_ptr() as *const u8,
95-
b"100 100 100 -100 -100 -100 cafe1234 cafe1234 CAFE1234\0" as *const u8,
96-
)
97-
},
98-
0
99-
);
100-
}
101-
102-
#[test]
103-
#[cfg(not(feature = "lp64"))]
104-
fn numbers() {
105-
let mut buf = [b'\0'; 64];
106-
assert_eq!(
107-
unsafe {
108-
snprintf(
109-
buf.as_mut_ptr(),
110-
buf.len(),
111-
"%u %lu %llu %d %ld %lld %x %lx %llX\0".as_ptr(),
112-
100u32,
113-
100u32,
114-
100u64,
115-
-100i32,
116-
-100i32,
117-
-100i64,
118-
0xcafe1234u32,
119-
0xcafe1234u64,
120-
0xcafe1234u64,
77+
CUInt::from(100u8),
78+
CULong::from(100u8),
79+
CULongLong::from(100u8),
80+
CInt::from(-100i8),
81+
CLong::from(-100i8),
82+
CLongLong::from(-100i8),
83+
CUInt::from(0xcafe1234u32),
84+
CULong::from(0xcafe1234u32),
85+
CULongLong::from(0xcafe1234u32),
12186
)
12287
},
12388
53

0 commit comments

Comments
 (0)