-
Notifications
You must be signed in to change notification settings - Fork 537
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
Generate QueryInterface
-like helper function for callbacks
#1835
Comments
Here's a quick query looking for callbacks with query-like signatures: fn main() {
use windows_metadata::reader::*;
let files = vec![
File::new("/git/windows-rs/crates/libs/metadata/default/Windows.Win32.winmd").unwrap(),
];
let reader = &Reader::new(&files);
let root = reader.tree("Windows.Win32", &[]).unwrap();
for tree in root.flatten() {
for def in reader.namespace_types(tree.namespace) {
if reader.type_def_kind(def) == TypeKind::Delegate
&& !reader.type_def_flags(def).winrt()
{
let method = reader.type_def_invoke_method(def);
let signature = reader.method_def_signature(method, &[]);
let kind = reader.signature_kind(&signature);
if matches!(
kind,
SignatureKind::Query(_) | SignatureKind::QueryOptional(_)
) {
println!("{}", reader.type_def_name(def));
}
}
}
}
} It only returns three results:
|
@kennykerr That matches my point 2., I'm concerned that this might not be very useful if there aren't that many functions, or if most of them lack the Adjusting that test by removing
|
That's a pretty short list - we should be able to get those fixed up by the win32 metadata project. The reason I went for the stricter test is that there are some false positives where functions have a trailing |
I totally agree with stricter tests - it just seems like we have some work to do fixing up the headers and/or temporary overrides in Do you still think it's worth pursuing this helper then? Are there other kinds of syntactic sugar that may be beneficial for |
I think callbacks could be a lot better - not just in this one area - but in general could offer a more appealing calling experience if they could offer a thin wrapper around the function pointer. Ideally, I would like them to behave more like regular function wrappers in the |
One thing I found annoying was them being wrapped inside (ALAS, nothing has changed since we last spoke; I still use Linux and unguarded How do you want to tackle this? I can possibly look into the Dxc/D3D methods and submit overrides to |
While this would be convenient for experimenting, I don't think there is enough demand for such a capability to warrant including all the extra code gen needed to make it happen. |
Also here, wrong close reason. You should close it as "not planned" etc. |
Ah, I never noticed the close drop-down before - thanks! |
It's "new" (±2 months old IIRC). Feel free to reopen and close with the right status.
I see, questions have no place on this repo? |
I'm happy to try and answer questions but they're not actionable and thus get closed pretty quickly. If there's valuable information in the Q&A then we can create a PR to capture that information in the FAQ. |
I should apply that technique to my repos 😈 |
Hi @kennykerr! This still only applies to the original 3 delegates found in #1835 (comment), but I do have a few custom metadata bindings where these helpers are relevant too. And they'll be even more relevant when (if?) we can get the SAL annotation fixes for DirectXShaderCompiler working: microsoft/DirectXShaderCompiler#4524. Should we re-discuss whether it is worth adding this helper again? I still have a branch open and it mostly works: https://github.com/MarijnS95/windows-rs/compare/callback-query-interface-2, there's just one incompatibility. Currently parameters for the type alias are generated as follows: windows-rs/crates/libs/bindgen/src/delegates.rs Lines 25 to 29 in 2e7f99d
Watch what happens to pub type PFNMagic = ::core::option::Option<
unsafe extern "system" fn(
pouter: ::core::option::Option<::windows_core::IUnknown>,
// pouter: *mut ::core::ffi::c_void,
riid: *const ::windows_core::GUID,
ppvobject: *mut *mut ::core::ffi::c_void,
) -> ::windows_core::HRESULT,
>; The function call arguments generated by windows-rs/crates/libs/bindgen/src/functions.rs Lines 198 to 206 in 2e7f99d
pub unsafe fn PFNMagic<P0, T>(
func: &PFNMagic,
pouter: P0,
) -> ::windows::core::Result<T>
where
P0: ::windows_core::IntoParam<::windows_core::IUnknown>,
T: ::windows::core::ComInterface,
{
let mut result__ = ::std::ptr::null_mut();
(func.unwrap())(
pouter.into_param().abi(), // <------------- Boom. This *mut c_void is not compatible with Option<IUnknown>.
&<T as ::windows_core::ComInterface>::IID,
&mut result__,
)
.from_abi(result__)
} What is the desired solution for this? Custom argument/input handling to match the target type of a delegate type alias, or adjust the argument type of that delegate type alias? And what if the metadata didn't annotate the pointer with On a closely related note (perhaps worth creating a new issue for) the |
It'd be great to have helper functions for callbacks with nicer signatures in the
windows
crate, just like "normal function" wrappers. For starters, when doing this toQuery
(orQueryOptional
) callbacks, code can be written as follows:Without this we'd have to replace the last two lines with this atrocity (using
transmute
for lack of a non-verbose way to put together all the pointer casts):There are currently 517 hits for
pub type PFN_
and there must be some that behave likeQueryInterface
(i.e. D3D10/11/12CREATE_DEVICE
). I'd like to get #747 reopened for this to make it in, but one major blocker was not having any (test) code that actively practices this system.Reasons to not do this
"windows"
directly if#[link = "windows"]
onDxcCreateInstance
is to be believed);windows-rs
is now more strict in requiring_COM_Outptr_
SAL before marking functions/callbacks asSignatureKind::Query
. This has been worked around forDxcCreateInstance(2)
in Add ComOutPtr attribute to additional params win32metadata#890, but not for the*Proc
function types (this will be PR'd to DXC soon™).Originally posted by @MarijnS95 in #747 (comment)
The text was updated successfully, but these errors were encountered: