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

Use Ref and OutRef for C++ delegates #3447

Merged
merged 4 commits into from
Jan 15, 2025
Merged

Use Ref and OutRef for C++ delegates #3447

merged 4 commits into from
Jan 15, 2025

Conversation

kennykerr
Copy link
Collaborator

This fixes the issue of C++ delegates (C++ function pointer/callback types) are generated with parameters that assume ownership is passed into the function. This is fine for sys-style bindings where all types are copyable but not so for regular bindings where some times might require ownership or lifetime management. That's exactly what Ref and OutRef handle so that's what these delegates now use for their parameters.

A somewhat contrived test is provided that implements PFNGETACTIVATIONFACTORY to verify that such delegates can be both implemented and called in Rust. This highlighted a limitation in the fact that Ref now has no lifetime parameter (#3433 #3435) and thus makes it unsafe to construct on the call side. This is unfortunate, so I'll rethink Ref and see if we can reintroduce the lifetime for cases where this needs to be called safely.

Fixes: #3446

@kennykerr kennykerr merged commit 68b029e into master Jan 15, 2025
75 checks passed
@kennykerr kennykerr deleted the cpp-delegate-params branch January 15, 2025 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windows-bindgen should use Ref for certain delegate parameters
1 participant