-
Notifications
You must be signed in to change notification settings - Fork 122
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
Annotate methods that return handles that are not meant to be closed #244
Comments
I'm having them return a native typdef called NonClosableHandle which has the attribute that says it's also usable for HANDLE. |
I think I'd rather see the return value attributed so that it can work for any handle type -- not just |
Would this be in addition to the |
I see |
I like |
HANDLE is marked as closable by CloseHandle, but that's not how you close a heap handle. How would I have it return HANDLE and the projection then know how to dispose of it? |
I thought about that, but the way I've done it doesn't require any extra work for you (or for me). The type it returns doesn't have a close function, but it's usable in the same places where the closeable is used. If we think it's too unwieldy I can do it the other way as an attribute on return and out parameters. |
I didn't say anything about |
Sorry, I thought your complaint was that it's not returning HANDLE. Like I said, I can do Andrew's suggestion but it will be more work for projection writers. If you've already implemented AlsoUsableAs it should work the way it is. |
Yes, I don't really mind either way - I just don't see the point of having both. |
The In contrast, simply returning
That all said, I'm ok with going with @sotteson1's original plan based on it requiring no additional work for anyone and wait to hear from customers to see if my above two concerns are warranted. |
That's true. I like how using the DoNotRelease would keep from hiding the original handle type. |
Nice. I also like preserving the original handle types. |
What possible solutions are there for annotating a function like GetModuleHandleExW? This is a special case where the semantics of the return value depend on the input: If |
@tim-weis: oooh, good one. I imagine the very specific cases like this one may lead us to places that we may never be able to express in the metadata. In such cases the user may need to be careful and read the docs and code their app in such a way as to conform with the docs, possibly without the nuanced help from the metadata or projection. The projection should (IMO) allow the app/library author to control releasing handles enough to always get it right for cases like this even if the metadata or projection do not know about these special cases. |
I would avoid using a handle type that includes the |
That's one idea. But I wonder whether the 99% common use case of the function should win out in cases where the no-free flag is the 1% case. |
That's a fair point, I guess the 1% case could just write their own import/extern declaration. |
Agreed, if that's really the % breakdown. I don't have data for this particular case. In CsWin32, we offer two overloads so the 99% and the 1% case can self-serve without having to declare the extern method. |
Methods such as
GetStdHandle
andGetCurrentProcess
return handles that are not expected to ever be closed by the caller, and doing so may cause malfunctions.While tagging such methods may be a manual process, we should have such a means so that projections that offer enhanced handle closing APIs can avoid causing problems for such APIs.
The text was updated successfully, but these errors were encountered: