From 172e4b847168a9b3933addcf9c979b5be1cd8b10 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 23 Sep 2024 10:34:29 -0500 Subject: [PATCH 1/4] allow improper_ctypes --- crates/libs/windows/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index fa25ca9206..7bf46d686b 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -8,7 +8,7 @@ Learn more about Rust for Windows here: Date: Mon, 23 Sep 2024 10:39:46 -0500 Subject: [PATCH 2/4] windows-sys --- crates/libs/sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/libs/sys/src/lib.rs b/crates/libs/sys/src/lib.rs index 396dd24e1b..f4beca775e 100644 --- a/crates/libs/sys/src/lib.rs +++ b/crates/libs/sys/src/lib.rs @@ -6,7 +6,7 @@ Learn more about Rust for Windows here: Date: Mon, 23 Sep 2024 10:56:44 -0500 Subject: [PATCH 3/4] shared reference to mutable static --- crates/tests/misc/implement/tests/identity.rs | 82 +++++++++---------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/crates/tests/misc/implement/tests/identity.rs b/crates/tests/misc/implement/tests/identity.rs index 87ad3980f5..19ce6b3385 100644 --- a/crates/tests/misc/implement/tests/identity.rs +++ b/crates/tests/misc/implement/tests/identity.rs @@ -1,26 +1,23 @@ #![allow(non_snake_case)] +use std::sync::atomic::*; use windows::{core::*, Foundation::*}; -static mut COUNTER: isize = 0; +static COUNTER: AtomicIsize = AtomicIsize::new(0); #[implement(IStringable, IClosable)] struct Test(String); impl Test { fn new(value: &str) -> Self { - unsafe { - COUNTER += 1; - } + COUNTER.fetch_add(1, Ordering::Relaxed); Self(value.to_string()) } } impl Drop for Test { fn drop(&mut self) { - unsafe { - COUNTER -= 1; - } + COUNTER.fetch_sub(1, Ordering::Release); } } @@ -38,48 +35,47 @@ impl IClosable_Impl for Test_Impl { #[test] fn identity() -> Result<()> { - unsafe { - assert_eq!(COUNTER, 0); - { - let a: IStringable = Test::new("test").into(); - assert!(a.ToString()? == "test"); + assert_eq!(COUNTER.load(Ordering::Acquire), 0); + { + let a: IStringable = Test::new("test").into(); + assert_eq!(COUNTER.load(Ordering::Acquire), 1); + assert!(a.ToString()? == "test"); - let b: IClosable = a.cast()?; - b.Close()?; + let b: IClosable = a.cast()?; + b.Close()?; - let c: IUnknown = b.cast()?; + let c: IUnknown = b.cast()?; - let d: IInspectable = c.cast()?; + let d: IInspectable = c.cast()?; - assert!(a == d.cast()?); - } - { - let a: IUnknown = Test::new("test").into(); - let b: IClosable = a.cast()?; - let c: IStringable = b.cast()?; - assert!(c.ToString()? == "test"); - } - { - let a: IInspectable = Test::new("test").into(); - let b: IStringable = a.cast()?; - assert!(b.ToString()? == "test"); - } - { - let a: IInspectable = Test::new("test").into(); - assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); + assert!(a == d.cast()?); + } + { + let a: IUnknown = Test::new("test").into(); + let b: IClosable = a.cast()?; + let c: IStringable = b.cast()?; + assert!(c.ToString()? == "test"); + } + { + let a: IInspectable = Test::new("test").into(); + let b: IStringable = a.cast()?; + assert!(b.ToString()? == "test"); + } + { + let a: IInspectable = Test::new("test").into(); + assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); - let b: IStringable = a.cast()?; - let c: &IInspectable = &b.cast()?; - assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); + let b: IStringable = a.cast()?; + let c: &IInspectable = &b.cast()?; + assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); - let d: IClosable = a.cast()?; - let e: &IInspectable = (&d).into(); - assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable"); + let d: IClosable = a.cast()?; + let e: &IInspectable = (&d).into(); + assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable"); - let f: IInspectable = e.cast()?; - assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); - } - assert_eq!(COUNTER, 0); - Ok(()) + let f: IInspectable = e.cast()?; + assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable"); } + assert_eq!(COUNTER.load(Ordering::Acquire), 0); + Ok(()) } From 1b841eeedff94cc4f3aa1de0c0d83d782bdb2467 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 23 Sep 2024 12:05:38 -0500 Subject: [PATCH 4/4] todo --- crates/libs/sys/src/lib.rs | 4 +++- crates/libs/windows/src/lib.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/libs/sys/src/lib.rs b/crates/libs/sys/src/lib.rs index f4beca775e..1dd5d5a334 100644 --- a/crates/libs/sys/src/lib.rs +++ b/crates/libs/sys/src/lib.rs @@ -6,8 +6,10 @@ Learn more about Rust for Windows here: