diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-03-07 19:28:30 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-03-07 19:28:30 +0000 |
commit | 8037da06feea097716ce700f38c0eac0d5411a7c (patch) | |
tree | 482fa34741bcdf650948eebb99903943137f4e19 /generator/generator_java.ml | |
parent | 7c721e4fd674c409b3eee60fe237d480afa1c5e2 (diff) | |
download | libguestfs-8037da06feea097716ce700f38c0eac0d5411a7c.tar.gz libguestfs-8037da06feea097716ce700f38c0eac0d5411a7c.tar.xz libguestfs-8037da06feea097716ce700f38c0eac0d5411a7c.zip |
generator: Introduce error code (errcode) concept.
There was a lot of repeated code to map return types (eg. RErr)
to error cases (eg. -1 or NULL).
This commit introduces an error code type and two functions to
map return types to error codes and error codes to strings.
Diffstat (limited to 'generator/generator_java.ml')
-rw-r--r-- | generator/generator_java.ml | 85 |
1 files changed, 47 insertions, 38 deletions
diff --git a/generator/generator_java.ml b/generator/generator_java.ml index dedf9625..767c94cf 100644 --- a/generator/generator_java.ml +++ b/generator/generator_java.ml @@ -374,40 +374,40 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr ")\n"; pr "{\n"; pr " guestfs_h *g = (guestfs_h *) (long) jg;\n"; - let error_code, no_ret = - match ret with - | RErr -> pr " int r;\n"; "-1", "" - | RBool _ - | RInt _ -> pr " int r;\n"; "-1", "0" - | RInt64 _ -> pr " int64_t r;\n"; "-1", "0" - | RConstString _ -> pr " const char *r;\n"; "NULL", "NULL" - | RConstOptString _ -> pr " const char *r;\n"; "NULL", "NULL" - | RString _ -> - pr " jstring jr;\n"; - pr " char *r;\n"; "NULL", "NULL" - | RStringList _ - | RHashtable _ -> - pr " jobjectArray jr;\n"; - pr " int r_len;\n"; - pr " jclass cl;\n"; - pr " jstring jstr;\n"; - pr " char **r;\n"; "NULL", "NULL" - | RStruct (_, typ) -> - pr " jobject jr;\n"; - pr " jclass cl;\n"; - pr " jfieldID fl;\n"; - pr " struct guestfs_%s *r;\n" typ; "NULL", "NULL" - | RStructList (_, typ) -> - pr " jobjectArray jr;\n"; - pr " jclass cl;\n"; - pr " jfieldID fl;\n"; - pr " jobject jfl;\n"; - pr " struct guestfs_%s_list *r;\n" typ; "NULL", "NULL" - | RBufferOut _ -> - pr " jstring jr;\n"; - pr " char *r;\n"; - pr " size_t size;\n"; - "NULL", "NULL" in + (match ret with + | RErr -> pr " int r;\n" + | RBool _ + | RInt _ -> pr " int r;\n" + | RInt64 _ -> pr " int64_t r;\n" + | RConstString _ -> pr " const char *r;\n" + | RConstOptString _ -> pr " const char *r;\n" + | RString _ -> + pr " jstring jr;\n"; + pr " char *r;\n" + | RStringList _ + | RHashtable _ -> + pr " jobjectArray jr;\n"; + pr " int r_len;\n"; + pr " jclass cl;\n"; + pr " jstring jstr;\n"; + pr " char **r;\n" + | RStruct (_, typ) -> + pr " jobject jr;\n"; + pr " jclass cl;\n"; + pr " jfieldID fl;\n"; + pr " struct guestfs_%s *r;\n" typ + | RStructList (_, typ) -> + pr " jobjectArray jr;\n"; + pr " jclass cl;\n"; + pr " jfieldID fl;\n"; + pr " jobject jfl;\n"; + pr " struct guestfs_%s_list *r;\n" typ + | RBufferOut _ -> + pr " jstring jr;\n"; + pr " char *r;\n"; + pr " size_t size;\n" + ); + List.iter ( function | Pathname n @@ -527,10 +527,19 @@ Java_com_redhat_et_libguestfs_GuestFS__1close ) args; (* Check for errors. *) - pr " if (r == %s) {\n" error_code; - pr " throw_exception (env, guestfs_last_error (g));\n"; - pr " return %s;\n" no_ret; - pr " }\n"; + (match errcode_of_ret ret with + | `CannotReturnError -> () + | `ErrorIsMinusOne -> + pr " if (r == -1) {\n"; + pr " throw_exception (env, guestfs_last_error (g));\n"; + pr " return -1;\n"; + pr " }\n" + | `ErrorIsNULL -> + pr " if (r == NULL) {\n"; + pr " throw_exception (env, guestfs_last_error (g));\n"; + pr " return NULL;\n"; + pr " }\n" + ); (* Return value. *) (match ret with |