-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow enums to implement NativeMapped
#1003
Conversation
There is alternative, that does not even need changes to the enums: Use a TypeConverter and register that with the typemapper of the structure/library. I suggest to try that way first. |
@matthiasblaesing Sorry for the late response. Should the But even if it works I think this change would enable users to use an alternative way to handle enums. And with default interface methods this can be slipstreamed a lot. |
I see the benefit for types you have control over, so I tend to agree merging this. But please also add unittest(s), that verify the correct handling of the Enums. I adjusted the existing test for enum mapping to also cover the structure case (it indeed needed adjusting). See here: Please also add a note to CHANGES.md for this feature. Have a look at the other entries as a template. Default Interfaces are currently out of scope, as the target java version is still 6. I also doubt, that a default interface is a really good idea. C enums don't need to start at 0 and can have arbitrary integer values, so ordinal works often, but not always. |
So is this a known bug in JNA 4.5.2 or did it just affect the tests? The Errors are like below:
And this problem can be fixed with my patch. |
My change only added a full implementation of the TypeMapper and the corresponding test. The call For your patch I already admitted, that there is value and I'd be willing to merge it, but it requires testing and adjustment of the changelog. |
This will allow enums to be used inside structures.
9e99612
to
21f2b31
Compare
I added a few tests for the code I touched. Where should I put this inside |
Merged with slight changes - thank you! |
Great, thanks! |
This will allow enums to be used inside structures.
Currently (i.e. 4.5.x), it’s impossible to use enums (instead of
int
) inside aStructure
. This will fail inNative.getNativeSize()
.This patch will fix this problem and allow enums like:
With Java 8’s
default
methods it’s even possible to completely move this into an own interface, so you’ll only need to add the interface to an enum and be done.PS: I don’t know which Java version JNA is currently targeting. Should I add such a special enum interface with default methods to this patch?