diff --git a/.gitignore b/.gitignore index bbbad4bc51532..f0ff2599d09b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ target Cargo.lock *~ -style diff --git a/ci/run.sh b/ci/run.sh index 9754118f742b8..8889cda5a21e5 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -81,6 +81,7 @@ if [ -n "${QEMU:-}" ]; then fi cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}" +test_flags="--skip check_style" # Run tests in the `libc` crate case "$target" in @@ -101,17 +102,20 @@ if [ "$target" = "s390x-unknown-linux-gnu" ]; then passed=0 until [ $n -ge $N ]; do if [ "$passed" = "0" ]; then - if $cmd --no-default-features; then + # shellcheck disable=SC2086 + if $cmd --no-default-features -- $test_flags; then passed=$((passed+1)) continue fi elif [ "$passed" = "1" ]; then - if $cmd; then + # shellcheck disable=SC2086 + if $cmd -- $test_flags; then passed=$((passed+1)) continue fi elif [ "$passed" = "2" ]; then - if $cmd --features extra_traits; then + # shellcheck disable=SC2086 + if $cmd --features extra_traits -- $test_flags; then break fi fi @@ -119,7 +123,10 @@ if [ "$target" = "s390x-unknown-linux-gnu" ]; then sleep 1 done else - $cmd --no-default-features - $cmd - $cmd --features extra_traits + # shellcheck disable=SC2086 + $cmd --no-default-features -- $test_flags + # shellcheck disable=SC2086 + $cmd -- $test_flags + # shellcheck disable=SC2086 + $cmd --features extra_traits -- $test_flags fi diff --git a/ci/runtest-android.rs b/ci/runtest-android.rs index 92bce79b0d714..d422f9c2e8a7e 100644 --- a/ci/runtest-android.rs +++ b/ci/runtest-android.rs @@ -1,11 +1,11 @@ use std::env; -use std::process::Command; use std::path::{Path, PathBuf}; +use std::process::Command; fn main() { let args = env::args_os() .skip(1) - .filter(|arg| arg != "--quiet") + .filter(|arg| arg != "--quiet" && arg != "--skip" && arg != "check_style") .collect::>(); assert_eq!(args.len(), 1); let test = PathBuf::from(&args[0]); @@ -36,14 +36,16 @@ fn main() { let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - println!("status: {}\nstdout ---\n{}\nstderr ---\n{}", - output.status, - stdout, - stderr); + println!( + "status: {}\nstdout ---\n{}\nstderr ---\n{}", + output.status, stdout, stderr + ); - if !stderr.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok")) - && !stdout.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok")) - { + if !stderr.lines().any(|l| { + (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok") + }) && !stdout.lines().any(|l| { + (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok") + }) { panic!("failed to find successful test run"); }; } diff --git a/ci/style.rs b/ci/style.rs deleted file mode 100644 index cad08f2eecc88..0000000000000 --- a/ci/style.rs +++ /dev/null @@ -1,213 +0,0 @@ -//! Simple script to verify the coding style of this library -//! -//! ## How to run -//! -//! The first argument to this script is the directory to run on, so running -//! this script should be as simple as: -//! -//! ```notrust -//! rustc ci/style.rs -//! ./style src -//! ``` -//! -//! ## Guidelines -//! -//! The current style is: -//! -//! * Specific module layout: -//! 1. use directives -//! 2. typedefs -//! 3. structs -//! 4. constants -//! 5. f! { ... } functions -//! 6. extern functions -//! 7. modules + pub use -//! -//! Things not verified: -//! -//! * alignment -//! * leading colons on paths - -use std::io::prelude::*; -use std::path::Path; -use std::{env, fs}; - -macro_rules! t { - ($e:expr) => { - match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - } - }; -} - -fn main() { - let arg = env::args().skip(1).next().unwrap_or(".".to_string()); - - let mut errors = Errors { errs: false }; - walk(Path::new(&arg), &mut errors); - - if errors.errs { - panic!("found some lint errors"); - } else { - println!("good style!"); - } -} - -fn walk(path: &Path, err: &mut Errors) { - for entry in t!(path.read_dir()).map(|e| t!(e)) { - let path = entry.path(); - if t!(entry.file_type()).is_dir() { - walk(&path, err); - continue; - } - - let name = entry.file_name().into_string().unwrap(); - match &name[..] { - n if !n.ends_with(".rs") => continue, - - "lib.rs" | "macros.rs" => continue, - - _ => {} - } - - let mut contents = String::new(); - t!(t!(fs::File::open(&path)).read_to_string(&mut contents)); - - check_style(&contents, &path, err); - } -} - -struct Errors { - errs: bool, -} - -#[derive(Clone, Copy, PartialEq)] -enum State { - Start, - Imports, - Typedefs, - Structs, - Constants, - FunctionDefinitions, - Functions, - Modules, -} - -fn check_style(file: &str, path: &Path, err: &mut Errors) { - let mut state = State::Start; - - // FIXME: see below - // let mut s_macros = 0; - - let mut f_macros = 0; - let mut in_impl = false; - - for (i, line) in file.lines().enumerate() { - if line.contains("#[cfg(") - && line.contains(']') - && !line.contains(" if ") - && !(line.contains("target_endian") || line.contains("target_arch")) - { - if state != State::Structs { - err.error(path, i, "use cfg_if! and submodules instead of #[cfg]"); - } - } - if line.contains("#[derive(") && (line.contains("Copy") || line.contains("Clone")) { - err.error(path, i, "impl Copy and Clone manually"); - } - if line.contains("impl") { - in_impl = true; - } - if in_impl && line.starts_with('}') { - in_impl = false; - } - - let orig_line = line; - let line = line.trim_start(); - let is_pub = line.starts_with("pub "); - let line = if is_pub { &line[4..] } else { line }; - - let line_state = if line.starts_with("use ") { - if line.contains("c_void") || line.contains("c_char") { - continue; - } - if is_pub { - State::Modules - } else { - State::Imports - } - } else if line.starts_with("const ") { - State::Constants - } else if line.starts_with("type ") && !in_impl { - State::Typedefs - } else if line.starts_with("s! {") { - // FIXME: see below - // s_macros += 1; - State::Structs - } else if line.starts_with("s_no_extra_traits! {") { - // multiple macros of this type are allowed - State::Structs - } else if line.starts_with("s_paren! {") { - // multiple macros of this type are allowed - State::Structs - } else if line.starts_with("f! {") { - f_macros += 1; - State::FunctionDefinitions - } else if line.starts_with("extern ") && !orig_line.starts_with(" ") { - State::Functions - } else if line.starts_with("mod ") { - State::Modules - } else { - continue; - }; - - if state as usize > line_state as usize { - err.error( - path, - i, - &format!( - "{} found after {} when it belongs before", - line_state.desc(), - state.desc() - ), - ); - } - - if f_macros == 2 { - f_macros += 1; - err.error(path, i, "multiple f! macros in one module"); - } - - // FIXME(#4109): multiple should be allowed if at least one is `cfg(not) within `cfg_if`. - // For now just disable this and check by hand. - // if s_macros == 2 { - // s_macros += 1; - // err.error(path, i, "multiple s! macros in one module"); - // } - - state = line_state; - } -} - -impl State { - fn desc(&self) -> &str { - match *self { - State::Start => "start", - State::Imports => "import", - State::Typedefs => "typedef", - State::Structs => "struct", - State::Constants => "constant", - State::FunctionDefinitions => "function definition", - State::Functions => "extern function", - State::Modules => "module", - } - } -} - -impl Errors { - fn error(&mut self, path: &Path, line: usize, msg: &str) { - self.errs = true; - println!("{}:{}: {}", path.display(), line + 1, msg); - } -} diff --git a/ci/style.sh b/ci/style.sh index c758712012e16..da16bf4fe9baf 100755 --- a/ci/style.sh +++ b/ci/style.sh @@ -9,7 +9,7 @@ if [ -n "${CI:-}" ]; then check="--check" fi -rustc ci/style.rs && ./style src +cargo test --manifest-path libc-test/Cargo.toml --test style -- --nocapture command -v rustfmt rustfmt -V diff --git a/libc-test/Cargo.toml b/libc-test/Cargo.toml index 725d2f3247593..f0f4c22346753 100644 --- a/libc-test/Cargo.toml +++ b/libc-test/Cargo.toml @@ -17,6 +17,12 @@ path = ".." version = "0.2.169" default-features = false +[dev-dependencies] +syn = { version = "2.0.91", features = ["full", "visit"] } +proc-macro2 = { version = "1.0.92", features = ["span-locations"] } +glob = "0.3.2" +annotate-snippets = { version = "0.11.5", features = ["testing-colors"] } + [build-dependencies] cc = "1.0.83" # FIXME: Use fork ctest until the maintainer gets back. @@ -93,3 +99,13 @@ harness = false name = "primitive_types" path = "test/primitive_types.rs" harness = true + +[[test]] +name = "style" +path = "test/check_style.rs" +harness = true + +[[test]] +name = "style_tests" +path = "test/style_tests.rs" +harness = true diff --git a/libc-test/test/check_style.rs b/libc-test/test/check_style.rs new file mode 100644 index 0000000000000..ee5e134891104 --- /dev/null +++ b/libc-test/test/check_style.rs @@ -0,0 +1,50 @@ +//! Simple script to verify the coding style of this library. +//! +//! ## How to run +//! +//! The first argument to this script is the directory to run on, so running +//! this script should be as simple as: +//! +//! ```notrust +//! cargo test --test style +//! ``` + +pub mod style; + +use std::env; +use std::path::Path; + +use style::{Result, StyleChecker}; + +#[test] +fn check_style() { + let root_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../src"); + walk(&root_dir).unwrap(); + eprintln!("good style!"); +} + +fn walk(root_dir: &Path) -> Result<()> { + let mut style_checker = StyleChecker::new(); + + for entry in glob::glob(&format!( + "{}/**/*.rs", + root_dir.to_str().expect("dir should be valid UTF-8") + ))? { + let entry = entry?; + + let name = entry + .file_name() + .expect("file name should not end in ..") + .to_str() + .expect("file name should be valid UTF-8"); + if let "lib.rs" | "macros.rs" = &name[..] { + continue; + } + + let path = entry.as_path(); + style_checker.check_file(path)?; + style_checker.reset_state(); + } + + style_checker.finalize() +} diff --git a/libc-test/test/style/mod.rs b/libc-test/test/style/mod.rs new file mode 100644 index 0000000000000..cc953d32c3aed --- /dev/null +++ b/libc-test/test/style/mod.rs @@ -0,0 +1,490 @@ +//! Provides the [StyleChecker] visitor to verify the coding style of +//! this library. +//! +//! This is split out so that the implementation itself can be tested +//! separately, see test/check_style.rs for how it's used and +//! test/style_tests.rs for the implementation tests. +//! +//! ## Guidelines +//! +//! The current style is: +//! +//! * Specific module layout: +//! 1. use directives +//! 2. typedefs +//! 3. structs +//! 4. constants +//! 5. f! { ... } functions +//! 6. extern functions +//! 7. modules + pub use +//! * No manual deriving Copy/Clone +//! * Only one f! per module +//! * Multiple s! macros are allowed as long as there isn't a duplicate cfg, +//! whether as a standalone attribute (#[cfg]) or in a cfg_if! +//! * s! macros should not just have a positive cfg since they should +//! just go into the relevant file but combined cfgs with all(...) and +//! any(...) are allowed + +use std::collections::HashMap; +use std::fs; +use std::ops::Deref; +use std::path::{Path, PathBuf}; + +use annotate_snippets::{Level, Renderer, Snippet}; +use proc_macro2::Span; +use syn::parse::{Parse, ParseStream}; +use syn::spanned::Spanned; +use syn::visit::{self, Visit}; +use syn::Token; + +const ALLOWED_REPEATED_MACROS: &[&str] = &["s", "s_no_extra_traits", "s_paren"]; + +pub type Error = Box; +pub type Result = std::result::Result; + +#[derive(Default)] +pub struct StyleChecker { + /// The state the style checker is in, used to enforce the module layout. + state: State, + /// Span of the first item encountered in this state to use in help + /// diagnostic text. + state_span: Option, + /// The s! macro cfgs we have seen, whether through #[cfg] attributes + /// or within the branches of cfg_if! blocks so that we can check for duplicates. + seen_s_macro_cfgs: HashMap, + /// Span of the first f! macro seen, used to enforce only one f! macro + /// per module. + first_f_macro: Option, + /// The errors that the style checker has seen. + errors: Vec, + /// Path of the currently active file. + path: PathBuf, + /// Whether the style checker is currently in an `impl` block. + in_impl: bool, +} + +/// The part of the module layout we are currently checking. +#[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +enum State { + #[default] + Start, + Imports, + Typedefs, + Structs, + Constants, + FunctionDefinitions, + Functions, + Modules, +} + +/// Similar to [syn::ExprIf] except with [syn::Attribute] +/// as the condition instead of [syn::Expr]. +struct ExprCfgIf { + _cond: syn::Attribute, + /// A `cfg_if!` branch can only contain items. + then_branch: Vec, + else_branch: Option>, +} + +enum ExprCfgElse { + /// Final block with no condition `else { /* ... */ }`. + Block(Vec), + /// `else if { /* ... */ }` block. + If(ExprCfgIf), +} + +/// Describes an that occurred error when checking the file +/// at the given `path`. Besides the error message, it contains +/// additional span information so that we can print nice error messages. +#[derive(Debug)] +struct FileError { + path: PathBuf, + span: Span, + title: String, + msg: String, + help: Option, +} + +/// Help message with an optional span where the help should point to. +type HelpMsg = (Option, String); + +impl StyleChecker { + pub fn new() -> Self { + Self::default() + } + + /// Reads and parses the file at the given path and checks + /// for any style violations. + pub fn check_file(&mut self, path: &Path) -> Result<()> { + let contents = fs::read_to_string(path)?; + + self.path = PathBuf::from(path); + self.check_string(contents) + } + + pub fn check_string(&mut self, contents: String) -> Result<()> { + let file = syn::parse_file(&contents)?; + self.visit_file(&file); + Ok(()) + } + + /// Resets the state of the [StyleChecker]. + pub fn reset_state(&mut self) { + *self = Self { + errors: std::mem::take(&mut self.errors), + ..Self::default() + }; + } + + /// Collect all errors into a single error, reporting them if any. + pub fn finalize(self) -> Result<()> { + if self.errors.is_empty() { + return Ok(()); + } + + let renderer = Renderer::styled(); + for error in self.errors { + let source = fs::read_to_string(&error.path)?; + + let mut snippet = Snippet::source(&source) + .origin(error.path.to_str().expect("path to be UTF-8")) + .fold(true) + .annotation(Level::Error.span(error.span.byte_range()).label(&error.msg)); + if let Some((help_span, help_msg)) = &error.help { + if let Some(help_span) = help_span { + snippet = snippet + .annotation(Level::Help.span(help_span.byte_range()).label(help_msg)); + } + } + + let mut msg = Level::Error.title(&error.title).snippet(snippet); + if let Some((help_span, help_msg)) = &error.help { + if help_span.is_none() { + msg = msg.footer(Level::Help.title(help_msg)) + } + } + + eprintln!("{}", renderer.render(msg)); + } + + Err("some tests failed".into()) + } + + fn set_state(&mut self, new_state: State, span: Span) { + if self.state > new_state && !self.in_impl { + let help_span = self + .state_span + .expect("state_span should be set since we are on a second state"); + self.error( + "incorrect module layout".to_string(), + span, + format!( + "{} found after {} when it belongs before", + new_state.desc(), + self.state.desc() + ), + ( + Some(help_span), + format!( + "move the {} to before this {}", + new_state.desc(), + self.state.desc() + ), + ), + ); + } + + if self.state != new_state { + self.state = new_state; + self.state_span = Some(span); + } + } + + /// Visit the items inside the [ExprCfgIf], restoring the state after + /// each branch. + fn visit_expr_cfg_if(&mut self, expr_cfg_if: &ExprCfgIf) { + let initial_state = self.state; + + for item in &expr_cfg_if.then_branch { + self.visit_item(item); + } + self.state = initial_state; + + if let Some(else_branch) = &expr_cfg_if.else_branch { + match else_branch.deref() { + ExprCfgElse::Block(items) => { + for item in items { + self.visit_item(item); + } + } + ExprCfgElse::If(expr_cfg_if) => self.visit_expr_cfg_if(&expr_cfg_if), + } + } + self.state = initial_state; + } + + /// If we see a normal s! macro without any attributes we just need + /// to check if there are any duplicates. + fn handle_s_macro_no_attrs(&mut self, item_macro: &syn::ItemMacro) { + let span = item_macro.span(); + match self.seen_s_macro_cfgs.get("") { + Some(seen_span) => { + self.error( + "duplicate s! macro".to_string(), + span, + format!("other s! macro"), + (Some(*seen_span), "combine the two".to_string()), + ); + } + None => { + self.seen_s_macro_cfgs.insert(String::new(), span); + } + } + } + + /// If an s! macro has attributes we check for any duplicates as well + /// as if they are standalone positive cfgs that would be better + /// in a separate file. + fn handle_s_macro_with_attrs(&mut self, item_macro: &syn::ItemMacro) { + for attr in &item_macro.attrs { + let Ok(meta_list) = attr.meta.require_list() else { + continue; + }; + + if meta_list.path.is_ident("cfg") { + let span = meta_list.span(); + let meta_str = meta_list.tokens.to_string(); + + match self.seen_s_macro_cfgs.get(&meta_str) { + Some(seen_span) => { + self.error( + "duplicate #[cfg] for s! macro".to_string(), + span, + "duplicated #[cfg]".to_string(), + (Some(*seen_span), "combine the two".to_string()), + ); + } + None => { + self.seen_s_macro_cfgs.insert(meta_str.clone(), span); + } + } + + if !meta_str.starts_with("not") + && !meta_str.starts_with("any") + && !meta_str.starts_with("all") + { + self.error( + "positive #[cfg] for s! macro".to_string(), + span, + String::new(), + (None, "move it to the relevant file".to_string()), + ); + } + } + } + } + + fn push_error(&mut self, title: String, span: Span, msg: String, help: Option) { + self.errors.push(FileError { + path: self.path.clone(), + title, + span, + msg, + help, + }); + } + + fn error(&mut self, title: String, span: Span, msg: String, help: HelpMsg) { + self.push_error(title, span, msg, Some(help)); + } +} + +impl<'ast> Visit<'ast> for StyleChecker { + /// Visit all items; most just update our current state but some also + /// perform additional checks like for the s! macro. + fn visit_item_use(&mut self, item_use: &'ast syn::ItemUse) { + let span = item_use.span(); + let new_state = if matches!(item_use.vis, syn::Visibility::Public(_)) { + State::Modules + } else { + State::Imports + }; + self.set_state(new_state, span); + + visit::visit_item_use(self, item_use); + } + + fn visit_item_const(&mut self, item_const: &'ast syn::ItemConst) { + let span = item_const.span(); + self.set_state(State::Constants, span); + + visit::visit_item_const(self, item_const); + } + + fn visit_item_impl(&mut self, item_impl: &'ast syn::ItemImpl) { + self.in_impl = true; + visit::visit_item_impl(self, item_impl); + self.in_impl = false; + } + + fn visit_item_struct(&mut self, item_struct: &'ast syn::ItemStruct) { + let span = item_struct.span(); + self.set_state(State::Structs, span); + + visit::visit_item_struct(self, item_struct); + } + + fn visit_item_type(&mut self, item_type: &'ast syn::ItemType) { + let span = item_type.span(); + self.set_state(State::Typedefs, span); + + visit::visit_item_type(self, item_type); + } + + /// Checks s! macros for any duplicate cfgs and whether they are + /// just positive #[cfg(...)] attributes. We need [syn::ItemMacro] + /// instead of [syn::Macro] because it contains the attributes. + fn visit_item_macro(&mut self, item_macro: &'ast syn::ItemMacro) { + if item_macro.mac.path.is_ident("s") { + if item_macro.attrs.is_empty() { + self.handle_s_macro_no_attrs(item_macro); + } else { + self.handle_s_macro_with_attrs(item_macro); + } + } + + visit::visit_item_macro(self, item_macro); + } + + fn visit_macro(&mut self, mac: &'ast syn::Macro) { + let span = mac.span(); + if mac.path.is_ident("cfg_if") { + let expr_cfg_if: ExprCfgIf = mac + .parse_body() + .expect("cfg_if! should be parsed since it compiled"); + + self.visit_expr_cfg_if(&expr_cfg_if); + } else { + let new_state = + if mac.path.get_ident().is_some_and(|ident| { + ALLOWED_REPEATED_MACROS.contains(&ident.to_string().as_str()) + }) { + // multiple macros of this type are allowed + State::Structs + } else if mac.path.is_ident("f") { + match self.first_f_macro { + Some(f_macro_span) => { + self.error( + "multiple f! macros in one module".to_string(), + span, + "other f! macro".to_string(), + ( + Some(f_macro_span), + "combine it with this f! macro".to_string(), + ), + ); + } + None => { + self.first_f_macro = Some(span); + } + } + State::FunctionDefinitions + } else { + self.state + }; + self.set_state(new_state, span); + } + + visit::visit_macro(self, mac); + } + + fn visit_item_foreign_mod(&mut self, item_foreign_mod: &'ast syn::ItemForeignMod) { + let span = item_foreign_mod.span(); + self.set_state(State::Functions, span); + + visit::visit_item_foreign_mod(self, item_foreign_mod); + } + + fn visit_item_mod(&mut self, item_mod: &'ast syn::ItemMod) { + let span = item_mod.span(); + self.set_state(State::Modules, span); + + visit::visit_item_mod(self, item_mod); + } + + fn visit_meta_list(&mut self, meta_list: &'ast syn::MetaList) { + let span = meta_list.span(); + let meta_str = meta_list.tokens.to_string(); + if meta_list.path.is_ident("derive") + && (meta_str.contains("Copy") || meta_str.contains("Clone")) + { + self.error( + "impl Copy and Clone manually".to_string(), + span, + "found manual implementation of Copy and/or Clone".to_string(), + (None, "use one of the s! macros instead".to_string()), + ); + } + + visit::visit_meta_list(self, meta_list); + } +} + +impl Parse for ExprCfgIf { + fn parse(input: ParseStream) -> syn::Result { + input.parse::()?; + let cond = input + .call(syn::Attribute::parse_outer)? + .into_iter() + .next() + .expect("an attribute should be present since it compiled"); + + let content; + syn::braced!(content in input); + let mut then_branch = Vec::new(); + while !content.is_empty() { + let mut value = content.parse()?; + if let syn::Item::Macro(item_macro) = &mut value { + item_macro.attrs.push(cond.clone()); + } + then_branch.push(value); + } + + let mut else_branch = None; + if input.peek(Token![else]) { + input.parse::()?; + + if input.peek(Token![if]) { + else_branch = Some(Box::new(ExprCfgElse::If(input.parse()?))); + } else { + let content; + syn::braced!(content in input); + let mut items = Vec::new(); + while !content.is_empty() { + items.push(content.parse()?); + } + else_branch = Some(Box::new(ExprCfgElse::Block(items))); + } + } + Ok(Self { + _cond: cond, + then_branch, + else_branch, + }) + } +} + +impl State { + fn desc(&self) -> &str { + match *self { + State::Start => "start", + State::Imports => "import", + State::Typedefs => "typedef", + State::Structs => "struct", + State::Constants => "constant", + State::FunctionDefinitions => "function definition", + State::Functions => "extern function", + State::Modules => "module", + } + } +} diff --git a/libc-test/test/style_tests.rs b/libc-test/test/style_tests.rs new file mode 100644 index 0000000000000..be8fddbccf644 --- /dev/null +++ b/libc-test/test/style_tests.rs @@ -0,0 +1,260 @@ +//! Verifies the implementation of the style checker in [style]. + +use style::StyleChecker; + +pub mod style; + +#[test] +fn check_style_accept_correct_module_layout() { + let contents = r#" +use core::mem::size_of; +pub type foo_t = u32; +struct Foo {} +pub const FOO: u32 = 0x20000; +f! {} +extern "C" {} +mod foolib; +pub use self::foolib::*; +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_reject_incorrect_module_layout() { + let contents = r#" +use core::mem::size_of; +pub type foo_t = u32; +struct Foo {} +pub const FOO: u32 = 0x20000; +extern "C" {} +f! {} +mod foolib; +pub use self::foolib::*; +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_reject_incorrect_cfg_if_layout() { + let contents = r#" +cfg_if! { + if #[cfg(foo)] { + pub type foo_t = u32; + use core::mem::size_of; + } +} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_accept_cfg_if_branch_resets_state() { + let contents = r#" +cfg_if! { + if #[cfg(foo)] { + use core::mem::size_of; + pub type foo_t = u32; + } else { + use core::mem::align_of; + } +} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_reject_multiple_f_macros() { + let contents = r#" +f! {} +f! {} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_accept_cfg_ignore_target_endian_nested() { + let contents = r#" +pub struct Foo { + #[cfg(target_endian = "little")] + pub id: __u16, +} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_reject_manual_copy() { + let contents = r#" +#[derive(Copy)] +pub struct Foo {} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_reject_manual_clone() { + let contents = r#" +#[derive(Clone)] +pub struct Foo {} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_accept_multiple_s_macros_with_disjoint_cfg() { + let contents = r#" +// Main `s!` +s! {} + +// These are not supported on a single arch. It doesn't make sense to +// duplicate `foo` into every single file except one, so allow this here. +#[cfg(not(target_arch = "foo"))] +s! { pub struct foo { /* ... */ } } + +// Similar to the above, no problems here +#[cfg(not(target_os = "illumos"))] +s! { pub struct bar { /* ... */ } } +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_reject_duplicated_s_macro() { + let contents = r#" +s! {} +s! {} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_reject_duplicated_s_macro_cfg() { + let contents = r#" +#[cfg(not(target_arch = "foo"))] +s! {} + +#[cfg(not(target_arch = "foo"))] +s! {} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_reject_single_positive_s_macro_cfg() { + let contents = r#" +// A positive (no `not`) config: reject because this should go into +// the relevant file. +#[cfg(target_arch = "foo")] +s! { pub struct foo { /* ... */ } } +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_reject_single_positive_s_macro_cfg_target_os() { + let contents = r#" +// A positive (no `not`) config: reject because this should go into +// the relevant file. +#[cfg(target_os = "foo")] +s! { pub struct foo { /* ... */ } } +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} + +#[test] +fn check_style_accept_positive_s_macro_any() { + let contents = r#" +// It's nicer to accept this so that we don't have to duplicate the same struct 3 times. +#[cfg(any(target_arch = "foo", target_arch = "bar", target_arch = "baz"))] +s! { pub struct foo { /* ... */ } } +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_accept_positive_s_macro_all() { + let contents = r#" +#[cfg(all(target_arch = "foo", target_arch = "bar", target_arch = "baz"))] +s! { pub struct foo { /* ... */ } } +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + checker.finalize().unwrap(); +} + +#[test] +fn check_style_reject_duplicated_cfg_and_cfg_if() { + let contents = r#" +#[cfg(not(target_arch = "foo"))] +s! { pub struct foo { /* ... */ } } + +cfg_if! { + if #[cfg(not(target_arch = "foo"))] { + s!{ pub struct bar {} } + } +} +"# + .to_string(); + + let mut checker = StyleChecker::new(); + checker.check_string(contents).unwrap(); + assert!(checker.finalize().is_err()); +} diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index f0559db9bee55..d666c7e39de60 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -7,16 +7,6 @@ use crate::prelude::*; // PUB_TYPE -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; @@ -88,9 +78,6 @@ pub type fsblkcnt_t = c_ulonglong; pub type fsfilcnt_t = c_ulonglong; pub type rlim_t = c_ulonglong; -pub type c_long = i64; -pub type c_ulong = u64; - // FIXME(fuchsia): why are these uninhabited types? that seems... wrong? // Presumably these should be `()` or an `extern type` (when that stabilizes). #[cfg_attr(feature = "extra_traits", derive(Debug))] diff --git a/src/hermit.rs b/src/hermit.rs index 03947bc01ade5..65d0bf374d8cd 100644 --- a/src/hermit.rs +++ b/src/hermit.rs @@ -2,24 +2,11 @@ use crate::prelude::*; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; pub type intptr_t = isize; pub type uintptr_t = usize; -pub type c_float = f32; -pub type c_double = f64; - pub type size_t = usize; pub type ssize_t = isize; pub type ptrdiff_t = isize; diff --git a/src/lib.rs b/src/lib.rs index 060c4c1b39cdd..50aed357a82ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,138 +41,106 @@ cfg_if! { pub use core::ffi::c_void; -cfg_if! { - // This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`. - if #[cfg(all( - not(windows), - // FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it - not(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", - )), - any( - target_arch = "aarch64", - target_arch = "arm", - target_arch = "csky", - target_arch = "hexagon", - target_arch = "msp430", - target_arch = "powerpc", - target_arch = "powerpc64", - target_arch = "riscv64", - target_arch = "riscv32", - target_arch = "s390x", - target_arch = "xtensa", - ) - ))] { - pub type c_char = u8; - } else { - pub type c_char = i8; - } -} - cfg_if! { if #[cfg(windows)] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod windows; pub use crate::windows::*; prelude!(); } else if #[cfg(target_os = "fuchsia")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod fuchsia; pub use crate::fuchsia::*; prelude!(); } else if #[cfg(target_os = "switch")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; + mod primitives; + pub use primitives::*; mod switch; pub use switch::*; prelude!(); } else if #[cfg(target_os = "psp")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use primitives::*; mod psp; pub use crate::psp::*; prelude!(); } else if #[cfg(target_os = "vxworks")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod vxworks; pub use crate::vxworks::*; prelude!(); } else if #[cfg(target_os = "solid_asp3")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod solid; pub use crate::solid::*; prelude!(); } else if #[cfg(unix)] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod unix; pub use crate::unix::*; prelude!(); } else if #[cfg(target_os = "hermit")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod hermit; pub use crate::hermit::*; prelude!(); } else if #[cfg(target_os = "teeos")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; + mod primitives; + pub use primitives::*; mod teeos; pub use teeos::*; prelude!(); } else if #[cfg(target_os = "trusty")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod trusty; pub use crate::trusty::*; prelude!(); } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod sgx; pub use crate::sgx::*; prelude!(); } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod wasi; pub use crate::wasi::*; prelude!(); } else if #[cfg(target_os = "xous")] { - mod fixed_width_ints; - pub use crate::fixed_width_ints::*; + mod primitives; + pub use crate::primitives::*; mod xous; pub use crate::xous::*; diff --git a/src/fixed_width_ints.rs b/src/primitives.rs similarity index 73% rename from src/fixed_width_ints.rs rename to src/primitives.rs index d2385fd385d10..ed71e843057b1 100644 --- a/src/fixed_width_ints.rs +++ b/src/primitives.rs @@ -1,6 +1,68 @@ -//! This module contains type aliases for C's fixed-width integer types . +//! This module contains type aliases for C's platform-specific types +//! and fixed-width integer types. //! -//! These aliases are deprecated: use the Rust types instead. +//! The platform-specific types definitions were taken from rust-lang/rust in +//! library/core/src/ffi/primitives.rs +//! +//! The fixed-width integer aliases are deprecated: use the Rust types instead. + +pub type c_schar = i8; +pub type c_uchar = u8; +pub type c_short = i16; +pub type c_ushort = u16; + +pub type c_longlong = i64; +pub type c_ulonglong = u64; + +pub type c_float = f32; +pub type c_double = f64; + +cfg_if! { + if #[cfg(all( + not(windows), + not(target_vendor = "apple"), + not(target_os = "vita"), + any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "csky", + target_arch = "hexagon", + target_arch = "msp430", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "s390x", + target_arch = "xtensa", + ) + ))] { + pub type c_char = u8; + } else { + // On every other target, c_char is signed. + pub type c_char = i8; + } +} + +cfg_if! { + if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] { + pub type c_int = i16; + pub type c_uint = u16; + } else { + pub type c_int = i32; + pub type c_uint = u32; + } +} + +cfg_if! { + if #[cfg(all(target_pointer_width = "64", not(windows)))] { + pub type c_long = i64; + pub type c_ulong = u64; + } else { + // The minimal size of `long` in the C standard is 32 bits + pub type c_long = i32; + pub type c_ulong = u32; + } +} #[deprecated(since = "0.2.55", note = "Use i8 instead.")] pub type int8_t = i8; diff --git a/src/psp.rs b/src/psp.rs index ed9d4f4d5b415..73d4ae0173ece 100644 --- a/src/psp.rs +++ b/src/psp.rs @@ -6,16 +6,6 @@ use crate::prelude::*; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; @@ -25,9 +15,6 @@ pub type intptr_t = isize; pub type uintptr_t = usize; pub type ssize_t = isize; -pub type c_long = i64; -pub type c_ulong = u64; - pub type SceKernelVTimerHandler = unsafe extern "C" fn( uid: SceUid, arg1: *mut SceKernelSysClock, diff --git a/src/sgx.rs b/src/sgx.rs index 65eded63ad460..9cf9c6d3b41b8 100644 --- a/src/sgx.rs +++ b/src/sgx.rs @@ -1,15 +1,7 @@ //! SGX C types definition -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; +use crate::prelude::*; + pub type intmax_t = i64; pub type uintmax_t = u64; @@ -19,8 +11,5 @@ pub type intptr_t = isize; pub type uintptr_t = usize; pub type ssize_t = isize; -pub type c_long = i64; -pub type c_ulong = u64; - pub const INT_MIN: c_int = -2147483648; pub const INT_MAX: c_int = 2147483647; diff --git a/src/solid/aarch64.rs b/src/solid/aarch64.rs index 630c7db54b55b..376783c8234ba 100644 --- a/src/solid/aarch64.rs +++ b/src/solid/aarch64.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/src/solid/arm.rs b/src/solid/arm.rs index 01fc7262f03e2..376783c8234ba 100644 --- a/src/solid/arm.rs +++ b/src/solid/arm.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/src/solid/mod.rs b/src/solid/mod.rs index 19c9b6aed344b..965c5bb1aa522 100644 --- a/src/solid/mod.rs +++ b/src/solid/mod.rs @@ -4,16 +4,6 @@ use crate::prelude::*; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; diff --git a/src/switch.rs b/src/switch.rs index 1875ea81ad1ec..d965ff7005fb2 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -1,15 +1,5 @@ //! Switch C type definitions -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; @@ -20,8 +10,6 @@ pub type uintptr_t = usize; pub type ssize_t = isize; pub type off_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = u32; pub const INT_MIN: c_int = -2147483648; diff --git a/src/teeos/mod.rs b/src/teeos/mod.rs index b055d2aca8c7e..9929e70e61e63 100644 --- a/src/teeos/mod.rs +++ b/src/teeos/mod.rs @@ -7,28 +7,8 @@ use crate::prelude::*; -pub type c_schar = i8; - -pub type c_uchar = u8; - -pub type c_short = i16; - -pub type c_ushort = u16; - -pub type c_int = i32; - -pub type c_uint = u32; - pub type c_bool = i32; -pub type c_float = f32; - -pub type c_double = f64; - -pub type c_longlong = i64; - -pub type c_ulonglong = u64; - pub type intmax_t = i64; pub type uintmax_t = u64; @@ -47,13 +27,6 @@ pub type pid_t = c_int; pub type wchar_t = u32; -pub type c_long = i64; - -pub type c_ulong = u64; - -#[repr(align(16))] -pub struct _CLongDouble(pub u128); - // long double in C means A float point value, which has 128bit length. // but some bit maybe not used, so the real length of long double could be 80(x86) or 128(power pc/IEEE) // this is different from f128(not stable and not included default) in Rust, so we use u128 for FFI(Rust to C). @@ -88,6 +61,9 @@ pub type wctype_t = c_ulong; pub type cmpfunc = extern "C" fn(x: *const c_void, y: *const c_void) -> c_int; +#[repr(align(16))] +pub struct _CLongDouble(pub u128); + #[repr(align(8))] #[repr(C)] pub struct pthread_cond_t { diff --git a/src/trusty.rs b/src/trusty.rs index db908d5c6d47a..7441aade0631e 100644 --- a/src/trusty.rs +++ b/src/trusty.rs @@ -4,26 +4,6 @@ pub type ssize_t = isize; pub type off_t = i64; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; - -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - pub type c_long = i32; - pub type c_ulong = u32; - } else if #[cfg(target_pointer_width = "64")] { - pub type c_long = i64; - pub type c_ulong = u64; - } -} - -pub type c_longlong = i64; -pub type c_ulonglong = u64; - pub type c_uint8_t = u8; pub type c_uint16_t = u16; pub type c_uint32_t = u32; @@ -37,9 +17,6 @@ pub type c_int64_t = i64; pub type intptr_t = isize; pub type uintptr_t = usize; -pub type c_float = f32; -pub type c_double = f64; - pub type time_t = c_long; pub type clockid_t = c_int; diff --git a/src/unix/aix/powerpc64.rs b/src/unix/aix/powerpc64.rs index 921774611e299..fcb9e6edfafa7 100644 --- a/src/unix/aix/powerpc64.rs +++ b/src/unix/aix/powerpc64.rs @@ -1,9 +1,6 @@ use crate::off_t; use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; - s! { pub struct sigset_t { pub ss_set: [c_ulong; 4], diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index 70f8de79af7b6..4fec58f76be47 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -2,8 +2,6 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type boolean_t = c_int; s! { diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index b09bcb9dad332..98dccd3d49ddd 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -2,9 +2,6 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; - s! { pub struct timeval32 { pub tv_sec: i32, diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 2897ad377f14d..cfaa93f76d88e 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -10,8 +10,6 @@ pub type nlink_t = u32; pub type blksize_t = i64; pub type clockid_t = c_ulong; -pub type c_long = i64; -pub type c_ulong = u64; pub type time_t = i64; pub type suseconds_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs index 0201008e485fb..ae93648ebd94f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/aarch64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/aarch64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type clock_t = i32; pub type wchar_t = u32; pub type time_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/arm.rs b/src/unix/bsd/freebsdlike/freebsd/arm.rs index 1624e655a0f4c..e29c9cef3981e 100644 --- a/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ b/src/unix/bsd/freebsdlike/freebsd/arm.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type clock_t = u32; pub type wchar_t = u32; pub type time_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs index 6c8c973d570d1..9fde25d37b62f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type clock_t = u32; pub type wchar_t = i32; pub type time_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs index a812568b38e7d..e7df7f7737997 100644 --- a/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type clock_t = u32; pub type wchar_t = i32; pub type time_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs index 212413cbe22af..449a29f7d3df4 100644 --- a/src/unix/bsd/freebsdlike/freebsd/riscv64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/riscv64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type clock_t = i32; pub type wchar_t = c_int; pub type time_t = i64; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index c5a922b455642..b196eafe06ab8 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type clock_t = c_ulong; pub type wchar_t = i32; pub type time_t = i32; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs index 199ea643fdab4..fde274bb15a69 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type clock_t = i32; pub type wchar_t = i32; pub type time_t = i64; diff --git a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs index dbac03d2fb2ac..b511fc8457752 100644 --- a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i64; -pub type c_ulong = u64; pub type greg_t = u64; pub type __cpu_simple_lock_nv_t = c_uchar; diff --git a/src/unix/bsd/netbsdlike/netbsd/arm.rs b/src/unix/bsd/netbsdlike/netbsd/arm.rs index 698eba93b31a5..b252862dfe650 100644 --- a/src/unix/bsd/netbsdlike/netbsd/arm.rs +++ b/src/unix/bsd/netbsdlike/netbsd/arm.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i32; -pub type c_ulong = u32; pub type __cpu_simple_lock_nv_t = c_int; pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; diff --git a/src/unix/bsd/netbsdlike/netbsd/mips.rs b/src/unix/bsd/netbsdlike/netbsd/mips.rs index 028deb0cfbf76..eabfe1bbcc1e8 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mips.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mips.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i32; -pub type c_ulong = u32; pub type __cpu_simple_lock_nv_t = c_int; pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; diff --git a/src/unix/bsd/netbsdlike/netbsd/powerpc.rs b/src/unix/bsd/netbsdlike/netbsd/powerpc.rs index 20eba6849a3ee..fc4cc3898e12a 100644 --- a/src/unix/bsd/netbsdlike/netbsd/powerpc.rs +++ b/src/unix/bsd/netbsdlike/netbsd/powerpc.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i32; -pub type c_ulong = u32; pub type __cpu_simple_lock_nv_t = c_int; pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 0437b994ca276..550c3bd7bb4ea 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -2,8 +2,6 @@ use PT_FIRSTMACH; use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type __greg_t = u64; pub type __cpu_simple_lock_nv_t = c_int; pub type __gregset = [__greg_t; _NGREG]; diff --git a/src/unix/bsd/netbsdlike/netbsd/sparc64.rs b/src/unix/bsd/netbsdlike/netbsd/sparc64.rs index 3cfe535e7edfa..91622f7eea3fa 100644 --- a/src/unix/bsd/netbsdlike/netbsd/sparc64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/sparc64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type __cpu_simple_lock_nv_t = c_uchar; // should be pub(crate), but that requires Rust 1.18.0 diff --git a/src/unix/bsd/netbsdlike/netbsd/x86.rs b/src/unix/bsd/netbsdlike/netbsd/x86.rs index 04741f2dc1f4e..92e160d9bca0c 100644 --- a/src/unix/bsd/netbsdlike/netbsd/x86.rs +++ b/src/unix/bsd/netbsdlike/netbsd/x86.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type __cpu_simple_lock_nv_t = c_uchar; pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; diff --git a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs index 52f3da771a157..5d31c0661e9c6 100644 --- a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i64; -pub type c_ulong = u64; pub type c___greg_t = u64; pub type __cpu_simple_lock_nv_t = c_uchar; diff --git a/src/unix/bsd/netbsdlike/openbsd/aarch64.rs b/src/unix/bsd/netbsdlike/openbsd/aarch64.rs index 4cd0b32549835..2c4b1df26ce83 100644 --- a/src/unix/bsd/netbsdlike/openbsd/aarch64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/aarch64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type ucontext_t = sigcontext; s! { diff --git a/src/unix/bsd/netbsdlike/openbsd/arm.rs b/src/unix/bsd/netbsdlike/openbsd/arm.rs index 7fd17cf65a55f..ae91cde0a1739 100644 --- a/src/unix/bsd/netbsdlike/openbsd/arm.rs +++ b/src/unix/bsd/netbsdlike/openbsd/arm.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; - pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/mips64.rs b/src/unix/bsd/netbsdlike/openbsd/mips64.rs index 17ebae2889f17..162ceda265df9 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mips64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mips64.rs @@ -1,6 +1,3 @@ -pub type c_long = i64; -pub type c_ulong = u64; - #[doc(hidden)] pub const _ALIGNBYTES: usize = 7; diff --git a/src/unix/bsd/netbsdlike/openbsd/powerpc.rs b/src/unix/bsd/netbsdlike/openbsd/powerpc.rs index 7fd17cf65a55f..ae91cde0a1739 100644 --- a/src/unix/bsd/netbsdlike/openbsd/powerpc.rs +++ b/src/unix/bsd/netbsdlike/openbsd/powerpc.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; - pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs b/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs index 1a3b452091ce0..1c3d8df3b7956 100644 --- a/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/powerpc64.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; - pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/riscv64.rs b/src/unix/bsd/netbsdlike/openbsd/riscv64.rs index d37e9a67e6888..a0865406b80f3 100644 --- a/src/unix/bsd/netbsdlike/openbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/riscv64.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type ucontext_t = sigcontext; s! { diff --git a/src/unix/bsd/netbsdlike/openbsd/sparc64.rs b/src/unix/bsd/netbsdlike/openbsd/sparc64.rs index f8e165a7de299..88481f4f014e8 100644 --- a/src/unix/bsd/netbsdlike/openbsd/sparc64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/sparc64.rs @@ -1,6 +1,3 @@ -pub type c_long = i64; -pub type c_ulong = u64; - #[doc(hidden)] pub const _ALIGNBYTES: usize = 0xf; diff --git a/src/unix/bsd/netbsdlike/openbsd/x86.rs b/src/unix/bsd/netbsdlike/openbsd/x86.rs index cac4ea7f8e94c..d2cf7832edd7f 100644 --- a/src/unix/bsd/netbsdlike/openbsd/x86.rs +++ b/src/unix/bsd/netbsdlike/openbsd/x86.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; - pub(crate) const _ALIGNBYTES: usize = mem::size_of::() - 1; pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs index 683046836320d..db9114e27cb60 100644 --- a/src/unix/bsd/netbsdlike/openbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/openbsd/x86_64.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::PT_FIRSTMACH; -pub type c_long = i64; -pub type c_ulong = u64; pub type ucontext_t = sigcontext; s! { diff --git a/src/unix/haiku/b32.rs b/src/unix/haiku/b32.rs index c1135c834ef8b..1aa27e615ca4e 100644 --- a/src/unix/haiku/b32.rs +++ b/src/unix/haiku/b32.rs @@ -1,5 +1,3 @@ -pub type c_long = i32; -pub type c_ulong = u32; pub type time_t = i32; pub type Elf_Addr = crate::Elf32_Addr; diff --git a/src/unix/haiku/b64.rs b/src/unix/haiku/b64.rs index 96617042cf2ab..3355241fdb797 100644 --- a/src/unix/haiku/b64.rs +++ b/src/unix/haiku/b64.rs @@ -1,5 +1,3 @@ -pub type c_ulong = u64; -pub type c_long = i64; pub type time_t = i64; pub type Elf_Addr = crate::Elf64_Addr; diff --git a/src/unix/hurd/b32.rs b/src/unix/hurd/b32.rs index 5223d549dd025..e706789006dba 100644 --- a/src/unix/hurd/b32.rs +++ b/src/unix/hurd/b32.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; - pub type __int64_t = c_longlong; pub type __uint64_t = c_ulonglong; diff --git a/src/unix/hurd/b64.rs b/src/unix/hurd/b64.rs index 1954c27f88563..a44428c575adf 100644 --- a/src/unix/hurd/b64.rs +++ b/src/unix/hurd/b64.rs @@ -1,8 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; - pub type __int64_t = c_long; pub type __uint64_t = c_ulong; diff --git a/src/unix/linux_like/android/b32/mod.rs b/src/unix/linux_like/android/b32/mod.rs index 3e3485757ce98..42be94d425c72 100644 --- a/src/unix/linux_like/android/b32/mod.rs +++ b/src/unix/linux_like/android/b32/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; // The following definitions are correct for arm and i686, // but may be wrong for mips -pub type c_long = i32; -pub type c_ulong = u32; pub type mode_t = u16; pub type off64_t = c_longlong; pub type sigset_t = c_ulong; diff --git a/src/unix/linux_like/android/b64/mod.rs b/src/unix/linux_like/android/b64/mod.rs index 0da702b45d18e..cc407e113f67a 100644 --- a/src/unix/linux_like/android/b64/mod.rs +++ b/src/unix/linux_like/android/b64/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; // The following definitions are correct for aarch64 and x86_64, // but may be wrong for mips64 -pub type c_long = i64; -pub type c_ulong = u64; pub type mode_t = u32; pub type off64_t = i64; pub type socklen_t = u32; diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index c1c5108c17eb4..f22843e54073f 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -27,8 +27,6 @@ pub type blksize_t = c_long; pub type fsblkcnt_t = u32; pub type fsfilcnt_t = u32; pub type rlim_t = u64; -pub type c_long = i32; -pub type c_ulong = u32; pub type nlink_t = u32; pub type ino64_t = crate::ino_t; diff --git a/src/unix/linux_like/linux/gnu/b32/mod.rs b/src/unix/linux_like/linux/gnu/b32/mod.rs index adb36cc169fef..2cdd1320bf3e3 100644 --- a/src/unix/linux_like/linux/gnu/b32/mod.rs +++ b/src/unix/linux_like/linux/gnu/b32/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; use crate::pthread_mutex_t; -pub type c_long = i32; -pub type c_ulong = u32; pub type clock_t = i32; pub type shmatt_t = c_ulong; diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs index cec3b7ee28b5a..f808ff31f8cca 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs @@ -1,8 +1,6 @@ +use crate::prelude::*; use crate::pthread_mutex_t; -pub type c_long = i32; -pub type c_ulong = u32; - pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 32; pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs index 4b09e476d370c..960e5127806b3 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs @@ -1,8 +1,6 @@ +use crate::prelude::*; use crate::pthread_mutex_t; -pub type c_long = i64; -pub type c_ulong = u64; - pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8; pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 48; pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 8; diff --git a/src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs index e8f045ba5f83b..6162565da17ca 100644 --- a/src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs @@ -1,8 +1,6 @@ use crate::prelude::*; use crate::{off64_t, off_t, pthread_mutex_t}; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = i32; pub type blksize_t = i32; diff --git a/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs b/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs index 1d13bdb945d6e..375ea40cb6a1d 100644 --- a/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs @@ -2,8 +2,6 @@ use crate::prelude::*; use crate::{off64_t, off_t, pthread_mutex_t}; pub type blksize_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type nlink_t = u64; pub type suseconds_t = i64; pub type wchar_t = i32; diff --git a/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs b/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs index 3eda86440d40c..e537dbcd0a86a 100644 --- a/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; use crate::{off64_t, off_t, pthread_mutex_t}; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = i32; pub type nlink_t = u64; pub type blksize_t = i64; diff --git a/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs b/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs index 3dd9369457353..578057ce58ed2 100644 --- a/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; use crate::{off64_t, off_t}; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = c_int; pub type nlink_t = c_uint; diff --git a/src/unix/linux_like/linux/gnu/b64/s390x.rs b/src/unix/linux_like/linux/gnu/b64/s390x.rs index 7a48de58c967b..c08e12108b918 100644 --- a/src/unix/linux_like/linux/gnu/b64/s390x.rs +++ b/src/unix/linux_like/linux/gnu/b64/s390x.rs @@ -4,8 +4,6 @@ use crate::prelude::*; use crate::{off64_t, off_t, pthread_mutex_t}; pub type blksize_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type nlink_t = u64; pub type suseconds_t = i64; pub type wchar_t = i32; diff --git a/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs b/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs index 829686ff16ee5..f77606e10cbf5 100644 --- a/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; use crate::{off64_t, off_t, pthread_mutex_t}; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = i32; pub type nlink_t = u32; pub type blksize_t = i64; diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs index eb9563e53e2c0..27b96a60aabd8 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs @@ -1,9 +1,6 @@ use crate::prelude::*; use crate::pthread_mutex_t; -pub type c_long = i64; -pub type c_ulong = u64; - s! { pub struct statvfs { pub f_bsize: c_ulong, diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs index eafb5246c9edc..1a1cd34be035f 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs @@ -1,9 +1,6 @@ use crate::prelude::*; use crate::pthread_mutex_t; -pub type c_long = i32; -pub type c_ulong = u32; - s! { pub struct statvfs { pub f_bsize: c_ulong, diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 88d39c6316a40..c2fa6392fa500 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -2162,18 +2162,6 @@ cfg_if! { } } -cfg_if! { - if #[cfg(all( - any(target_env = "gnu", target_env = "musl", target_env = "ohos"), - any(target_arch = "x86_64", target_arch = "x86") - ))] { - extern "C" { - pub fn iopl(level: c_int) -> c_int; - pub fn ioperm(from: c_ulong, num: c_ulong, turn_on: c_int) -> c_int; - } - } -} - cfg_if! { if #[cfg(any( target_env = "gnu", @@ -6007,6 +5995,18 @@ safe_f! { } } +cfg_if! { + if #[cfg(all( + any(target_env = "gnu", target_env = "musl", target_env = "ohos"), + any(target_arch = "x86_64", target_arch = "x86") + ))] { + extern "C" { + pub fn iopl(level: c_int) -> c_int; + pub fn ioperm(from: c_ulong, num: c_ulong, turn_on: c_int) -> c_int; + } + } +} + cfg_if! { if #[cfg(all(not(target_env = "uclibc"), not(target_env = "ohos")))] { extern "C" { diff --git a/src/unix/linux_like/linux/musl/b32/mod.rs b/src/unix/linux_like/linux/musl/b32/mod.rs index 4a62ef1906ffb..00b3d7705090f 100644 --- a/src/unix/linux_like/linux/musl/b32/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/mod.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type nlink_t = u32; pub type blksize_t = c_long; pub type __u64 = c_ulonglong; diff --git a/src/unix/linux_like/linux/musl/b64/mod.rs b/src/unix/linux_like/linux/musl/b64/mod.rs index 50d862f570426..b6e7de6591809 100644 --- a/src/unix/linux_like/linux/musl/b64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/mod.rs @@ -1,7 +1,5 @@ use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type regoff_t = c_long; s! { diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index c237b7e160bbf..000d9e33a734a 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -2,8 +2,6 @@ use crate::off64_t; use crate::prelude::*; pub type wchar_t = c_uint; -pub type c_long = i32; -pub type c_ulong = u32; pub type time_t = c_long; pub type clock_t = c_long; diff --git a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs index a78daea80b62c..783b879cbf8dd 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs @@ -1,8 +1,6 @@ use crate::off64_t; use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; pub type clock_t = i32; pub type time_t = i32; pub type suseconds_t = i32; diff --git a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs index d0a0f345546b6..2e60f0d03fff9 100644 --- a/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs @@ -3,8 +3,6 @@ use crate::prelude::*; pub type blkcnt_t = i64; pub type blksize_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type fsblkcnt_t = c_ulong; pub type fsfilcnt_t = c_ulong; pub type ino_t = u64; diff --git a/src/unix/linux_like/linux/uclibc/x86_64/l4re.rs b/src/unix/linux_like/linux/uclibc/x86_64/l4re.rs index 7e1499a1fd8bd..b108e77c7cd32 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/l4re.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/l4re.rs @@ -28,7 +28,6 @@ s! { } } -#[cfg(target_os = "l4re")] #[allow(missing_debug_implementations)] pub struct pthread_attr_t { pub __detachstate: c_int, diff --git a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs index 016b6580c5754..684eef20473db 100644 --- a/src/unix/linux_like/linux/uclibc/x86_64/mod.rs +++ b/src/unix/linux_like/linux/uclibc/x86_64/mod.rs @@ -6,8 +6,6 @@ use crate::prelude::*; pub type blkcnt_t = i64; pub type blksize_t = i64; pub type clock_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type fsblkcnt_t = c_ulong; pub type fsfilcnt_t = c_ulong; pub type fsword_t = c_long; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 8a0aa3266759b..65c426c181aef 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -5,16 +5,6 @@ use crate::prelude::*; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; diff --git a/src/unix/newlib/aarch64/mod.rs b/src/unix/newlib/aarch64/mod.rs index f0ab09443da22..e4640580e2478 100644 --- a/src/unix/newlib/aarch64/mod.rs +++ b/src/unix/newlib/aarch64/mod.rs @@ -3,9 +3,6 @@ use crate::prelude::*; pub type clock_t = c_long; pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; - s! { pub struct sockaddr { pub sa_len: u8, diff --git a/src/unix/newlib/arm/mod.rs b/src/unix/newlib/arm/mod.rs index ae89440f237db..aea4ed764b03c 100644 --- a/src/unix/newlib/arm/mod.rs +++ b/src/unix/newlib/arm/mod.rs @@ -3,9 +3,6 @@ use crate::prelude::*; pub type clock_t = c_long; pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; - s! { pub struct sockaddr { pub sa_family: crate::sa_family_t, diff --git a/src/unix/newlib/espidf/mod.rs b/src/unix/newlib/espidf/mod.rs index 0bb8e3ae9c766..57a033fcaf263 100644 --- a/src/unix/newlib/espidf/mod.rs +++ b/src/unix/newlib/espidf/mod.rs @@ -3,9 +3,6 @@ use crate::prelude::*; pub type clock_t = c_ulong; pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; - s! { pub struct cmsghdr { pub cmsg_len: crate::socklen_t, diff --git a/src/unix/newlib/horizon/mod.rs b/src/unix/newlib/horizon/mod.rs index 05a1b284e295d..e98a4c53ccfff 100644 --- a/src/unix/newlib/horizon/mod.rs +++ b/src/unix/newlib/horizon/mod.rs @@ -3,9 +3,6 @@ use crate::off_t; use crate::prelude::*; -pub type c_long = i32; -pub type c_ulong = u32; - pub type wchar_t = c_uint; pub type u_register_t = c_uint; diff --git a/src/unix/newlib/powerpc/mod.rs b/src/unix/newlib/powerpc/mod.rs index b53c832a71aed..c4d4a2ed07c5e 100644 --- a/src/unix/newlib/powerpc/mod.rs +++ b/src/unix/newlib/powerpc/mod.rs @@ -3,9 +3,6 @@ use crate::prelude::*; pub type clock_t = c_ulong; pub type wchar_t = c_int; -pub type c_long = i32; -pub type c_ulong = u32; - pub use crate::unix::newlib::generic::{dirent, sigset_t, stat}; // the newlib shipped with devkitPPC does not support the following components: diff --git a/src/unix/newlib/vita/mod.rs b/src/unix/newlib/vita/mod.rs index 1f531cb4d35ff..822b61989d479 100644 --- a/src/unix/newlib/vita/mod.rs +++ b/src/unix/newlib/vita/mod.rs @@ -5,9 +5,6 @@ pub type clock_t = c_long; pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; - pub type sigset_t = c_ulong; s! { diff --git a/src/unix/nto/aarch64.rs b/src/unix/nto/aarch64.rs index acc36bbf75363..559ab6e49a45d 100644 --- a/src/unix/nto/aarch64.rs +++ b/src/unix/nto/aarch64.rs @@ -1,8 +1,6 @@ use crate::prelude::*; pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; pub type time_t = i64; s! { diff --git a/src/unix/nto/x86_64.rs b/src/unix/nto/x86_64.rs index 6cd24e187c443..521b5d4ab7879 100644 --- a/src/unix/nto/x86_64.rs +++ b/src/unix/nto/x86_64.rs @@ -1,8 +1,6 @@ use crate::prelude::*; pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; pub type time_t = i64; s! { diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs index bf6efdd7ae362..f77b104493670 100644 --- a/src/unix/nuttx/mod.rs +++ b/src/unix/nuttx/mod.rs @@ -5,8 +5,6 @@ pub type nlink_t = u16; pub type ino_t = u16; pub type blkcnt_t = u64; pub type blksize_t = i16; -pub type c_long = isize; -pub type c_ulong = usize; pub type cc_t = u8; pub type clock_t = i64; pub type dev_t = i32; diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 2f13157fff64a..c453f83efce60 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -2,20 +2,6 @@ use crate::prelude::*; pub type wchar_t = i32; -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - pub type c_long = i32; - pub type c_ulong = u32; - } -} - -cfg_if! { - if #[cfg(target_pointer_width = "64")] { - pub type c_long = i64; - pub type c_ulong = u64; - } -} - pub type blkcnt_t = c_ulong; pub type blksize_t = c_long; pub type clock_t = c_long; diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 25913377e4a17..3a335357d6b6b 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2,8 +2,6 @@ use core::mem::size_of; use crate::prelude::*; -pub type c_long = i64; -pub type c_ulong = u64; pub type caddr_t = *mut c_char; pub type clockid_t = c_int; diff --git a/src/vxworks/aarch64.rs b/src/vxworks/aarch64.rs index 630c7db54b55b..376783c8234ba 100644 --- a/src/vxworks/aarch64.rs +++ b/src/vxworks/aarch64.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/src/vxworks/arm.rs b/src/vxworks/arm.rs index 01fc7262f03e2..376783c8234ba 100644 --- a/src/vxworks/arm.rs +++ b/src/vxworks/arm.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index e7ec43ab5e430..2b910616d794c 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -14,16 +14,6 @@ impl Clone for DIR { } } -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; diff --git a/src/vxworks/powerpc.rs b/src/vxworks/powerpc.rs index 01fc7262f03e2..376783c8234ba 100644 --- a/src/vxworks/powerpc.rs +++ b/src/vxworks/powerpc.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/src/vxworks/powerpc64.rs b/src/vxworks/powerpc64.rs index 630c7db54b55b..376783c8234ba 100644 --- a/src/vxworks/powerpc64.rs +++ b/src/vxworks/powerpc64.rs @@ -1,3 +1 @@ pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/src/vxworks/riscv32.rs b/src/vxworks/riscv32.rs index 741e312afce17..f562626f7fb2b 100644 --- a/src/vxworks/riscv32.rs +++ b/src/vxworks/riscv32.rs @@ -1,3 +1 @@ pub type wchar_t = i32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/src/vxworks/riscv64.rs b/src/vxworks/riscv64.rs index 7bacd5c5abec4..f562626f7fb2b 100644 --- a/src/vxworks/riscv64.rs +++ b/src/vxworks/riscv64.rs @@ -1,3 +1 @@ pub type wchar_t = i32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/src/vxworks/x86.rs b/src/vxworks/x86.rs index 741e312afce17..f562626f7fb2b 100644 --- a/src/vxworks/x86.rs +++ b/src/vxworks/x86.rs @@ -1,3 +1 @@ pub type wchar_t = i32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/src/vxworks/x86_64.rs b/src/vxworks/x86_64.rs index 7bacd5c5abec4..f562626f7fb2b 100644 --- a/src/vxworks/x86_64.rs +++ b/src/vxworks/x86_64.rs @@ -1,3 +1 @@ pub type wchar_t = i32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index 909b33a20ac77..035ff8958ab20 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -7,16 +7,6 @@ use core::iter::Iterator; use crate::prelude::*; -pub type c_uchar = u8; -pub type c_schar = i8; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; pub type size_t = usize; @@ -28,8 +18,6 @@ pub type off_t = i64; pub type pid_t = i32; pub type clock_t = c_longlong; pub type time_t = c_longlong; -pub type c_double = f64; -pub type c_float = f32; pub type ino_t = u64; pub type sigset_t = c_uchar; pub type suseconds_t = c_longlong; @@ -44,6 +32,7 @@ pub type nfds_t = c_ulong; pub type wchar_t = i32; pub type nl_item = c_int; pub type __wasi_rights_t = u64; +pub type locale_t = *mut __locale_struct; s_no_extra_traits! { #[repr(align(16))] @@ -63,8 +52,6 @@ pub enum DIR {} #[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum __locale_struct {} -pub type locale_t = *mut __locale_struct; - s_paren! { // in wasi-libc clockid_t is const struct __clockid* (where __clockid is an opaque struct), // but that's an implementation detail that we don't want to have to deal with diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 632c33f461493..06cab0e5037a3 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -2,16 +2,6 @@ use crate::prelude::*; -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; @@ -22,8 +12,6 @@ pub type uintptr_t = usize; pub type ssize_t = isize; pub type sighandler_t = usize; -pub type c_long = i32; -pub type c_ulong = u32; pub type wchar_t = u16; pub type clock_t = i32; diff --git a/src/xous.rs b/src/xous.rs index 468865c8d4131..35350a723c8e9 100644 --- a/src/xous.rs +++ b/src/xous.rs @@ -1,15 +1,5 @@ //! Xous C type definitions -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; @@ -20,8 +10,6 @@ pub type uintptr_t = usize; pub type ssize_t = isize; pub type off_t = i64; -pub type c_long = i64; -pub type c_ulong = u64; pub type wchar_t = u32; pub const INT_MIN: c_int = -2147483648;