You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please add .IsNull helper on handle structs to improve the usage syntax over .Value == 0 #206
#122 is similar, in that we want an IsNull property exposed there. But that's for a vtbl which clearly is null or non-null.
In this case, what you probably really want to know is whether the handle is invalid. Note some handles are invalid when set to 0, while others are invalid at -1. Some are invalid with either value. So I think the new property should be called IsInvalid.
We're blocked on delivering this till the metadata delivers a way for us to know which values are in fact invalid.
Andrew Arnott (@AArnott) I'm getting isHandle == false in DeclareTypeDefStruct for HGDIOBJ. Does that mean metadata is wrong? Should I make all typedef structs have IsNull or just handle structs?
Also, is there an assumed langversion level? I was thinking of generating value == default in case the field type is changed to IntPtr for langversion < 9. But I could also put in smarts so that we get:
value == default for 7.1+, otherwise value == default(IntPtr)
value == 0 for 9+, otherwise value == IntPtr.Zero
value is 0 for 9+, otherwise value == IntPtr.Zero
value == IntPtr.Zero always and make sure that we only generate this when value is pointer-sized (probably should anyway)
I would use option 4 from your list. Supporting down-level lang versions is a (low priority) goal and I want to avoid branching for different versions unless there's a really compelling reason, so going with the syntax that's supported by lower versions is preferred. That said, I can't see us supporting anything less than C# 7.1.
Does that mean metadata is wrong?
No. That's probably just a side-effect of our non-support of AlsoUsableForAttribute (#199). If HGDIOBJ has that attribute, we might follow to the next struct and see if it has an RIAAFree attribute on it.
But then, some structs are handles that should never be freed, so I guess using RIAAFree to determine whether a typedef represents a handle isn't the greatest way.
Should I make all typedef structs have IsNull or just handle structs?
Any IntPtr field-based typedef struct is probably a reasonable target, since as "pointers" null is a legit concept. If a typedef ever exists for what ought to be treated as nint we can deal with that later.
Activity
AArnott commentedon Mar 17, 2021
#122 is similar, in that we want an
IsNullproperty exposed there. But that's for a vtbl which clearly is null or non-null.In this case, what you probably really want to know is whether the handle is invalid. Note some handles are invalid when set to
0, while others are invalid at-1. Some are invalid with either value. So I think the new property should be calledIsInvalid.We're blocked on delivering this till the metadata delivers a way for us to know which values are in fact invalid.
jnm2 commentedon Mar 17, 2021
Actually, I'm specifically interested in
NULL(0), not in handle validity, because this is how SelectObject signals an error.https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject#return-value
jnm2 commentedon May 1, 2021
Andrew Arnott (@AArnott) Given my last comment, would you accept a PR for this?
jnm2 commentedon May 2, 2021
Andrew Arnott (@AArnott) I'm getting
isHandle == falsein DeclareTypeDefStruct for HGDIOBJ. Does that mean metadata is wrong? Should I make all typedef structs have IsNull or just handle structs?Also, is there an assumed langversion level? I was thinking of generating
value == defaultin case the field type is changed to IntPtr for langversion < 9. But I could also put in smarts so that we get:value == defaultfor 7.1+, otherwisevalue == default(IntPtr)value == 0for 9+, otherwisevalue == IntPtr.Zerovalue is 0for 9+, otherwisevalue == IntPtr.Zerovalue == IntPtr.Zeroalways and make sure that we only generate this whenvalueis pointer-sized (probably should anyway)AArnott commentedon May 3, 2021
I would use option 4 from your list. Supporting down-level lang versions is a (low priority) goal and I want to avoid branching for different versions unless there's a really compelling reason, so going with the syntax that's supported by lower versions is preferred. That said, I can't see us supporting anything less than C# 7.1.
No. That's probably just a side-effect of our non-support of
AlsoUsableForAttribute(#199). IfHGDIOBJhas that attribute, we might follow to the next struct and see if it has anRIAAFreeattribute on it.But then, some structs are handles that should never be freed, so I guess using
RIAAFreeto determine whether a typedef represents a handle isn't the greatest way.Any
IntPtrfield-based typedef struct is probably a reasonable target, since as "pointers"nullis a legit concept. If a typedef ever exists for what ought to be treated asnintwe can deal with that later.jnm2 commentedon May 3, 2021
Oh, hmm. I found this while searching for
== defaultto make the change to== IntPtr.Zero:CsWin32/src/Microsoft.Windows.CsWin32/Generator.cs
Line 1131 in e67e9c5
Should they stay consistent? Which way should they both be?
AArnott commentedon May 3, 2021
defaultis fine.jnm2 commentedon May 3, 2021
In that case, I'm already finished: #258