No functional change.
---
generator/java.ml | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/generator/java.ml b/generator/java.ml
index 9f68eb1..cce1758 100644
--- a/generator/java.ml
+++ b/generator/java.ml
@@ -1165,41 +1165,46 @@ and generate_java_struct_list_return typ jtyp cols =
pr " jfl = (*env)->AllocObject (env, cl);\n";
pr "\n";
List.iter (
- function
- | name, FString ->
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"Ljava/lang/String;\");\n" name;
+ fun (name, ftyp) ->
+ (* Get the field ID in 'fl'. *)
+ let java_field_type = match ftyp with
+ | FString | FUUID | FBuffer -> "Ljava/lang/String;"
+ | FBytes | FUInt64 | FInt64 -> "J"
+ | FUInt32 | FInt32 -> "I"
+ | FOptPercent -> "F"
+ | FChar -> "C" in
+ pr " fl = (*env)->GetFieldID (env, cl, \"%s\",\n" name;
+ pr " \"%s\");\n" java_field_type;
+
+ (* Assign the value to this field. *)
+ match ftyp with
+ | FString ->
pr " (*env)->SetObjectField (env, jfl, fl,\n";
pr " (*env)->NewStringUTF (env,
r->val[i].%s));\n" name;
- | name, FUUID ->
+ | FUUID ->
pr " {\n";
pr " char s[33];\n";
pr " memcpy (s, r->val[i].%s, 32);\n" name;
pr " s[32] = 0;\n";
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"Ljava/lang/String;\");\n" name;
pr " (*env)->SetObjectField (env, jfl, fl,\n";
pr " (*env)->NewStringUTF (env,
s));\n";
pr " }\n";
- | name, FBuffer ->
+ | FBuffer ->
pr " {\n";
pr " size_t len = r->val[i].%s_len;\n" name;
pr " char s[len+1];\n";
pr " memcpy (s, r->val[i].%s, len);\n" name;
pr " s[len] = 0;\n";
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"Ljava/lang/String;\");\n" name;
pr " (*env)->SetObjectField (env, jfl, fl,\n";
pr " (*env)->NewStringUTF (env,
s));\n";
pr " }\n";
- | name, (FBytes|FUInt64|FInt64) ->
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"J\");\n" name;
+ | FBytes|FUInt64|FInt64 ->
pr " (*env)->SetLongField (env, jfl, fl, r->val[i].%s);\n"
name;
- | name, (FUInt32|FInt32) ->
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"I\");\n" name;
+ | FUInt32|FInt32 ->
pr " (*env)->SetLongField (env, jfl, fl, r->val[i].%s);\n"
name;
- | name, FOptPercent ->
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"F\");\n" name;
+ | FOptPercent ->
pr " (*env)->SetFloatField (env, jfl, fl, r->val[i].%s);\n"
name;
- | name, FChar ->
- pr " fl = (*env)->GetFieldID (env, cl, \"%s\",
\"C\");\n" name;
+ | FChar ->
pr " (*env)->SetLongField (env, jfl, fl, r->val[i].%s);\n"
name;
) cols;
pr "\n";
--
1.8.5.3