From c43a7448ae99be9b5710b4d226673d8c899fdea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20J=2E=20Saraiva?= Date: Thu, 9 Jan 2025 06:46:26 +0000 Subject: [PATCH 1/2] Use portable-atomic when AtomicU64 is not available. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Flávio J. Saraiva --- Cargo.toml | 3 +++ src/metric.rs | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 70e92b5..547678d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,9 @@ libc = "0.2.39" serde = { version = "1.0.27", optional = true } serde_derive = { version = "1.0.27", optional = true } +[target.'cfg(not(target_has_atomic = "u64"))'.dependencies] +portable-atomic = "1" + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] bitflags = "1.0" diff --git a/src/metric.rs b/src/metric.rs index c8b0e2b..eeca853 100644 --- a/src/metric.rs +++ b/src/metric.rs @@ -11,7 +11,12 @@ //! of these components can choose what metrics they’re interested in and also //! can add their own custom metrics without the need to maintain forks. -use std::sync::atomic::{AtomicU64, Ordering}; +#[cfg(target_has_atomic = "64")] +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; + +#[cfg(not(target_has_atomic = "64"))] +use portable_atomic::AtomicU64; /// Abstraction over the common metric operations. /// @@ -63,9 +68,13 @@ impl Metric for AtomicU64 { mod tests { use crate::metric::Metric; + #[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::Arc; + #[cfg(not(target_has_atomic = "64"))] + use portable_atomic::AtomicU64; + struct Dog { metrics: T, } From 2d0a5fd8581006aea8f89060c87228245c8e9977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20J=2E=20Saraiva?= Date: Thu, 9 Jan 2025 06:51:02 +0000 Subject: [PATCH 2/2] Fix tests for my 32-bit OS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Flávio J. Saraiva --- src/fam.rs | 2 +- src/linux/sock_ctrl_msg.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fam.rs b/src/fam.rs index c216495..ac7c1e0 100644 --- a/src/fam.rs +++ b/src/fam.rs @@ -757,7 +757,7 @@ mod tests { fn test_invalid_type_conversion() { let mut adapter = MockFamStructWrapperU8::new(10).unwrap(); assert!(matches!( - adapter.set_len(0xffff_ffff_ffff_ff00), + adapter.set_len(usize::MAX & !0xff), Err(Error::SizeLimitExceeded) )); } diff --git a/src/linux/sock_ctrl_msg.rs b/src/linux/sock_ctrl_msg.rs index bc797e9..cf3cca9 100644 --- a/src/linux/sock_ctrl_msg.rs +++ b/src/linux/sock_ctrl_msg.rs @@ -479,15 +479,15 @@ mod tests { if size_of::() == 4 { assert_eq!( CMSG_SPACE!(2 * size_of::()), - size_of::() + size_of::() + size_of::() + size_of::() * 2 ); assert_eq!( CMSG_SPACE!(3 * size_of::()), - size_of::() + size_of::() * 2 + size_of::() + size_of::() * 3 ); assert_eq!( CMSG_SPACE!(4 * size_of::()), - size_of::() + size_of::() * 2 + size_of::() + size_of::() * 4 ); } else if size_of::() == 8 { assert_eq!(