-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Java: fix unsigned default value code generation and add 'L' suffix for long default value #4051
Conversation
… code and add "L" suffix to long default value.
I don't think I understand. We use "user facing" signed types one size bigger whenever you read an unsigned value. So |
Hmm, indeed I suspect you are correct. The "signed" conversion should only be needed for ulong. Now that generated code compile, I can write some tests. I'll get back to you once I've done that. |
…d specific handling as "user facing" type is int. uint need 'L' suffix as "user facing" type is long.
…buffers into java_unsigned_default_value # Conflicts: # tests/MyGame/Example/Monster.java
…er facing" type in builder.add<type>() calls.
public static void addTesthashu32Fnv1(FlatBufferBuilder builder, long testhashu32Fnv1) { builder.addInt(17, (int)testhashu32Fnv1, 0); } | ||
public static void addTesthashs64Fnv1(FlatBufferBuilder builder, long testhashs64Fnv1) { builder.addLong(18, testhashs64Fnv1, 0); } | ||
public static void addTesthashu64Fnv1(FlatBufferBuilder builder, long testhashu64Fnv1) { builder.addLong(19, testhashu64Fnv1, 0); } | ||
public static void addTesthashu32Fnv1(FlatBufferBuilder builder, long testhashu32Fnv1) { builder.addInt(17, (int)testhashu32Fnv1, (int)0L); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it is adding both the L and an (int) cast, that may be a bit superfluous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you asked, the code that generate the default value do it using user facing type. The problem is that some part of the builder API don't use user facing type, hence the cast.
@@ -26,7 +26,7 @@ public partial struct TestSimpleTableWithEnum : IFlatbufferObject | |||
} | |||
|
|||
public static void StartTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.StartObject(1); } | |||
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, 2); } | |||
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, (sbyte)2); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not be needed in C#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, should be fixed now.
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
This PR gained a lot commits and changed files, something is not quite right? |
d89aded
to
1945e11
Compare
CLAs look good, thanks! |
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
d89aded
to
1945e11
Compare
CLAs look good, thanks! |
Fixed too many commit issues (I had merged romain's master by error instead of upstream). |
code += ", " + GenDefaultValue(field.value, false); | ||
code += ", "; | ||
if (lang_.language == IDLOptions::kJava) | ||
code += SourceCastBasic( field.value.type ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove spaces in ()
Mostly looks good.. ready to go in? |
Yes, this has been well tested on my side with keysearch_test #4048 generated code. |
Thanks! |
As mentionned in #4048 (keysearch_test), Java code generation is currently broken w.r.t. default value:
This PR fix those issue by "converting" unsigned value to their signed equivalent in Java (255 becomes -1), and adding 'L' suffix to long default value.
The full impact can be seen in one of our branch (where I integrated most pending PR):
https://github.com/rgilles/flatbuffers/blob/java_fieldbykey/tests/keysearch_test/Testing/KeySearch/UIntEntry.java#L19
Default value is -1 instead of 4294967295 as is currently generated:
https://github.com/rgilles/flatbuffers/blob/keysearch_test_data/tests/keysearch_test/Testing/KeySearch/UIntEntry.java#L19