From 1c1e7e3bc336cf42084e137e8b212bfe6411dcd9 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 4 May 2020 15:15:08 -0700 Subject: [PATCH 01/24] delegate --- crates/winmd/src/types/delegate.rs | 13 ++++++++----- crates/winmd/src/types/type_kind.rs | 25 ++++++++----------------- tests/xaml.rs | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 8fb970e35d..d9b24a3ad7 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -41,7 +41,7 @@ impl Delegate { #[repr(transparent)] #[derive(Default)] pub struct #definition where #constraints { - ptr: ::winrt::IUnknown, + ptr: ::winrt::ComPtr<#name>, #phantoms } unsafe impl<#constraints> ::winrt::ComInterface for #name { @@ -58,17 +58,20 @@ impl Delegate { } #[repr(C)] pub struct #abi_definition where #constraints { - __base: [usize; 6], + pub unknown_query_interface: + extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>, &::winrt::Guid, *mut ::winrt::RawPtr) -> ::winrt::ErrorCode, + pub unknown_add_ref: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, + pub unknown_release: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, #abi_method #phantoms } unsafe impl<#constraints> ::winrt::RuntimeType for #name { - type Abi = ::winrt::RawPtr; + type Abi = ::winrt::RawComPtr; fn abi(&self) -> Self::Abi { - <::winrt::IUnknown as ::winrt::ComInterface>::as_raw(&self.ptr) as Self::Abi + <::winrt::ComPtr as ::winrt::ComInterface>::as_raw(&self.ptr) } fn set_abi(&mut self) -> *mut Self::Abi { - self.ptr.set_abi() as _ + self.ptr.set_abi() } } } diff --git a/crates/winmd/src/types/type_kind.rs b/crates/winmd/src/types/type_kind.rs index b27b8fbe40..7493e9f676 100644 --- a/crates/winmd/src/types/type_kind.rs +++ b/crates/winmd/src/types/type_kind.rs @@ -218,32 +218,23 @@ impl TypeKind { Self::U64 => quote! { u64, }, Self::F32 => quote! { f32, }, Self::F64 => quote! { f64, }, + Self::Guid => quote! { ::winrt::Guid, }, Self::String => { quote! { <::winrt::HString as ::winrt::RuntimeType>::Abi, } } Self::Object => { quote! { <::winrt::Object as ::winrt::RuntimeType>::Abi, } } - Self::Guid => quote! { ::winrt::Guid, }, - Self::Class(c) => { - let name = c.to_tokens(calling_namespace); - quote! { <#name as ::winrt::RuntimeType>::Abi, } - } - Self::Interface(i) => { - let name = i.to_tokens(calling_namespace); - quote! { <#name as ::winrt::RuntimeType>::Abi, } - } - Self::Enum(name) => { - let name = name.to_tokens(calling_namespace); + Self::Generic(name) => { + let name = format_ident(name); quote! { <#name as ::winrt::RuntimeType>::Abi, } } - Self::Struct(name) => { + Self::Class(name) + | Self::Interface(name) + | Self::Delegate(name) + | Self::Enum(name) + | Self::Struct(name) => { let name = name.to_tokens(calling_namespace); - quote! { #name, } - } - Self::Delegate(_) => quote! { ::winrt::RawPtr, }, - Self::Generic(name) => { - let name = format_ident(name); quote! { <#name as ::winrt::RuntimeType>::Abi, } } } diff --git a/tests/xaml.rs b/tests/xaml.rs index 8f6105baf1..ccf5ef8384 100644 --- a/tests/xaml.rs +++ b/tests/xaml.rs @@ -1,11 +1,11 @@ -winrt::import!( - dependencies - "os" - modules - "windows.ui.xaml" -); +// winrt::import!( +// dependencies +// "os" +// modules +// "windows.ui.xaml" +// ); -#[test] -fn xaml() -> winrt::Result<()> { - Ok(()) -} +// #[test] +// fn xaml() -> winrt::Result<()> { +// Ok(()) +// } From fbe6f26405bf54aa87f13d3d2637ff1f0dae3b07 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 4 May 2020 15:28:14 -0700 Subject: [PATCH 02/24] abi --- crates/winmd/src/types/delegate.rs | 3 +-- crates/winmd/src/types/interface.rs | 7 ++++++- src/object.rs | 11 +++++++++-- src/unknown.rs | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index d9b24a3ad7..9db08e472e 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -58,8 +58,7 @@ impl Delegate { } #[repr(C)] pub struct #abi_definition where #constraints { - pub unknown_query_interface: - extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>, &::winrt::Guid, *mut ::winrt::RawPtr) -> ::winrt::ErrorCode, + pub unknown_query_interface: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>, &::winrt::Guid, *mut ::winrt::RawPtr) -> ::winrt::ErrorCode, pub unknown_add_ref: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, pub unknown_release: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, #abi_method diff --git a/crates/winmd/src/types/interface.rs b/crates/winmd/src/types/interface.rs index 7734816ad3..87403fc33d 100644 --- a/crates/winmd/src/types/interface.rs +++ b/crates/winmd/src/types/interface.rs @@ -85,7 +85,12 @@ impl Interface { } #[repr(C)] pub struct #abi_definition where #constraints { - __base: [usize; 6], + pub unknown_query_interface: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>, &::winrt::Guid, *mut ::winrt::RawPtr) -> ::winrt::ErrorCode, + pub unknown_add_ref: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, + pub unknown_release: extern "system" fn(::winrt::RawComPtr<::winrt::IUnknown>) -> u32, + pub inspectable_iids: extern "system" fn(::winrt::RawComPtr<::winrt::Object>, *mut u32, *mut *mut ::winrt::Guid) -> ::winrt::ErrorCode, + pub inspectable_type_name: extern "system" fn(::winrt::RawComPtr<::winrt::Object>, *mut <::winrt::HString as ::winrt::RuntimeType>::Abi) -> ::winrt::ErrorCode, + pub inspectable_trust_level: extern "system" fn(::winrt::RawComPtr<::winrt::Object>, *mut i32) -> ::winrt::ErrorCode, #abi_methods #phantoms } diff --git a/src/object.rs b/src/object.rs index c274b11cb5..345d1ac979 100644 --- a/src/object.rs +++ b/src/object.rs @@ -47,7 +47,14 @@ unsafe impl RuntimeType for Object { #[repr(C)] pub struct abi_IInspectable { - __base: [usize; 4], - inspectable_type_name: + pub unknown_query_interface: + extern "system" fn(RawComPtr, &Guid, *mut RawPtr) -> ErrorCode, + pub unknown_add_ref: extern "system" fn(RawComPtr) -> u32, + pub unknown_release: extern "system" fn(RawComPtr) -> u32, + + pub inspectable_iids: + extern "system" fn(RawComPtr, *mut u32, *mut *mut Guid) -> ErrorCode, + pub inspectable_type_name: extern "system" fn(RawComPtr, *mut ::Abi) -> ErrorCode, + pub inspectable_trust_level: extern "system" fn(RawComPtr, *mut i32) -> ErrorCode, } diff --git a/src/unknown.rs b/src/unknown.rs index 55221af089..ac1eed6054 100644 --- a/src/unknown.rs +++ b/src/unknown.rs @@ -25,8 +25,8 @@ unsafe impl ComInterface for IUnknown { #[repr(C)] pub struct abi_IUnknown { - pub(crate) unknown_query_interface: + pub unknown_query_interface: extern "system" fn(RawComPtr, &Guid, *mut RawPtr) -> ErrorCode, - pub(crate) unknown_add_ref: extern "system" fn(RawComPtr) -> u32, - pub(crate) unknown_release: extern "system" fn(RawComPtr) -> u32, + pub unknown_add_ref: extern "system" fn(RawComPtr) -> u32, + pub unknown_release: extern "system" fn(RawComPtr) -> u32, } From 67f994a923326d6486f4672021c8b8cff46b3c5b Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Mon, 4 May 2020 16:18:10 -0700 Subject: [PATCH 03/24] refcount --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 6fbc11712b..af07269e58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,7 @@ pub use runtime_type::RuntimeType; pub use try_into::TryInto; pub use unknown::IUnknown; pub use winrt_macros::import; +pub use ref_count::RefCount; /// A convenient alias of a void pointer pub type RawPtr = *mut std::ffi::c_void; From 5b306c76e6a6aa167c349ca380898661cf4e874c Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 5 May 2020 16:54:30 -0700 Subject: [PATCH 04/24] works --- crates/macros/src/lib.rs | 2 +- crates/winmd/src/types/delegate.rs | 4 ++++ src/agile_object.rs | 25 +++++++++++++++++++++++++ src/error.rs | 11 +++++++++++ src/hstring.rs | 2 +- src/lib.rs | 4 +++- src/ref_count.rs | 2 +- 7 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/agile_object.rs diff --git a/crates/macros/src/lib.rs b/crates/macros/src/lib.rs index 9549606abc..95a7e6c6b2 100644 --- a/crates/macros/src/lib.rs +++ b/crates/macros/src/lib.rs @@ -22,7 +22,7 @@ pub fn import(stream: TokenStream) -> TokenStream { let stage = TypeStage::from_limits(reader, &limits); let tree = stage.into_tree(); let stream = tree.to_tokens(); - + std::fs::write(r"c:\git\rust\dump.rs", stream.to_string()).unwrap(); stream.into() } diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 9db08e472e..292b3f512a 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -34,6 +34,7 @@ impl Delegate { let name = self.name.to_tokens(&self.name.namespace); let phantoms = self.name.phantoms(); let constraints = self.name.constraints(); + let method = self.method.to_default_tokens(&self.name.namespace); let abi_method = self.method.to_abi_tokens(&self.name, &self.name.namespace); let guid = self.guid.to_tokens(); @@ -44,6 +45,9 @@ impl Delegate { ptr: ::winrt::ComPtr<#name>, #phantoms } + impl<#constraints> #name { + #method + } unsafe impl<#constraints> ::winrt::ComInterface for #name { type VTable = #abi_definition; const IID: ::winrt::Guid = ::winrt::Guid::from_values(#guid); diff --git a/src/agile_object.rs b/src/agile_object.rs new file mode 100644 index 0000000000..4113e41d93 --- /dev/null +++ b/src/agile_object.rs @@ -0,0 +1,25 @@ +use crate::*; + +#[repr(transparent)] +#[derive(Default, Clone)] +pub struct IAgileObject { + ptr: ComPtr, +} + +unsafe impl ComInterface for IAgileObject { + type VTable = abi_IAgileObject; + const IID: Guid = Guid::from_values( + 0x94EA2B94, + 0xE9CC, + 0x49E0, + [0xC0, 0xFF, 0xEE, 0x64, 0xCA, 0x8F, 0x5B, 0x90], + ); +} + +#[repr(C)] +pub struct abi_IAgileObject { + pub unknown_query_interface: + extern "system" fn(RawComPtr, &Guid, *mut RawPtr) -> ErrorCode, + pub unknown_add_ref: extern "system" fn(RawComPtr) -> u32, + pub unknown_release: extern "system" fn(RawComPtr) -> u32, +} diff --git a/src/error.rs b/src/error.rs index 47810a3112..603b8c76bc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,17 @@ #[must_use] pub type Result = std::result::Result; +impl std::convert::From> for ErrorCode { + fn from(result: Result) -> Self { + if let Err(error) = result { + // TODO: call SetErrorInfo + return error.code(); + } + + ErrorCode(0) + } +} + /// A WinRT related error #[derive(Debug)] pub struct Error { diff --git a/src/hstring.rs b/src/hstring.rs index d0e6745b10..2b800fae99 100644 --- a/src/hstring.rs +++ b/src/hstring.rs @@ -230,7 +230,7 @@ impl Header { fn duplicate(&mut self) -> *mut Header { if self.flags & REFERENCE_FLAG == 0 { unsafe { - (*self.shared.as_ptr()).count.addref(); + (*self.shared.as_ptr()).count.add_ref(); self } } else { diff --git a/src/lib.rs b/src/lib.rs index af07269e58..3a6d78ea6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,7 @@ #[doc(hidden)] pub mod activation; +pub mod agile_object; mod array; mod com_interface; mod com_ptr; @@ -55,6 +56,7 @@ mod unknown; #[doc(inline)] pub use activation::IActivationFactory; +pub use agile_object::IAgileObject; pub use array::Array; pub use com_interface::{ComInterface, RawComPtr}; pub use com_ptr::ComPtr; @@ -63,12 +65,12 @@ pub use guid::Guid; pub use hstring::HString; pub use object::Object; pub use param::Param; +pub use ref_count::RefCount; pub use runtime_name::RuntimeName; pub use runtime_type::RuntimeType; pub use try_into::TryInto; pub use unknown::IUnknown; pub use winrt_macros::import; -pub use ref_count::RefCount; /// A convenient alias of a void pointer pub type RawPtr = *mut std::ffi::c_void; diff --git a/src/ref_count.rs b/src/ref_count.rs index 46220d69fc..c035757431 100644 --- a/src/ref_count.rs +++ b/src/ref_count.rs @@ -12,7 +12,7 @@ impl RefCount { } } - pub fn addref(&self) -> u32 { + pub fn add_ref(&self) -> u32 { self.value.fetch_add(1, Ordering::Relaxed) + 1 } From f1515b4862d6a712ab73e7ddf792db988c5f5a26 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 07:46:33 -0700 Subject: [PATCH 05/24] delegate --- crates/winmd/src/lib.rs | 4 ---- crates/winmd/src/types/delegate.rs | 18 ++++++++++++++++++ crates/winmd/src/types/type_name.rs | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/winmd/src/lib.rs b/crates/winmd/src/lib.rs index 600ad53f46..9e29872aaa 100644 --- a/crates/winmd/src/lib.rs +++ b/crates/winmd/src/lib.rs @@ -25,10 +25,6 @@ fn format_ident(name: &str) -> proc_macro2::Ident { } } -fn format_abi_ident(name: &str) -> proc_macro2::Ident { - quote::format_ident!("abi_{}", name) -} - #[cfg(target_pointer_width = "64")] const SYSTEM32: &str = "System32"; diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 292b3f512a..6dbc4a38c7 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -31,6 +31,7 @@ impl Delegate { pub fn to_tokens(&self) -> TokenStream { let definition = self.name.to_definition_tokens(&self.name.namespace); let abi_definition = self.name.to_abi_definition_tokens(&self.name.namespace); + let impl_definition = self.to_impl_definition_tokens(); let name = self.name.to_tokens(&self.name.namespace); let phantoms = self.name.phantoms(); let constraints = self.name.constraints(); @@ -79,4 +80,21 @@ impl Delegate { } } } + + pub fn to_impl_definition_tokens(&self) -> TokenStream { + let namespace = to_namespace_tokens(&self.name.namespace, &self.name.namespace); + + if self.name.generics.is_empty() { + let name = format_impl_ident(&self.name.name); + quote! { #namespace#name } + } else { + let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); + let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); + quote! { #namespace#name<#(#generics),*> } + } + } +} + +fn format_impl_ident(name: &str) -> proc_macro2::Ident { + quote::format_ident!("impl_{}", name) } diff --git a/crates/winmd/src/types/type_name.rs b/crates/winmd/src/types/type_name.rs index b511e4c17f..9240883344 100644 --- a/crates/winmd/src/types/type_name.rs +++ b/crates/winmd/src/types/type_name.rs @@ -303,6 +303,10 @@ impl TypeName { } } +fn format_abi_ident(name: &str) -> proc_macro2::Ident { + quote::format_ident!("abi_{}", name) +} + #[cfg(test)] mod tests { use super::*; From c8263d39a74d787744c3459f025d7d2eee5c8689 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 08:39:19 -0700 Subject: [PATCH 06/24] to_impl_definition_tokens --- crates/winmd/src/types/delegate.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 6dbc4a38c7..398de2134c 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -78,19 +78,23 @@ impl Delegate { self.ptr.set_abi() } } + #[repr(C)] + struct #impl_definition where #constraints { + vtable: *const #abi_definition, + count: ::winrt::RefCount, + invoke: F, + } } } pub fn to_impl_definition_tokens(&self) -> TokenStream { - let namespace = to_namespace_tokens(&self.name.namespace, &self.name.namespace); - if self.name.generics.is_empty() { let name = format_impl_ident(&self.name.name); - quote! { #namespace#name } + quote! { #name ::winrt::Result<()>> } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); - quote! { #namespace#name<#(#generics),*> } + quote! { #name<#(#generics,)* F: FnMut() -> ::winrt::Result<()>> } } } } From adb53546b337dbf9664198ff69a7e57ccfe40b2e Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 08:42:18 -0700 Subject: [PATCH 07/24] simpler --- crates/winmd/src/types/type_name.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/winmd/src/types/type_name.rs b/crates/winmd/src/types/type_name.rs index 9240883344..f3dcc6f678 100644 --- a/crates/winmd/src/types/type_name.rs +++ b/crates/winmd/src/types/type_name.rs @@ -255,27 +255,24 @@ impl TypeName { // and we would simply use to_tokens and to_abi_tokens everywhere but Rust is really // weird in requiring `IVector` in some places and `IVector::` in others. pub fn to_definition_tokens(&self, calling_namespace: &str) -> TokenStream { - let namespace = to_namespace_tokens(&self.namespace, calling_namespace); if self.generics.is_empty() { let name = format_ident(&self.name); - quote! { #namespace#name } + quote! { #name } } else { let name = format_ident(&self.name[..self.name.len() - 2]); let generics = self.generics.iter().map(|g| g.to_tokens(calling_namespace)); - quote! { #namespace#name<#(#generics),*> } + quote! { #name<#(#generics),*> } } } pub fn to_abi_definition_tokens(&self, calling_namespace: &str) -> TokenStream { - let namespace = to_namespace_tokens(&self.namespace, calling_namespace); - if self.generics.is_empty() { let name = format_abi_ident(&self.name); - quote! { #namespace#name } + quote! { #name } } else { let name = format_abi_ident(&self.name[..self.name.len() - 2]); let generics = self.generics.iter().map(|g| g.to_tokens(calling_namespace)); - quote! { #namespace#name<#(#generics),*> } + quote! { #name<#(#generics),*> } } } From 9c2c5717e356bc2125d094bceca80990456f3ad4 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 11:32:38 -0700 Subject: [PATCH 08/24] fn --- crates/winmd/src/types/delegate.rs | 12 ++++++++++-- crates/winmd/src/types/param.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 398de2134c..52f8fc23aa 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -88,13 +88,21 @@ impl Delegate { } pub fn to_impl_definition_tokens(&self) -> TokenStream { + let params = self.method.params.iter().map(|param| param.to_fn_tokens(&self.name.namespace)); + + let return_type = if let Some(return_type) = &self.method.return_type { + return_type.to_return_tokens(&self.name.namespace) + } else { + quote! { () } + }; + if self.name.generics.is_empty() { let name = format_impl_ident(&self.name.name); - quote! { #name ::winrt::Result<()>> } + quote! { #name ::winrt::Result<#return_type>> } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); - quote! { #name<#(#generics,)* F: FnMut() -> ::winrt::Result<()>> } + quote! { #name<#(#generics,)* F: FnMut(#(#params)*) -> ::winrt::Result<#return_type>> } } } } diff --git a/crates/winmd/src/types/param.rs b/crates/winmd/src/types/param.rs index d7336272a7..dfc6d39a1f 100644 --- a/crates/winmd/src/types/param.rs +++ b/crates/winmd/src/types/param.rs @@ -45,6 +45,36 @@ impl Param { } } + pub fn to_fn_tokens(&self, calling_namespace: &str) -> TokenStream { + let tokens = self.kind.to_tokens(calling_namespace); + + if self.array { + if self.input { + quote! { &[#tokens], } + } else if self.by_ref { + quote! { &mut ::winrt::Array<#tokens>, } + } else { + quote! { &mut [#tokens], } + } + } else if self.input { + match self.kind { + TypeKind::String + | TypeKind::Object + | TypeKind::Guid + | TypeKind::Class(_) + | TypeKind::Interface(_) + | TypeKind::Struct(_) + | TypeKind::Delegate(_) + | TypeKind::Generic(_) => { + quote! { &#tokens, } + } + _ => quote! { #tokens, }, + } + } else { + quote! { &mut #tokens, } + } + } + pub fn to_return_tokens(&self, calling_namespace: &str) -> TokenStream { let tokens = self.kind.to_tokens(calling_namespace); From 7ef0271e22047db37d28c782d31c4ca7eb64b430 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 11:50:10 -0700 Subject: [PATCH 09/24] impl impl --- crates/winmd/src/types/delegate.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 52f8fc23aa..eac43574e2 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -31,8 +31,10 @@ impl Delegate { pub fn to_tokens(&self) -> TokenStream { let definition = self.name.to_definition_tokens(&self.name.namespace); let abi_definition = self.name.to_abi_definition_tokens(&self.name.namespace); - let impl_definition = self.to_impl_definition_tokens(); + let fn_constraint = self.to_fn_constraint_tokens(); + let impl_definition = self.to_impl_definition_tokens(&fn_constraint); let name = self.name.to_tokens(&self.name.namespace); + let impl_name = self.to_impl_name_tokens(); let phantoms = self.name.phantoms(); let constraints = self.name.constraints(); let method = self.method.to_default_tokens(&self.name.namespace); @@ -84,10 +86,13 @@ impl Delegate { count: ::winrt::RefCount, invoke: F, } + impl<#constraints #fn_constraint> #impl_name { + + } } } - pub fn to_impl_definition_tokens(&self) -> TokenStream { + fn to_fn_constraint_tokens(&self) -> TokenStream { let params = self.method.params.iter().map(|param| param.to_fn_tokens(&self.name.namespace)); let return_type = if let Some(return_type) = &self.method.return_type { @@ -96,13 +101,28 @@ impl Delegate { quote! { () } }; + quote! { F: FnMut(#(#params)*) -> ::winrt::Result<#return_type> } + } + + fn to_impl_definition_tokens(&self, fn_constraint: &TokenStream) -> TokenStream { + if self.name.generics.is_empty() { + let name = format_impl_ident(&self.name.name); + quote! { #name<#fn_constraint> } + } else { + let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); + let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); + quote! { #name<#(#generics,)* #fn_constraint> } + } + } + + pub fn to_impl_name_tokens(&self) -> TokenStream { if self.name.generics.is_empty() { let name = format_impl_ident(&self.name.name); - quote! { #name ::winrt::Result<#return_type>> } + quote! { #name } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); - quote! { #name<#(#generics,)* F: FnMut(#(#params)*) -> ::winrt::Result<#return_type>> } + quote! { #name::<#(#generics,)* F> } } } } From fb56a940366e11b0d5827b9f0e23911d7733c9a3 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 11:59:54 -0700 Subject: [PATCH 10/24] add_ref release --- crates/winmd/src/types/delegate.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index eac43574e2..c0178f669c 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -88,6 +88,24 @@ impl Delegate { } impl<#constraints #fn_constraint> #impl_name { + extern "system" fn unknown_add_ref(this: ::winrt::RawComPtr<::winrt::IUnknown>) -> u32 { + unsafe { + let this = this as *const Self as *mut Self; + (*this).count.add_ref() + } + } + extern "system" fn unknown_release(this: ::winrt::RawComPtr<::winrt::IUnknown>) -> u32 { + unsafe { + let this = this as *const Self as *mut Self; + let remaining = (*this).count.release(); + + if remaining == 0 { + Box::from_raw(this); + } + + remaining + } + } } } } @@ -115,7 +133,7 @@ impl Delegate { } } - pub fn to_impl_name_tokens(&self) -> TokenStream { + fn to_impl_name_tokens(&self) -> TokenStream { if self.name.generics.is_empty() { let name = format_impl_ident(&self.name.name); quote! { #name } From 5236166cdfbb4d4a3e98f77074d5e8479f3f69f1 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 12:07:54 -0700 Subject: [PATCH 11/24] qi --- crates/winmd/src/types/delegate.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index c0178f669c..305d47d976 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -88,6 +88,27 @@ impl Delegate { } impl<#constraints #fn_constraint> #impl_name { + extern "system" fn unknown_query_interface( + this: ::winrt::RawComPtr<::winrt::IUnknown>, + iid: &::winrt::Guid, + interface: *mut ::winrt::RawPtr, + ) -> ::winrt::ErrorCode { + unsafe { + let this = this as *const Self as *mut Self; + + if *iid == <#name as ::winrt::ComInterface>::IID + || *iid == <::winrt::IUnknown as ::winrt::ComInterface>::IID + || *iid == <::winrt::IAgileObject as ::winrt::ComInterface>::IID + { + *interface = this as ::winrt::RawPtr; + (*this).count.add_ref(); + return ::winrt::ErrorCode(0); + } + + *interface = std::ptr::null_mut(); + ::winrt::ErrorCode(0x80004002) + } + } extern "system" fn unknown_add_ref(this: ::winrt::RawComPtr<::winrt::IUnknown>) -> u32 { unsafe { let this = this as *const Self as *mut Self; From 79f4db047a790d1867182cd4a9cc3f4bae8996eb Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 13:56:38 -0700 Subject: [PATCH 12/24] invoke --- crates/winmd/src/types/delegate.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 305d47d976..c09332d72f 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -127,6 +127,12 @@ impl Delegate { remaining } } + extern "system" fn invoke(this: *const *const #abi_definition) -> ::winrt::ErrorCode { + unsafe { + let this = this as *const Self as *mut Self; + ::winrt::ErrorCode(0) + } + } } } } From 28e42217c02119a8e8e78b77be7cf98e666da425 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 14:12:27 -0700 Subject: [PATCH 13/24] invoke_sig --- crates/winmd/src/types/delegate.rs | 3 ++- crates/winmd/src/types/method.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index c09332d72f..714484c0e8 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -40,6 +40,7 @@ impl Delegate { let method = self.method.to_default_tokens(&self.name.namespace); let abi_method = self.method.to_abi_tokens(&self.name, &self.name.namespace); let guid = self.guid.to_tokens(); + let invoke_sig = self.method.to_abi_impl_tokens(&self.name, &self.name.namespace); quote! { #[repr(transparent)] @@ -127,7 +128,7 @@ impl Delegate { remaining } } - extern "system" fn invoke(this: *const *const #abi_definition) -> ::winrt::ErrorCode { + #invoke_sig { unsafe { let this = this as *const Self as *mut Self; ::winrt::ErrorCode(0) diff --git a/crates/winmd/src/types/method.rs b/crates/winmd/src/types/method.rs index e3d3b9f7df..7b4b21a6db 100644 --- a/crates/winmd/src/types/method.rs +++ b/crates/winmd/src/types/method.rs @@ -147,6 +147,25 @@ impl Method { } } + pub fn to_abi_impl_tokens(&self, self_name: &TypeName, calling_namespace: &str) -> TokenStream { + let abi_name = self_name.to_abi_tokens(calling_namespace); + let name = format_ident(&self.name); + let params = + self.params + .iter() + .chain(self.return_type.iter()) + .map(|param| { + let name = format_ident(¶m.name); + let abi = param.to_abi_tokens(calling_namespace); + quote! { #name: #abi } + }); + + + quote! { + extern "system" fn #name(this: *const *const #abi_name, #(#params)*) -> ::winrt::ErrorCode + } + } + fn to_param_tokens(&self, calling_namespace: &str) -> TokenStream { TokenStream::from_iter( self.params From 7d4f48b9dfcd90819c15995af6201998b989df5c Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 23:19:40 -0700 Subject: [PATCH 14/24] from_abi --- crates/winmd/src/types/delegate.rs | 4 +++- crates/winmd/src/types/param.rs | 25 +++++++++++++++++++++++++ src/runtime_type.rs | 10 +++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 714484c0e8..257722f8c1 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -41,6 +41,7 @@ impl Delegate { let abi_method = self.method.to_abi_tokens(&self.name, &self.name.namespace); let guid = self.guid.to_tokens(); let invoke_sig = self.method.to_abi_impl_tokens(&self.name, &self.name.namespace); + let invoke_args = self.method.params.iter().map(|param| param.to_invoke_arg_tokens()); quote! { #[repr(transparent)] @@ -131,7 +132,8 @@ impl Delegate { #invoke_sig { unsafe { let this = this as *const Self as *mut Self; - ::winrt::ErrorCode(0) + ((*this).invoke)(#(#invoke_args,)*).into() + //::winrt::ErrorCode(0) } } } diff --git a/crates/winmd/src/types/param.rs b/crates/winmd/src/types/param.rs index dfc6d39a1f..4e3ae9b7e5 100644 --- a/crates/winmd/src/types/param.rs +++ b/crates/winmd/src/types/param.rs @@ -147,4 +147,29 @@ impl Param { quote! { ::winrt::RuntimeType::set_abi(#name), } } } + + pub fn to_invoke_arg_tokens(&self) -> TokenStream { + let name = format_ident(&self.name); + + if self.array { + panic!("array"); + // if self.input { + // quote! { #name.len() as u32, ::std::mem::transmute(#name.as_ptr()), } + // } else if self.by_ref { + // quote! { #name.set_abi_len(), #name.set_abi(), } + // } else { + // quote! { #name.len() as u32, ::std::mem::transmute_copy(&#name), } + // } + } else if self.input { + match self.kind { + TypeKind::Enum(_) => quote! { *::winrt::RuntimeType::from_abi(&#name) }, + _ => quote! { ::winrt::RuntimeType::from_abi(&#name) }, + } + + } else if self.kind.blittable() { + quote! { #name, } + } else { + quote! { ::winrt::RuntimeType::from_mut_abi(#name) } + } + } } diff --git a/src/runtime_type.rs b/src/runtime_type.rs index 02482b07ce..9a5c8ea43c 100644 --- a/src/runtime_type.rs +++ b/src/runtime_type.rs @@ -14,6 +14,14 @@ pub unsafe trait RuntimeType { fn abi(&self) -> Self::Abi; fn set_abi(&mut self) -> *mut Self::Abi; + + fn from_abi(abi: &Self::Abi) -> &Self { + unsafe { std::mem::transmute_copy(&abi) } + } + + fn from_mut_abi(abi: &mut Self::Abi) -> &mut Self { + unsafe { std::mem::transmute_copy(&abi) } + } } macro_rules! primitive_runtime_type { @@ -30,4 +38,4 @@ macro_rules! primitive_runtime_type { }; } -primitive_runtime_type! { bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64 } +primitive_runtime_type! { bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64 } // TODO: add Guid here From e147b1bab1f8ab3dc83abb53c7c08b68668ee7ba Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Wed, 6 May 2020 23:43:20 -0700 Subject: [PATCH 15/24] vtable --- crates/winmd/src/types/delegate.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 257722f8c1..509589f626 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -34,6 +34,7 @@ impl Delegate { let fn_constraint = self.to_fn_constraint_tokens(); let impl_definition = self.to_impl_definition_tokens(&fn_constraint); let name = self.name.to_tokens(&self.name.namespace); + let abi_name = self.name.to_abi_tokens(&self.name.namespace); let impl_name = self.to_impl_name_tokens(); let phantoms = self.name.phantoms(); let constraints = self.name.constraints(); @@ -89,7 +90,13 @@ impl Delegate { invoke: F, } impl<#constraints #fn_constraint> #impl_name { - + const VTABLE: #abi_definition = #abi_name { + unknown_query_interface: #impl_name::unknown_query_interface, + unknown_add_ref: #impl_name::unknown_add_ref, + unknown_release: #impl_name::unknown_release, + invoke: #impl_name::invoke, + #phantoms + }; extern "system" fn unknown_query_interface( this: ::winrt::RawComPtr<::winrt::IUnknown>, iid: &::winrt::Guid, @@ -133,7 +140,6 @@ impl Delegate { unsafe { let this = this as *const Self as *mut Self; ((*this).invoke)(#(#invoke_args,)*).into() - //::winrt::ErrorCode(0) } } } @@ -166,7 +172,7 @@ impl Delegate { fn to_impl_name_tokens(&self) -> TokenStream { if self.name.generics.is_empty() { let name = format_impl_ident(&self.name.name); - quote! { #name } + quote! { #name:: } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); From 7258c46d29a7160fe8ee7daf298527da8858db59 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 08:10:54 -0700 Subject: [PATCH 16/24] new --- crates/winmd/src/types/delegate.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 509589f626..920444d934 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -53,6 +53,9 @@ impl Delegate { } impl<#constraints> #name { #method + pub fn new<#fn_constraint>(invoke: F) -> Self { + #impl_name::new(invoke) + } } unsafe impl<#constraints> ::winrt::ComInterface for #name { type VTable = #abi_definition; @@ -97,6 +100,18 @@ impl Delegate { invoke: #impl_name::invoke, #phantoms }; + pub fn new(invoke: F) -> #name { + let value = Self { + vtable: &Self::VTABLE, + count: ::winrt::RefCount::new(1), + invoke, + }; + unsafe { + let mut result: #name = std::mem::zeroed(); + *<#name as ::winrt::RuntimeType>::set_abi(&mut result) = ::std::boxed::Box::into_raw(::std::boxed::Box::new(value)) as *const *const #abi_definition; + result + } + } extern "system" fn unknown_query_interface( this: ::winrt::RawComPtr<::winrt::IUnknown>, iid: &::winrt::Guid, From 3d9679fc2565b55606d5330caa301015c75be0c6 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 11:21:54 -0700 Subject: [PATCH 17/24] test --- tests/delegates.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/delegates.rs diff --git a/tests/delegates.rs b/tests/delegates.rs new file mode 100644 index 0000000000..10c2f705e2 --- /dev/null +++ b/tests/delegates.rs @@ -0,0 +1,67 @@ +winrt::import!( + dependencies + "os" + modules + "windows.foundation" +); + +use winrt::ComInterface; + +#[test] +fn non_generic() -> winrt::Result<()> { + use windows::foundation::AsyncStatus; + use windows::foundation::IAsyncAction; + type Handler = windows::foundation::AsyncActionCompletedHandler; + + assert_eq!( + Handler::IID, + winrt::Guid::from("A4ED5C81-76C9-40BD-8BE6-B1D90FB20AE7") + ); + + let d = Handler::default(); + assert!(d.is_null()); + + let mut invoked = false; + + let d = Handler::new(|info, status| { + invoked = true; + assert!(info.is_null()); + assert!(status == AsyncStatus::Completed); + Ok(()) + }); + + // TODO: delegates are function objects (logically) ans we should be able + // to call them without an explicit `invoke` method e.g. `d(args);` + d.invoke(IAsyncAction::default(), AsyncStatus::Completed); + + assert!(invoked); + + Ok(()) +} + +#[test] +fn generic() -> winrt::Result<()> { + use windows::foundation::Uri; + type Handler = windows::foundation::TypedEventHandler; + + // TODO: Handler::IID is not correct for generic types + + let d = Handler::default(); + assert!(d.is_null()); + + let uri = &Uri::create_uri("http://kennykerr.ca")?; + let mut invoked = false; + + let d = Handler::new(|sender, port| { + invoked = true; + assert!(uri.as_raw() == sender.as_raw()); + assert!(port == 80); + Ok(()) + }); + + d.invoke(uri, uri.port()?)?; + + assert!(invoked); + + Ok(()) +} From 85d71a74d807fc6baa795012e0b0433b1b58d8a2 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 11:25:07 -0700 Subject: [PATCH 18/24] fmt --- crates/winmd/src/types/delegate.rs | 36 ++++++++++++++++++++++-------- crates/winmd/src/types/method.rs | 19 ++++++++-------- crates/winmd/src/types/param.rs | 9 ++++---- tests/xaml.rs | 20 ++++++++--------- 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/crates/winmd/src/types/delegate.rs b/crates/winmd/src/types/delegate.rs index 920444d934..eaeca43012 100644 --- a/crates/winmd/src/types/delegate.rs +++ b/crates/winmd/src/types/delegate.rs @@ -41,8 +41,14 @@ impl Delegate { let method = self.method.to_default_tokens(&self.name.namespace); let abi_method = self.method.to_abi_tokens(&self.name, &self.name.namespace); let guid = self.guid.to_tokens(); - let invoke_sig = self.method.to_abi_impl_tokens(&self.name, &self.name.namespace); - let invoke_args = self.method.params.iter().map(|param| param.to_invoke_arg_tokens()); + let invoke_sig = self + .method + .to_abi_impl_tokens(&self.name, &self.name.namespace); + let invoke_args = self + .method + .params + .iter() + .map(|param| param.to_invoke_arg_tokens()); quote! { #[repr(transparent)] @@ -119,7 +125,7 @@ impl Delegate { ) -> ::winrt::ErrorCode { unsafe { let this = this as *const Self as *mut Self; - + if *iid == <#name as ::winrt::ComInterface>::IID || *iid == <::winrt::IUnknown as ::winrt::ComInterface>::IID || *iid == <::winrt::IAgileObject as ::winrt::ComInterface>::IID @@ -128,7 +134,7 @@ impl Delegate { (*this).count.add_ref(); return ::winrt::ErrorCode(0); } - + *interface = std::ptr::null_mut(); ::winrt::ErrorCode(0x80004002) } @@ -143,11 +149,11 @@ impl Delegate { unsafe { let this = this as *const Self as *mut Self; let remaining = (*this).count.release(); - + if remaining == 0 { Box::from_raw(this); } - + remaining } } @@ -162,7 +168,11 @@ impl Delegate { } fn to_fn_constraint_tokens(&self) -> TokenStream { - let params = self.method.params.iter().map(|param| param.to_fn_tokens(&self.name.namespace)); + let params = self + .method + .params + .iter() + .map(|param| param.to_fn_tokens(&self.name.namespace)); let return_type = if let Some(return_type) = &self.method.return_type { return_type.to_return_tokens(&self.name.namespace) @@ -179,7 +189,11 @@ impl Delegate { quote! { #name<#fn_constraint> } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); - let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); + let generics = self + .name + .generics + .iter() + .map(|g| g.to_tokens(&self.name.namespace)); quote! { #name<#(#generics,)* #fn_constraint> } } } @@ -190,7 +204,11 @@ impl Delegate { quote! { #name:: } } else { let name = format_impl_ident(&self.name.name[..self.name.name.len() - 2]); - let generics = self.name.generics.iter().map(|g| g.to_tokens(&self.name.namespace)); + let generics = self + .name + .generics + .iter() + .map(|g| g.to_tokens(&self.name.namespace)); quote! { #name::<#(#generics,)* F> } } } diff --git a/crates/winmd/src/types/method.rs b/crates/winmd/src/types/method.rs index 7b4b21a6db..bf88f8cd7a 100644 --- a/crates/winmd/src/types/method.rs +++ b/crates/winmd/src/types/method.rs @@ -150,16 +150,15 @@ impl Method { pub fn to_abi_impl_tokens(&self, self_name: &TypeName, calling_namespace: &str) -> TokenStream { let abi_name = self_name.to_abi_tokens(calling_namespace); let name = format_ident(&self.name); - let params = - self.params - .iter() - .chain(self.return_type.iter()) - .map(|param| { - let name = format_ident(¶m.name); - let abi = param.to_abi_tokens(calling_namespace); - quote! { #name: #abi } - }); - + let params = self + .params + .iter() + .chain(self.return_type.iter()) + .map(|param| { + let name = format_ident(¶m.name); + let abi = param.to_abi_tokens(calling_namespace); + quote! { #name: #abi } + }); quote! { extern "system" fn #name(this: *const *const #abi_name, #(#params)*) -> ::winrt::ErrorCode diff --git a/crates/winmd/src/types/param.rs b/crates/winmd/src/types/param.rs index 4e3ae9b7e5..c3c482a38f 100644 --- a/crates/winmd/src/types/param.rs +++ b/crates/winmd/src/types/param.rs @@ -152,20 +152,21 @@ impl Param { let name = format_ident(&self.name); if self.array { + // TODO: delegate with array parameters are challenging to say the least. + // I'll get to them shortly. panic!("array"); // if self.input { - // quote! { #name.len() as u32, ::std::mem::transmute(#name.as_ptr()), } + // // } else if self.by_ref { - // quote! { #name.set_abi_len(), #name.set_abi(), } + // // } else { - // quote! { #name.len() as u32, ::std::mem::transmute_copy(&#name), } + // // } } else if self.input { match self.kind { TypeKind::Enum(_) => quote! { *::winrt::RuntimeType::from_abi(&#name) }, _ => quote! { ::winrt::RuntimeType::from_abi(&#name) }, } - } else if self.kind.blittable() { quote! { #name, } } else { diff --git a/tests/xaml.rs b/tests/xaml.rs index ccf5ef8384..8f6105baf1 100644 --- a/tests/xaml.rs +++ b/tests/xaml.rs @@ -1,11 +1,11 @@ -// winrt::import!( -// dependencies -// "os" -// modules -// "windows.ui.xaml" -// ); +winrt::import!( + dependencies + "os" + modules + "windows.ui.xaml" +); -// #[test] -// fn xaml() -> winrt::Result<()> { -// Ok(()) -// } +#[test] +fn xaml() -> winrt::Result<()> { + Ok(()) +} From 8195b7b22006a7347a892dd66ea22c8e06d011bd Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 11:29:08 -0700 Subject: [PATCH 19/24] test --- tests/delegates.rs | 6 ++++-- tests/xaml.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/delegates.rs b/tests/delegates.rs index 10c2f705e2..6c2c851fed 100644 --- a/tests/delegates.rs +++ b/tests/delegates.rs @@ -32,7 +32,7 @@ fn non_generic() -> winrt::Result<()> { // TODO: delegates are function objects (logically) ans we should be able // to call them without an explicit `invoke` method e.g. `d(args);` - d.invoke(IAsyncAction::default(), AsyncStatus::Completed); + d.invoke(IAsyncAction::default(), AsyncStatus::Completed)?; assert!(invoked); @@ -55,7 +55,9 @@ fn generic() -> winrt::Result<()> { let d = Handler::new(|sender, port| { invoked = true; assert!(uri.as_raw() == sender.as_raw()); - assert!(port == 80); + + // TODO: ideally primitives would be passed by value + assert!(*port == 80); Ok(()) }); diff --git a/tests/xaml.rs b/tests/xaml.rs index 8f6105baf1..ccf5ef8384 100644 --- a/tests/xaml.rs +++ b/tests/xaml.rs @@ -1,11 +1,11 @@ -winrt::import!( - dependencies - "os" - modules - "windows.ui.xaml" -); +// winrt::import!( +// dependencies +// "os" +// modules +// "windows.ui.xaml" +// ); -#[test] -fn xaml() -> winrt::Result<()> { - Ok(()) -} +// #[test] +// fn xaml() -> winrt::Result<()> { +// Ok(()) +// } From 13a14c00b854260122bdd528b1d423e10598529b Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 11:59:15 -0700 Subject: [PATCH 20/24] xaml --- crates/winmd/src/types/method.rs | 2 +- tests/xaml.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/winmd/src/types/method.rs b/crates/winmd/src/types/method.rs index bf88f8cd7a..6d57bb7d56 100644 --- a/crates/winmd/src/types/method.rs +++ b/crates/winmd/src/types/method.rs @@ -66,7 +66,7 @@ impl Method { let return_type = if blob.read_expected(0x01) { None } else { - let name = String::new(); + let name = "__result".to_owned(); let array = blob.peek_unsigned().0 == 0x1D; let kind = TypeKind::from_blob(&mut blob, generics); let input = false; diff --git a/tests/xaml.rs b/tests/xaml.rs index ccf5ef8384..8f6105baf1 100644 --- a/tests/xaml.rs +++ b/tests/xaml.rs @@ -1,11 +1,11 @@ -// winrt::import!( -// dependencies -// "os" -// modules -// "windows.ui.xaml" -// ); +winrt::import!( + dependencies + "os" + modules + "windows.ui.xaml" +); -// #[test] -// fn xaml() -> winrt::Result<()> { -// Ok(()) -// } +#[test] +fn xaml() -> winrt::Result<()> { + Ok(()) +} From 494f09bca36c51ae9a988d546a895dbc1462bd75 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 12:01:17 -0700 Subject: [PATCH 21/24] fmt --- crates/winmd/src/types/param.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/winmd/src/types/param.rs b/crates/winmd/src/types/param.rs index c3c482a38f..4af2386b37 100644 --- a/crates/winmd/src/types/param.rs +++ b/crates/winmd/src/types/param.rs @@ -155,13 +155,6 @@ impl Param { // TODO: delegate with array parameters are challenging to say the least. // I'll get to them shortly. panic!("array"); - // if self.input { - // - // } else if self.by_ref { - // - // } else { - // - // } } else if self.input { match self.kind { TypeKind::Enum(_) => quote! { *::winrt::RuntimeType::from_abi(&#name) }, From 0efe66ec3eac875120160223a7377cad363806b6 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 12:01:35 -0700 Subject: [PATCH 22/24] cmt --- crates/macros/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/macros/src/lib.rs b/crates/macros/src/lib.rs index 95a7e6c6b2..1b46cf8873 100644 --- a/crates/macros/src/lib.rs +++ b/crates/macros/src/lib.rs @@ -22,7 +22,7 @@ pub fn import(stream: TokenStream) -> TokenStream { let stage = TypeStage::from_limits(reader, &limits); let tree = stage.into_tree(); let stream = tree.to_tokens(); - std::fs::write(r"c:\git\rust\dump.rs", stream.to_string()).unwrap(); + //std::fs::write(r"c:\git\rust\dump.rs", stream.to_string()).unwrap(); stream.into() } From 31339ac24bf37979bb0b303dbb5db00c7bbeb142 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 12:09:09 -0700 Subject: [PATCH 23/24] comment --- src/runtime_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime_type.rs b/src/runtime_type.rs index 9a5c8ea43c..f4c5c43baf 100644 --- a/src/runtime_type.rs +++ b/src/runtime_type.rs @@ -38,4 +38,4 @@ macro_rules! primitive_runtime_type { }; } -primitive_runtime_type! { bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64 } // TODO: add Guid here +primitive_runtime_type! { bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64 } From 5b2ac901fc15d3ab2f7523a3babb3bb6aae07134 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 7 May 2020 12:43:44 -0700 Subject: [PATCH 24/24] minesweeper --- src/com_ptr.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com_ptr.rs b/src/com_ptr.rs index 2b420e27dc..c80fc82bd0 100644 --- a/src/com_ptr.rs +++ b/src/com_ptr.rs @@ -7,6 +7,10 @@ pub struct ComPtr { } impl ComPtr { + pub fn abi(&self) -> RawComPtr { + self.ptr + } + pub fn set_abi(&mut self) -> *mut RawComPtr { if !self.ptr.is_null() { unsafe {