-
Notifications
You must be signed in to change notification settings - Fork 117
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
BITMAPINFO metadata is wrong (and may be hard to fix) #266
Comments
Metadata describes exactly the same struct defined in gdi.h:
Metadata:
|
I don't deny that it matches the header. But the header only tells a part of the story. The docs tell the rest, and the rest is that the header is misleading. For example the header claims the second field is an array with length of 1, but that is perhaps never really the case. |
There are around 700 structures across metadata having variable length arrays at the end, e.g. all the The problem is that the number of elements |
Likewise, variable-length arrays are an example of a fundamentally unsafe type which has additional constraints not representable by the type system. This holds true even in C/C++. The type system does not contain enough metadata to know or even represent that |
We came to a good place over at microsoft/CsWin32#117 where we think we can do the right thing if the metadata can indicate that the array has variable length. Bonus points if it can point out the field that indicates what the length is. If the header files don't disclose that it has variable length, perhaps we can infer it by the use of |
That seems like a good assumption. I could add an attribute as well if that would help, but @rumbu13 says there are around 700 (!) that do this. |
Are you suggesting that projections figure this out based on the pattern? If projections over time figure out these patterns and hard-code them, exceptions to the rule or refining the rule will be very slow to propagate through all the projections. I would favor finding a way to encode the rule in the metadata so that projections can just take the attribute as truth, and we can fiddle with the attributes as needed over time. Is there some way your metadata build can add the attribute to the 700 structs automatically so it's less tedious work for you? |
Yeah, that makes sense for the metadata writer to auto-add the attribute. |
ClangSharp already "supports" this and it uses a length of |
This was changed a while ago to set the length of the array to be 0. I went with what @tannergooding suggested, that we set the array length to 0 which implies it's a variable-length array. |
The BITMAPINFO struct represents a header and then an array that is arbitrarily long. Its length is determined by the header. It also may not be RGBQUAD at all.
The text was updated successfully, but these errors were encountered: