Fix generation of long-typed defines when on Linux#699
Draft
Exanite wants to merge 10 commits into
Draft
Conversation
This is my initial guess for what the output should look like.
Member
Author
|
There is also a similar case with Also from OpenCL: #if INTPTR_MAX == INT32_MAX
#define CL_ICD2_TAG_KHR ((intptr_t)0x434C3331)
#else
#define CL_ICD2_TAG_KHR ((intptr_t)0x4F50454E434C3331)
#endifThis generates as the following on both Windows and Linux: [NativeTypeName("#define CL_ICD2_TAG_KHR ((intptr_t)0x4F50454E434C3331)")]
public const nint CL_ICD2_TAG_KHR = unchecked((nint)(0x4F50454E434C3331));In this case, the only change needed to make this compile would be to replace |
… other observations
Will keep investigating the conditions a bit more since I'm not quite convinced this is optimal.
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
For context, C
longis output as C#ninton Linux.This causes an issue where a 64-bit
ulongvalue can be used as the initializer for aconstfield of typenint, leading to 2 errors:longtonint, causing a compile error.nintuntil run time, this errors withConstant initializer must be compile-time constantafter fixing the first error. This is specified here: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/native-integers.mdThis PR fixes the issue by updating the generator to output the expected test output below, along with some additional test cases.
Current test outputs (matching main branch)
This is the current output of the new
CLongDefinesTestUnixtest case on Linux when ran against the main branch.The new
CLongDefinesTestWindowstest case already passes and is there to ensure that no unintended changes occur to the Windows behavior.Expected test outputs
The expected test outputs are my proposal for roughly what the expected bindings output should look like.
Notably, we need to add a type cast and change the field to be a
static readonlyfield instead of aconstfield.Remaining Tasks
I'll handle these tasks before undrafting.