From c33744ea5af50e876fb4ed954178a1f82d42308b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 17 Dec 2024 21:29:10 +0000 Subject: [PATCH 1/2] Ignore ordering style for `c_char` --- ci/style.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/style.rs b/ci/style.rs index f5aeabcc71b5a..cad08f2eecc88 100644 --- a/ci/style.rs +++ b/ci/style.rs @@ -28,10 +28,9 @@ //! * alignment //! * leading colons on paths -use std::env; -use std::fs; use std::io::prelude::*; use std::path::Path; +use std::{env, fs}; macro_rules! t { ($e:expr) => { @@ -130,7 +129,7 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) { let line = if is_pub { &line[4..] } else { line }; let line_state = if line.starts_with("use ") { - if line.contains("c_void") { + if line.contains("c_void") || line.contains("c_char") { continue; } if is_pub { From fead383bf485cbed830b2686cf45ae5a12b74138 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 17 Dec 2024 21:30:30 +0000 Subject: [PATCH 2/2] Replace arch-conditional `c_char` with a reexport For any platforms that have `c_char` within a `cfg_if` block, ensure they match the top-level `arch` definitions and reexport that to clean up code. --- src/hermit.rs | 9 +-------- src/trusty.rs | 10 +--------- src/unix/nuttx/mod.rs | 12 +----------- src/unix/redox/mod.rs | 8 +------- src/unix/solarish/mod.rs | 8 +------- 5 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/hermit.rs b/src/hermit.rs index 2b470e78d3afe..9363fed788304 100644 --- a/src/hermit.rs +++ b/src/hermit.rs @@ -1,15 +1,8 @@ //! Hermit C type definitions +pub use crate::arch::c_char_def as c_char; use crate::prelude::*; -cfg_if! { - if #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] { - pub type c_char = u8; - } else { - pub type c_char = i8; - } -} - pub type c_schar = i8; pub type c_uchar = u8; pub type c_short = i16; diff --git a/src/trusty.rs b/src/trusty.rs index 60ca11d481613..676a456d892fe 100644 --- a/src/trusty.rs +++ b/src/trusty.rs @@ -1,18 +1,10 @@ +pub use crate::arch::c_char_def as c_char; use crate::prelude::*; - pub type size_t = usize; pub type ssize_t = isize; pub type off_t = i64; -cfg_if! { - if #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] { - pub type c_char = u8; - } else if #[cfg(target_arch = "x86_64")] { - pub type c_char = i8; - } -} - pub type c_schar = i8; pub type c_uchar = u8; pub type c_short = i16; diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index 78ecf3f133505..ed3e1ed8bfa34 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -1,3 +1,4 @@ +pub use crate::arch::c_char_def as c_char; use crate::prelude::*; use crate::{in6_addr, in_addr_t, timespec, DIR}; @@ -5,17 +6,6 @@ pub type nlink_t = u16; pub type ino_t = u16; pub type blkcnt_t = u64; pub type blksize_t = i16; -cfg_if! { - if #[cfg(any( - target_arch = "arm", - target_arch = "riscv32", - target_arch = "riscv64", - ))] { - pub type c_char = u8; - } else { - pub type c_char = i8; - } -} pub type c_long = isize; pub type c_ulong = usize; pub type cc_t = u8; diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 1c8bb40e746f3..93523253b620c 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -1,12 +1,6 @@ +pub use crate::arch::c_char_def as c_char; use crate::prelude::*; -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - pub type c_char = u8; - } else { - pub type c_char = i8; - } -} pub type wchar_t = i32; cfg_if! { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 83d94bff84373..2346aa5670249 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -1,14 +1,8 @@ use core::mem::size_of; +pub use crate::arch::c_char_def as c_char; use crate::prelude::*; -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - pub type c_char = u8; - } else { - pub type c_char = i8; - } -} pub type c_long = i64; pub type c_ulong = u64; pub type caddr_t = *mut c_char;