[Pkg-libvirt-commits] [libguestfs] 05/16: java: Factor out common field code in RStructList.

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 9 11:21:32 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 7a0e71f7331540809db5f539d1a9fe2af050c56a
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Mar 7 14:25:14 2014 +0000

    java: Factor out common field code in RStructList.
    
    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";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list