From: Richard W.M. Jones Date: Tue, 19 Jul 2011 13:32:45 +0000 (+0100) Subject: java: Enable warnings when compiling C bindings code. X-Git-Tag: 1.11.20~6 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=c79ba93f7e53f6a62b5793ba35f1c3b13527eef6;p=libguestfs.git java: Enable warnings when compiling C bindings code. And fix the code so it doesn't generate warnings. --- diff --git a/generator/generator_java.ml b/generator/generator_java.ml index 97bee84..9cd84d8 100644 --- a/generator/generator_java.ml +++ b/generator/generator_java.ml @@ -387,7 +387,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close | RStringList _ | RHashtable _ -> pr " jobjectArray jr;\n"; - pr " int r_len;\n"; + pr " size_t r_len;\n"; pr " jclass cl;\n"; pr " jstring jstr;\n"; pr " char **r;\n" @@ -419,11 +419,11 @@ Java_com_redhat_et_libguestfs_GuestFS__1close | Key n -> pr " const char *%s;\n" n | BufferIn n -> - pr " jbyte *%s;\n" n; + pr " char *%s;\n" n; pr " size_t %s_size;\n" n | StringList n | DeviceList n -> - pr " int %s_len;\n" n; - pr " const char **%s;\n" n + pr " size_t %s_len;\n" n; + pr " char **%s;\n" n | Bool n | Int n -> pr " int %s;\n" n @@ -464,7 +464,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close *) pr " %s = j%s ? (*env)->GetStringUTFChars (env, j%s, NULL) : NULL;\n" n n n | BufferIn n -> - pr " %s = (*env)->GetByteArrayElements (env, j%s, NULL);\n" n n; + pr " %s = (char *) (*env)->GetByteArrayElements (env, j%s, NULL);\n" n n; pr " %s_size = (*env)->GetArrayLength (env, j%s);\n" n n | StringList n | DeviceList n -> pr " %s_len = (*env)->GetArrayLength (env, j%s);\n" n n; @@ -472,7 +472,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " for (i = 0; i < %s_len; ++i) {\n" n; pr " jobject o = (*env)->GetObjectArrayElement (env, j%s, i);\n" n; - pr " %s[i] = (*env)->GetStringUTFChars (env, o, NULL);\n" n; + pr " %s[i] = (char *) (*env)->GetStringUTFChars (env, o, NULL);\n" n; pr " }\n"; pr " %s[%s_len] = NULL;\n" n n; | Bool n @@ -512,7 +512,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " if (j%s)\n" n; pr " (*env)->ReleaseStringUTFChars (env, j%s, %s);\n" n n | BufferIn n -> - pr " (*env)->ReleaseByteArrayElements (env, j%s, %s, 0);\n" n n + pr " (*env)->ReleaseByteArrayElements (env, j%s, (jbyte *) %s, 0);\n" n n | StringList n | DeviceList n -> pr " for (i = 0; i < %s_len; ++i) {\n" n; pr " jobject o = (*env)->GetObjectArrayElement (env, j%s, i);\n" @@ -529,15 +529,27 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Check for errors. *) (match errcode_of_ret ret with | `CannotReturnError -> () - | `ErrorIsMinusOne -> - pr " if (r == -1) {\n"; + | (`ErrorIsMinusOne|`ErrorIsNULL) as errcode -> + (match errcode with + | `ErrorIsMinusOne -> + pr " if (r == -1) {\n"; + | `ErrorIsNULL -> + pr " if (r == NULL) {\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"; + (match ret with + | RErr -> + pr " return;\n" + | RInt _ + | RInt64 _ + | RBool _ -> + pr " return -1;\n" + | RConstString _ | RConstOptString _ | RString _ + | RBufferOut _ + | RStruct _ | RHashtable _ + | RStringList _ | RStructList _ -> + pr " return NULL;\n" + ); pr " }\n" ); diff --git a/java/Makefile.am b/java/Makefile.am index 3a64b0e..3ae1123 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -73,7 +73,10 @@ libguestfs_jni_la_SOURCES = \ libguestfs_jni_la_LIBADD = $(top_builddir)/src/libguestfs.la libguestfs_jni_la_LDFLAGS = -version-info $(JNI_VERSION_INFO) -libguestfs_jni_la_CFLAGS = -Wall -I$(top_srcdir)/src -I$(top_builddir)/src $(JNI_CFLAGS) +libguestfs_jni_la_CFLAGS = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_builddir)/src \ + $(JNI_CFLAGS) BUILT_SOURCES = com_redhat_et_libguestfs_GuestFS.h