changeset 20121:41064c150724

Return bools instead of ints in oc-java box and unbox internal functions. * libinterp/octave-value/ov-java.cc (unbox): this functions return an int with value of 0 or 1 only but are always used as booleans.
author Carnë Draug <carandraug@octave.org>
date Mon, 20 Apr 2015 17:23:28 +0100
parents 2db2db2df55b
children 81fcf4aa9e03
files libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-java.h
diffstat 2 files changed, 15 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-java.cc	Mon Apr 20 15:01:27 2015 +0100
+++ b/libinterp/octave-value/ov-java.cc	Mon Apr 20 17:23:28 2015 +0100
@@ -1261,11 +1261,11 @@
   return retval;
 }
 
-int
+bool
 unbox (JNIEnv* jni_env, const octave_value& val, jobject_ref& jobj,
        jclass_ref& jcls)
 {
-  int found = 1;
+  bool found = true;
 
   if (val.is_java ())
     {
@@ -1393,7 +1393,7 @@
         }
       else
         {
-          found = 0;
+          found = false;
           error ("cannot convert matrix of type '%s'", val.class_name ().c_str ());
         }
     }
@@ -1425,11 +1425,11 @@
   return found;
 }
 
-int
+bool
 unbox (JNIEnv* jni_env, const octave_value_list& args,
        jobjectArray_ref& jobjs, jobjectArray_ref& jclss)
 {
-  int found = 1;
+  bool found = true;
 
   jclass_ref ocls (jni_env, jni_env->FindClass ("java/lang/Object"));
   jclass_ref ccls (jni_env, jni_env->FindClass ("java/lang/Class"));
@@ -1445,11 +1445,9 @@
       jobject_ref jobj (jni_env);
       jclass_ref jcls (jni_env);
 
-      if (! unbox (jni_env, args(i), jobj, jcls))
-        {
-          found = 0;
-          break;
-        }
+      found = unbox (jni_env, args(i), jobj, jcls);
+      if (! found)
+        break;
 
       jni_env->SetObjectArrayElement (jobjs, i, jobj);
       jni_env->SetObjectArrayElement (jclss, i, jcls);
@@ -1537,18 +1535,12 @@
     varargin(i) = box (env, env->GetObjectArrayElement (argin, i), 0);
 
   varargout = feval (fname, varargin, nargout);
-
-  if (! error_state)
-    {
-      jobjectArray_ref out_objs (env, argout), out_clss (env);
+  if (error_state)
+    return false;
 
-      out_objs.detach ();
-
-      if (unbox (env, varargout, out_objs, out_clss))
-        return true;
-    }
-
-  return false;
+  jobjectArray_ref out_objs (env, argout), out_clss (env);
+  out_objs.detach ();
+  return unbox (env, varargout, out_objs, out_clss);
 }
 
 JNIEXPORT void JNICALL
--- a/libinterp/octave-value/ov-java.h	Mon Apr 20 15:01:27 2015 +0100
+++ b/libinterp/octave-value/ov-java.h	Mon Apr 20 17:23:28 2015 +0100
@@ -95,11 +95,11 @@
 extern OCTINTERP_API octave_value
 box_more (JNIEnv* jni_env, jobject jobj, jclass jcls = 0);
 
-extern OCTINTERP_API int
+extern OCTINTERP_API bool
 unbox (JNIEnv* jni_env, const octave_value& val, jobject_ref& jobj,
        jclass_ref& jcls);
 
-extern OCTINTERP_API int
+extern OCTINTERP_API bool
 unbox (JNIEnv* jni_env, const octave_value_list& args,
        jobjectArray_ref& jobjs, jobjectArray_ref& jclss);