Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle IDispatch edge case #1642

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ jobs:
cargo clippy -p test_core &&
cargo clippy -p test_debug &&
cargo clippy -p test_deprecated &&
cargo clippy -p test_dispatch &&
cargo clippy -p test_does_not_return &&
cargo clippy -p test_enums &&
cargo clippy -p test_error &&
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
cargo test --target ${{ matrix.target }} -p test_core &&
cargo test --target ${{ matrix.target }} -p test_debug &&
cargo test --target ${{ matrix.target }} -p test_deprecated &&
cargo test --target ${{ matrix.target }} -p test_dispatch &&
cargo test --target ${{ matrix.target }} -p test_does_not_return &&
cargo test --target ${{ matrix.target }} -p test_enums &&
cargo test --target ${{ matrix.target }} -p test_error &&
Expand Down
7 changes: 3 additions & 4 deletions crates/libs/bindgen/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ fn gen_methods(def: &TypeDef, cfg: &Cfg, gen: &Gen) -> TokenStream {
match def {
Type::IUnknown | Type::IInspectable => {}
Type::TypeDef(def) => {
if def.type_name() != TypeName::IDispatch {
methods.combine(&gen_methods_impl(&def, InterfaceKind::Default, &mut method_names, &mut virtual_names, bases, gen));
}
let kind = if def.type_name() == TypeName::IDispatch { InterfaceKind::NonDefault } else { InterfaceKind::Default };
methods.combine(&gen_methods_impl(&def, kind, &mut method_names, &mut virtual_names, bases, gen));
}
_ => unimplemented!(),
}
Expand Down Expand Up @@ -116,7 +115,7 @@ fn gen_methods_impl(def: &TypeDef, kind: InterfaceKind, method_names: &mut Metho
if is_winrt {
methods.combine(&gen_winrt_method(def, kind, &method, method_names, virtual_names, gen));
} else {
methods.combine(&gen_com_method(def, &method, method_names, virtual_names, bases, gen));
methods.combine(&gen_com_method(def, kind, &method, method_names, virtual_names, bases, gen));
}
}

Expand Down
6 changes: 5 additions & 1 deletion crates/libs/bindgen/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn gen_winrt_method(def: &TypeDef, kind: InterfaceKind, method: &MethodDef,
}
}

pub fn gen_com_method(def: &TypeDef, method: &MethodDef, method_names: &mut MethodNames, virtual_names: &mut MethodNames, base_count: usize, gen: &Gen) -> TokenStream {
pub fn gen_com_method(def: &TypeDef, kind: InterfaceKind, method: &MethodDef, method_names: &mut MethodNames, virtual_names: &mut MethodNames, base_count: usize, gen: &Gen) -> TokenStream {
let signature = method.signature(&def.generics);
let name = method_names.add(method);
let vname = virtual_names.add(method);
Expand All @@ -150,6 +150,10 @@ pub fn gen_com_method(def: &TypeDef, method: &MethodDef, method_names: &mut Meth
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

if kind == InterfaceKind::NonDefault {
return quote! {};
}

let mut bases = quote! {};

for _ in 0..base_count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2965,9 +2965,9 @@ impl IWSManSession {
}
#[doc = "*Required features: `\"Win32_System_RemoteManagement\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com\"`, `\"Win32_System_Ole\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com", feature = "Win32_System_Ole"))]
pub unsafe fn Invoke<'a, Param0: ::windows::core::IntoParam<'a, super::super::Foundation::BSTR>, Param1: ::windows::core::IntoParam<'a, super::Com::VARIANT>, Param2: ::windows::core::IntoParam<'a, super::super::Foundation::BSTR>>(&self, actionuri: Param0, resourceuri: Param1, parameters: Param2, flags: i32) -> ::windows::core::Result<super::super::Foundation::BSTR> {
pub unsafe fn Invoke2<'a, Param0: ::windows::core::IntoParam<'a, super::super::Foundation::BSTR>, Param1: ::windows::core::IntoParam<'a, super::Com::VARIANT>, Param2: ::windows::core::IntoParam<'a, super::super::Foundation::BSTR>>(&self, actionuri: Param0, resourceuri: Param1, parameters: Param2, flags: i32) -> ::windows::core::Result<super::super::Foundation::BSTR> {
let mut result__: ::core::mem::ManuallyDrop<super::super::Foundation::BSTR> = ::core::mem::zeroed();
(::windows::core::Interface::vtable(self).Invoke)(::core::mem::transmute_copy(self), actionuri.into_param().abi(), resourceuri.into_param().abi(), parameters.into_param().abi(), ::core::mem::transmute(flags), ::core::mem::transmute(&mut result__)).from_abi::<super::super::Foundation::BSTR>(result__)
(::windows::core::Interface::vtable(self).Invoke2)(::core::mem::transmute_copy(self), actionuri.into_param().abi(), resourceuri.into_param().abi(), parameters.into_param().abi(), ::core::mem::transmute(flags), ::core::mem::transmute(&mut result__)).from_abi::<super::super::Foundation::BSTR>(result__)
}
#[doc = "*Required features: `\"Win32_System_RemoteManagement\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com\"`, `\"Win32_System_Ole\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com", feature = "Win32_System_Ole"))]
Expand Down
14 changes: 14 additions & 0 deletions crates/tests/dispatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "test_dispatch"
version = "0.0.0"
authors = ["Microsoft"]
edition = "2021"

[dependencies.windows]
path = "../../libs/windows"
features = [
"Win32_Foundation",
"Win32_System_Com",
"Win32_System_Ole",
"Win32_System_RemoteManagement",
]
1 change: 1 addition & 0 deletions crates/tests/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions crates/tests/dispatch/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This test just ensures that IWSManSession is generated correctly as it has a method
// that collides with one of IDispatch's methods.