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

Ensure external references to static factories are generated correctly #3392

Merged
merged 2 commits into from
Dec 13, 2024
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
5 changes: 3 additions & 2 deletions crates/libs/bindgen/src/types/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Class {

let method = method.write(
writer,
interface.write_name(writer),
Some(interface),
interface.kind,
&mut method_names,
&mut virtual_names,
Expand Down Expand Up @@ -88,12 +88,13 @@ impl Class {
if interface.def.methods().next().is_none() {
None
} else {
let method_name = to_ident(interface.def.name());
let interface_type = interface.write_name(writer);
let cfg = quote! {};

Some(quote! {
#cfg
fn #interface_type<R, F: FnOnce(&#interface_type) -> windows_core::Result<R>>(
fn #method_name<R, F: FnOnce(&#interface_type) -> windows_core::Result<R>>(
callback: F,
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<#name, #interface_type> =
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Delegate {

let invoke = method.write(
writer,
self.write_name(writer),
None,
InterfaceKind::Default,
&mut MethodNames::new(),
&mut MethodNames::new(),
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/types/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Interface {

let method = method.write(
writer,
self.write_name(writer),
Some(self),
InterfaceKind::Default,
method_names,
virtual_names,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Interface {

let method = method.write(
writer,
interface.write_name(writer),
Some(interface),
interface.kind,
method_names,
virtual_names,
Expand Down
6 changes: 5 additions & 1 deletion crates/libs/bindgen/src/types/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Method {
pub fn write(
&self,
writer: &Writer,
interface_name: TokenStream,
interface: Option<&Interface>,
kind: InterfaceKind,
method_names: &mut MethodNames,
virtual_names: &mut MethodNames,
Expand Down Expand Up @@ -525,6 +525,8 @@ impl Method {
quote! { ? }
};

let interface_name = interface.unwrap().write_name(writer);

quote! {
pub fn #name<#(#generics,)*>(&self, #(#params)*) #return_type #where_clause {
let this = &windows_core::Interface::cast::<#interface_name>(self)#unwrap;
Expand All @@ -535,6 +537,8 @@ impl Method {
}
}
InterfaceKind::Static | InterfaceKind::Composable => {
let interface_name = to_ident(interface.unwrap().def.name());

quote! {
pub fn #name<#(#generics,)*>(#(#params)*) #return_type #where_clause {
Self::#interface_name(|this| unsafe { #vcall })
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspace = true
[dependencies.windows]
workspace = true
features = [
"Foundation",
"Foundation_Collections",
"Win32_Foundation",
"Win32_Security",
]
Expand Down
1 change: 1 addition & 0 deletions crates/tests/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub mod reference_async_action_reference_type;
pub mod reference_async_info_no_status;
pub mod reference_async_info_status_filter;
pub mod reference_async_info_status_reference;
pub mod reference_class_ref_static;
pub mod reference_dependency_flat;
pub mod reference_dependency_full;
pub mod reference_dependency_skip_root;
Expand Down
Loading
Loading