Skip to content

Commit a265c95

Browse files
authored
Remove more unnecessary libc usage (immunant#1229)
By using `std::ffi` types. A follow-up to immunant#1221 and immunant#1222.
2 parents 75bff7f + 5305b7d commit a265c95

Some content is hidden

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

70 files changed

+77
-99
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

c2rust-bitfields/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@ categories.workspace = true
1414
[dependencies]
1515
c2rust-bitfields-derive = { version = "0.20.0", path = "../c2rust-bitfields-derive" }
1616

17-
[dev-dependencies]
18-
libc = "0.2"
19-
2017
[features]
2118
no_std = []

c2rust-bitfields/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ And this is enough to build our rust struct:
4343
#[repr(C, align(1))]
4444
#[derive(BitfieldStruct)]
4545
struct Date {
46-
#[bitfield(name = "day", ty = "libc::c_uchar", bits = "0..=4")]
47-
#[bitfield(name = "month", ty = "libc::c_uchar", bits = "5..=8")]
48-
#[bitfield(name = "year", ty = "libc::c_ushort", bits = "9..=23")]
46+
#[bitfield(name = "day", ty = "std::ffi::c_uchar", bits = "0..=4")]
47+
#[bitfield(name = "month", ty = "std::ffi::c_uchar", bits = "5..=8")]
48+
#[bitfield(name = "year", ty = "std::ffi::c_ushort", bits = "9..=23")]
4949
day_month_year: [u8; 3]
5050
}
5151

c2rust-bitfields/c2rust-tests/test_structs.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use c2rust_bitfields::BitfieldStruct;
2-
use libc::{c_double, c_short, c_uchar, c_uint, c_ulong, c_ushort};
2+
use std::ffi::{c_double, c_short, c_uchar, c_uint, c_ulong, c_ushort};
33
use std::mem::{size_of, transmute};
44

55
#[link(name = "test")]
@@ -46,8 +46,8 @@ struct CompactDate {
4646
// Compact combination of d + m
4747
// which can't be accessed via ptr in C anyway
4848
// so we combine the fields into one:
49-
#[bitfield(name = "d", ty = "libc::c_uchar", bits = "0..=4")]
50-
#[bitfield(name = "m", ty = "libc::c_uchar", bits = "8..=11")]
49+
#[bitfield(name = "d", ty = "std::ffi::c_uchar", bits = "0..=4")]
50+
#[bitfield(name = "m", ty = "std::ffi::c_uchar", bits = "8..=11")]
5151
d_m: [u8; 2],
5252
y: u16,
5353
}
@@ -190,8 +190,8 @@ fn test_overflow() {
190190
struct OverlappingByteDate {
191191
// This is also compact, however, the first byte is shared between the two
192192
// bitfields and the month also has a bit in the second byte
193-
#[bitfield(name = "d", ty = "libc::c_ulong", bits = "0..=4")]
194-
#[bitfield(name = "m", ty = "libc::c_ushort", bits = "5..=8")]
193+
#[bitfield(name = "d", ty = "std::ffi::c_ulong", bits = "0..=4")]
194+
#[bitfield(name = "m", ty = "std::ffi::c_ushort", bits = "5..=8")]
195195
d_m: [u8; 2],
196196
y: u16,
197197
#[bitfield(padding)]
@@ -261,11 +261,11 @@ fn test_overlapping_byte_date2() {
261261
#[derive(BitfieldStruct, Copy, Clone)]
262262
struct UnnamedBitfield {
263263
z: f64,
264-
#[bitfield(name = "x", ty = "libc::c_ushort", bits = "0..=4")]
264+
#[bitfield(name = "x", ty = "std::ffi::c_ushort", bits = "0..=4")]
265265
x: [u8; 1],
266266
#[bitfield(padding)]
267267
_pad: [u8; 1],
268-
#[bitfield(name = "y", ty = "libc::c_ushort", bits = "0..=8")]
268+
#[bitfield(name = "y", ty = "std::ffi::c_ushort", bits = "0..=8")]
269269
y: [u8; 2],
270270
}
271271

@@ -301,9 +301,9 @@ fn test_unnamed_bitfield() {
301301
#[repr(C, align(2))]
302302
#[derive(BitfieldStruct, Copy, Clone)]
303303
struct SignedBitfields {
304-
#[bitfield(name = "x", ty = "libc::c_short", bits = "0..=3")]
305-
#[bitfield(name = "y", ty = "libc::c_ushort", bits = "4..=8")]
306-
#[bitfield(name = "z", ty = "libc::c_short", bits = "9..=13")]
304+
#[bitfield(name = "x", ty = "std::ffi::c_short", bits = "0..=3")]
305+
#[bitfield(name = "y", ty = "std::ffi::c_ushort", bits = "4..=8")]
306+
#[bitfield(name = "z", ty = "std::ffi::c_short", bits = "9..=13")]
307307
x_y_z: [u8; 2],
308308
}
309309

@@ -478,8 +478,8 @@ fn test_signed_underflow_overflow() {
478478
#[repr(C, align(2))]
479479
#[derive(BitfieldStruct, Copy, Clone)]
480480
struct SingleBits {
481-
#[bitfield(name = "x", ty = "libc::c_ushort", bits = "0..=0")]
482-
#[bitfield(name = "y", ty = "libc::c_short", bits = "1..=1")]
481+
#[bitfield(name = "x", ty = "std::ffi::c_ushort", bits = "0..=0")]
482+
#[bitfield(name = "y", ty = "std::ffi::c_short", bits = "1..=1")]
483483
x_y: [u8; 1],
484484
#[bitfield(padding)]
485485
_pad: [u8; 1],
@@ -532,9 +532,9 @@ fn test_single_bits() {
532532
#[repr(C, align(1))]
533533
#[derive(BitfieldStruct)]
534534
struct ThreeByteDate {
535-
#[bitfield(name = "day", ty = "libc::c_uchar", bits = "0..=4")]
536-
#[bitfield(name = "month", ty = "libc::c_uchar", bits = "5..=8")]
537-
#[bitfield(name = "year", ty = "libc::c_ushort", bits = "9..=23")]
535+
#[bitfield(name = "day", ty = "std::ffi::c_uchar", bits = "0..=4")]
536+
#[bitfield(name = "month", ty = "std::ffi::c_uchar", bits = "5..=8")]
537+
#[bitfield(name = "year", ty = "std::ffi::c_ushort", bits = "9..=23")]
538538
day_month_year: [u8; 3],
539539
}
540540

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Then create a new `.rs` file with the following skeleton (_does not need to be a
1313
```rust
1414
use crate::c_file::rust_example;
1515
16-
use libc::c_int;
16+
use std::ffi::c_int;
1717
1818
#[link(name = "test")]
1919
extern "C" {

tests/arrays/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libc = "0.2"

tests/arrays/src/test_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::arrays::rust_entry;
22
use crate::incomplete_arrays::{rust_check_some_ints, rust_entry2, rust_test_sized_array};
33
use crate::variable_arrays::{rust_alloca_arrays, rust_variable_arrays};
4-
use libc::{c_int, c_uint};
4+
use std::ffi::{c_int, c_uint};
55

66
#[link(name = "test")]
77
extern "C" {

tests/asm.aarch64/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libc = "0.2"
87
c2rust-asm-casts = { path = "../../c2rust-asm-casts", version = "0.20.0" }

tests/asm.aarch64/src/test_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! extern_crate_c2rust_asm_casts
22
33
use crate::asm::rust_entry;
4-
use libc::{c_int, c_uint};
4+
use std::ffi::{c_int, c_uint};
55

66
#[link(name = "test")]
77
extern "C" {

tests/asm.arm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libc = "0.2"

0 commit comments

Comments
 (0)