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

Type-specific handle validity checking #1648

Merged
merged 6 commits into from
Mar 31, 2022
Merged

Type-specific handle validity checking #1648

merged 6 commits into from
Mar 31, 2022

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Mar 31, 2022

The win32 metadata now includes information about what constitutes invalid handle values. This update plumbs this through so that you can accurately check whether a handle returned by some function is invalid. Handles will have an is_invalid method if their underlying type is a pointer or have at least one invalid value.

With this information in hand, the bindgen crate can now combine this with metadata that indicates whether a particular function set the last error so that the caller should use GetLastError on failure. This means that functions that return a handle and provide error information in this way will now be transformed to return -> Result<HANDLE> instead of just -> HANDLE. This should make error handling more predictable.

Fixes #1630

@kennykerr kennykerr requested a review from riverar March 31, 2022 18:37
crates/libs/bindgen/src/functions.rs Outdated Show resolved Hide resolved
crates/libs/bindgen/src/handles.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@riverar riverar left a comment

Choose a reason for hiding this comment

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

Nice! Really cool to see all this light up with a sprinkle of metadata 🎉

@kennykerr kennykerr merged commit ab6994f into master Mar 31, 2022
@kennykerr kennykerr deleted the handles branch March 31, 2022 20:08
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.

Bug: FindVolumeHandle::is_invalid() does not check for a value of -1
2 participants