-
Notifications
You must be signed in to change notification settings - Fork 120
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
MetadataTypedef
attribute does not work
#1575
Comments
Has this been addressed? Seems like 3608e3f just removed that one metadata type but didn't address the original issue where there are various such types where the native type is not preserved. |
The native types all seem to be preserved unless you're referring to scenarios where the MetadataTypedef wraps a NativeTypedef like HANDLE. Today, the NativeTypedef would be lost. Is that what you're referring to? |
Yes. |
Ok. I'll reactivate and see if we can set the value of the MetadataTypedef to a NativeTypedef. |
We could update the Value field like below, but if you expose just HANDLE, that might suggest that you should close the handle with CloseHandle which would be incorrect. I know you ignore RAIIFree right now @kennykerr, but how would you imagine handling this if you did?
|
I'd associate the free function with the function rather than the return type. |
I was thinking the same. I'll try that. |
Alternatively, we could establish a rule that states |
Example: // Theoretical APIs
public unsafe HANDLE GetASharedHandle();
public unsafe ClosableHandle GetAFreshHandle();
public unsafe TimerQueueHandle GetATimerQueueHandle();
// Untouched "raw" typedef
[NativeTypedef]
public struct HANDLE
{
public IntPtr Value;
}
// A specialization with a free function
[RAIIFree("CloseHandle")]
[InvalidHandleValue(-1L)]
[InvalidHandleValue(0L)]
[MetadataTypedef]
public struct ClosableHandle
{
public HANDLE Value;
}
// A specialization with an overriding free function
[RAIIFree("DeleteTimerQueueEx")]
[InvalidHandleValue(0L)]
[MetadataTypedef]
public struct TimerQueueHandle
{
public HANDLE Value;
} |
Just my 2 cents, but I think that's too prescriptive. It's not the metadata's job to invent types and associations that don't exist in the API. |
So it sounds like Kenny's proposal is to delete MetadataTypedefs and produce the following instead: [return: RAIIFree("CloseHandle")]
public unsafe static extern HANDLE CreateFileA(...);
public unsafe static extern BOOL CreateTimerQueueTimer(
[Out]
[RAIIFree("DeleteTimerQueueEx")]
[InvalidHandleValue(0L)]
HANDLE* phNewTimer,
[Optional]
[In]
[InvalidHandleValue(0L)]
HANDLE TimerQueue,
...
); |
I'd put the invalid value and the free function on the same attribute since they're inextricably linked. |
I was thinking the HANDLE NativeTypedef has CloseHandle and InvalidHandleValues like it does today. For scenarios where HANDLEs must be closed with a more specific function, that is attributed on the HANDLE return value or out parameter like you showed above. |
It seems a little convoluted to have to support two different approaches to retrieve the same information. |
It seems redundant to decorate every HANDLE reference in the SDK with mostly the same attributes. I'd rather only decorate the deviations from the norm. |
So you're proposing something like this: [RAIIFree("CloseHandle")]
[InvalidHandleValue(-1L)]
[InvalidHandleValue(0L)]
[NativeTypedef]
public struct HANDLE
{
public IntPtr Value;
}
public unsafe static extern HANDLE CreateFileA(...);
public unsafe static extern BOOL CreateTimerQueueTimer(
[Out]
[RAIIFree("DeleteTimerQueueEx")]
HANDLE* phNewTimer,
[Optional]
[In]
HANDLE TimerQueue,
...
); Hm. I see what you're trying to do there, but am wondering if some APIs may return a |
We have |
I took the
MetadataTypedef
attribute for a spin but it's useless as the metadata doesn't actually tell me what it replaced. I don't know for example thatCreateCompatibleDC
actually returns anHDC
. Ideally the metadata would use the native types (e.g.HDC
in this case) and use attributes to indicate alternatives that may optionally be used but as it stands, we can tell that something's changed but not what it changed from.Originally posted by @kennykerr in #561 (comment)
The text was updated successfully, but these errors were encountered: