Repository navigation
Generate SafeHandle owners for cleanup functions that return BOOLEAN - #1859
Merged
Jevan Saks (jevansaks) merged 1 commit intoOct 19, 2026
Merged
Conversation
IsSupportedCleanupReturn rejected cleanup functions that return BOOLEAN, such as HidD_FreePreparsedData, so their owners were generated as abstract and producers kept raw outputs. BOOLEAN is now handled like BOOL: the generated ReleaseHandle returns the result through BOOLEAN's implicit bool conversion, where non-zero is success. Related: microsoft/win32metadata#2375 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0aa7080c-77a0-44e7-8869-029671991a9a
Jevan Saks (jevansaks)
marked this pull request as ready for review
October 18, 2026 20:49
Jevan Saks (jevansaks)
enabled auto-merge (squash)
October 19, 2026 01:25
Sergio Pedri (Sergio0694)
approved these changes
Oct 19, 2026
Jevan Saks (jevansaks)
deleted the
jevansaks-hidp-preparsed-data-safehandle
branch
October 19, 2026 01:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IsSupportedCleanupReturnnow acceptsBOOLEAN. The generatedReleaseHandlereturns aBOOLEANresult directly, the same way it already handlesBOOL: non-zero is success, throughBOOLEAN's implicitboolconversion.Before this change, a
RAIIFreeorFreeWithannotation that names aBOOLEANcleanup function produced an abstract owner, and the producer kept its raw output.HidD_FreePreparsedDatais the motivating case (discussion #1675, microsoft/win32metadata#2375). With this change and microsoft/win32metadata#2376, this works:Effect on current metadata
None. In Windows.Win32.winmd 71.0.30-preview, the only
BOOLEANfunction named by a cleanup annotation isClosePrivateNamespace. It takes two arguments, so its owner stays abstract. Generated output for the stock winmd is unchanged.Validation
BooleanCleanupProducesOwnertheory (RAIIFree and FreeWith, with and without runtime marshaling). It uses theSafeHandleOwnershipfixture, which now includes aBOOLEANtypedef, aFreeBooleancleanup function, and returned and out-parameter producers. The test fails without the fix. All 75SafeHandleLeaseTestspass with it.ReleaseHandlecalls the cleanup function, itsIsInvalidtreats0as invalid, and every producer has an overload with anoutowner parameter. With the stock 71.0.30-preview winmd, all 15 fail this check.HidD_GetPreparsedDatawithout HidD_FreePreparsedDataSafeHandle, followed byHidP_GetCapsthroughDangerousValueand throughLease(), succeeded on 32 of them.ReleaseHandlereturns true.