Skip to content
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

Golang: fix enum type for large values #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucebac
Copy link
Contributor

@lucebac lucebac commented Jun 21, 2022

When using 32bit Golang, the standard int type only holds 32 bits. This is a problem when the enum keys are larger than Int.MaxValue. This fix should solve the problem for Golang. However, I cannot tell whether this issue also affects other languages which then need a fix as well. Maybe, there is a more thorough solution for this anyway - I'm not at all used to Scala so my fix might be not the ideal way of doing this.

@puhitaku
Copy link

+1

@GreyCat
Copy link
Member

GreyCat commented Jul 21, 2023

@lucebac @puhitaku
Apologies for very late response.

  1. Do we need a new test to cover these among others already available in tests repo?
  2. Do we need a special golang build to test this? (rather than the one we use in CI)

@lucebac
Copy link
Contributor Author

lucebac commented Jul 22, 2023

  1. I am not sure. Please see this part of my code where I needed these large enum values for: https://github.com/GDATAAdvancedAnalytics/winreg-tasks/blob/72bc92e0623f9ed3212a04bf81bcce9efc7d7216/kaitai/optional_settings.ksy#L89..L93
  2. no, Golang natively supports 64 bit integers. My change just makes kaitai use 64bit integers in enums when the values exceed the maximum for 32bit integers. So as long as the fix is in place, everything should be working ootb

@GreyCat
Copy link
Member

GreyCat commented Jul 24, 2023

  1. I am not sure. Please see this part of my code where I needed these large enum values for: https://github.com/GDATAAdvancedAnalytics/winreg-tasks/blob/72bc92e0623f9ed3212a04bf81bcce9efc7d7216/kaitai/optional_settings.ksy#L89..L93

Got it, let me try to reproduce it in a test.

In this specific case you seem to be abusing enums for bitmasks. Very likely you'd want to replace that enum with a separate type with bit-sized flags.

@lucebac
Copy link
Contributor Author

lucebac commented Jul 25, 2023

Yes and no. I want to be able to export the enum members in generated code so I believe the enum is correct

@lucebac
Copy link
Contributor Author

lucebac commented Nov 1, 2023

Hi @GreyCat
have found the time to decide on whether or not this change will be accepted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants