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

fix!: generated types from DECLARE_HANDLE macro are marked as opaque, non-copy, and non-default #280

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

leon-xd
Copy link
Contributor

@leon-xd leon-xd commented Jan 29, 2025

This pull request fixes default bindgen behavior that resulted in types from the WDK macro DECLARE_HANDLE not being marked as opaque. My PR introduces a new function in the trait BuilderExt, opaque_windows_handle_types, which searches through the current Config's include_paths, and finds each instance of the DECLARE_HANDLE macro in order to mark these types as opaque_type, no_copy, and no_default.

Validation

The effect of this change can be found in opaque_handles.zip. There are three directories: one for the original versions of the file types.rs generated by bindgen, one for the new versions of types.rs, and one containing the diffs between the two.

The DECLARE_HANDLE macro is defined as follows:

#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name

In each diffed file, you can see each struct defined by this macro, marked by pub unused: ::core::ffi::c_int, is now replaced by an opaque type, marked by pub _bindgen_opaque_blob: u32. We can be sure of this approach as there are no generated structs in the new types.rs files that contain the unused member.

Breaking Changes

Types generated by bindgen for the WDK have been edited. These are public facing, so therefore this PR contains a breaking change.

@leon-xd leon-xd requested review from Copilot and wmmc88 and removed request for Copilot January 30, 2025 00:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

crates/wdk-build/src/bindgen.rs:166

  • The phrase 'open and closed parentheses' should be corrected to 'opening and closing parentheses'.
// We find the open and closed parentheses in each line, and push the

crates/wdk-build/src/bindgen.rs Outdated Show resolved Hide resolved
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Leon Durrenberger <[email protected]>
@leon-xd leon-xd changed the title fix: generated types from DECLARE_HANDLE macro are marked as opaque, non-copy, and non-default fix!: generated types from DECLARE_HANDLE macro are marked as opaque, non-copy, and non-default Jan 30, 2025
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.

1 participant