comparison libinterp/octave-value/ov-java.cc @ 15800:d9b8333df5e4

Deprecate java_debug, java_convert_matrix, java_unsigned_conversion. Replace with debug_java, java_matrix_autoconversion, java_unsigned_autoconversion. * libinterp/octave-value/ov-java.h: Rename Vjava_debug, Vjava_unsigned_conversion, Vjava_convert_matrix to Vdebug_java, Vjava_unsigned_autoconversion, Vjava_matrix_autoconversion. * libinterp/octave-value/ov-java.cc(Fjava_debug, Fjava_unsigned_conversion, Fjava_convert_matrix): Rename functions to match variables in ov-java.h. Improve docstrings. * scripts/deprecated/module.mk: Add java_debug.m, java_convert_matrix.m, java_unsigned_conversion.m files to build system. * scripts/deprecated/java_convert_matrix.m: New m-file for deprecated function. * scripts/deprecated/java_debug.m: New m-file for deprecated function. * scripts/deprecated/java_unsigned_conversion.m: New m-file for deprecated function.
author Rik <rik@octave.org>
date Sun, 16 Dec 2012 21:43:52 -0800
parents ac9e34f83522
children 01d4f742d75d
comparison
equal deleted inserted replaced
15799:d0579fed7e22 15800:d9b8333df5e4
82 static std::map<int,octave_value> listener_map; 82 static std::map<int,octave_value> listener_map;
83 static std::map<int,octave_value> octave_ref_map; 83 static std::map<int,octave_value> octave_ref_map;
84 static int octave_java_refcount = 0; 84 static int octave_java_refcount = 0;
85 static long octave_thread_ID = -1; 85 static long octave_thread_ID = -1;
86 86
87 bool Vjava_convert_matrix = false; 87 bool Vjava_matrix_autoconversion = false;
88 bool Vjava_unsigned_conversion = true; 88 bool Vjava_unsigned_autoconversion = true;
89 bool Vjava_debug = false; 89 bool Vdebug_java = false;
90 90
91 class JVMArgs 91 class JVMArgs
92 { 92 {
93 public: 93 public:
94 94
128 { 128 {
129 std::getline (js, line); 129 std::getline (js, line);
130 if (line.length () > 2 130 if (line.length () > 2
131 && (line.find ("-D") == 0 || line.find ("-X") == 0)) 131 && (line.find ("-D") == 0 || line.find ("-X") == 0))
132 java_opts.push_back (line); 132 java_opts.push_back (line);
133 else if (line.length () > 0 && Vjava_debug) 133 else if (line.length () > 0 && Vdebug_java)
134 std::cerr << "invalid JVM option, skipping: " << line << std::endl; 134 std::cerr << "invalid JVM option, skipping: " << line << std::endl;
135 } 135 }
136 } 136 }
137 } 137 }
138 138
161 161
162 vm_args.nOptions = java_opts.size (); 162 vm_args.nOptions = java_opts.size ();
163 vm_args.options = new JavaVMOption [vm_args.nOptions]; 163 vm_args.options = new JavaVMOption [vm_args.nOptions];
164 for (std::list<std::string>::const_iterator it = java_opts.begin (); it != java_opts.end (); ++it) 164 for (std::list<std::string>::const_iterator it = java_opts.begin (); it != java_opts.end (); ++it)
165 { 165 {
166 if (Vjava_debug) 166 if (Vdebug_java)
167 std::cout << *it << std::endl; 167 std::cout << *it << std::endl;
168 vm_args.options[index++].optionString = strsave ((*it).c_str ()); 168 vm_args.options[index++].optionString = strsave ((*it).c_str ());
169 } 169 }
170 java_opts.clear (); 170 java_opts.clear ();
171 } 171 }
628 628
629 jthrowable_ref ex (jni_env, jni_env->ExceptionOccurred ()); 629 jthrowable_ref ex (jni_env, jni_env->ExceptionOccurred ());
630 630
631 if (ex) 631 if (ex)
632 { 632 {
633 if (Vjava_debug) 633 if (Vdebug_java)
634 jni_env->ExceptionDescribe (); 634 jni_env->ExceptionDescribe ();
635 635
636 jni_env->ExceptionClear (); 636 jni_env->ExceptionClear ();
637 637
638 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex)); 638 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
965 { 965 {
966 retval = jstring_to_string (jni_env, jobj); 966 retval = jstring_to_string (jni_env, jobj);
967 } 967 }
968 } 968 }
969 969
970 if (retval.is_undefined () && Vjava_convert_matrix) 970 if (retval.is_undefined () && Vjava_matrix_autoconversion)
971 { 971 {
972 cls = find_octave_class (jni_env, "org/octave/Matrix"); 972 cls = find_octave_class (jni_env, "org/octave/Matrix");
973 973
974 if (jni_env->IsInstanceOf (jobj, cls)) 974 if (jni_env->IsInstanceOf (jobj, cls))
975 { 975 {
996 jni_env->GetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ()); 996 jni_env->GetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ());
997 retval = m; 997 retval = m;
998 } 998 }
999 else if (s == "byte") 999 else if (s == "byte")
1000 { 1000 {
1001 if (Vjava_unsigned_conversion) 1001 if (Vjava_unsigned_autoconversion)
1002 { 1002 {
1003 uint8NDArray m (dims); 1003 uint8NDArray m (dims);
1004 mID = jni_env->GetMethodID (cls, "toByte", "()[B"); 1004 mID = jni_env->GetMethodID (cls, "toByte", "()[B");
1005 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID))); 1005 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID)));
1006 jni_env->GetByteArrayRegion (dv, 0, m.length (), reinterpret_cast<jbyte *> (m.fortran_vec ())); 1006 jni_env->GetByteArrayRegion (dv, 0, m.length (), reinterpret_cast<jbyte *> (m.fortran_vec ()));
1015 retval = m; 1015 retval = m;
1016 } 1016 }
1017 } 1017 }
1018 else if (s == "integer") 1018 else if (s == "integer")
1019 { 1019 {
1020 if (Vjava_unsigned_conversion) 1020 if (Vjava_unsigned_autoconversion)
1021 { 1021 {
1022 uint32NDArray m (dims); 1022 uint32NDArray m (dims);
1023 mID = jni_env->GetMethodID (cls, "toInt", "()[I"); 1023 mID = jni_env->GetMethodID (cls, "toInt", "()[I");
1024 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID))); 1024 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
1025 jni_env->GetIntArrayRegion (dv, 0, m.length (), reinterpret_cast<jint *> (m.fortran_vec ())); 1025 jni_env->GetIntArrayRegion (dv, 0, m.length (), reinterpret_cast<jint *> (m.fortran_vec ()));
1189 { 1189 {
1190 jobj = 0; 1190 jobj = 0;
1191 //jcls = jni_env->FindClass ("java/lang/Object"); 1191 //jcls = jni_env->FindClass ("java/lang/Object");
1192 jcls = 0; 1192 jcls = 0;
1193 } 1193 }
1194 else if (!Vjava_convert_matrix 1194 else if (!Vjava_matrix_autoconversion
1195 && ((val.is_real_matrix () 1195 && ((val.is_real_matrix ()
1196 && (val.rows () == 1 || val.columns () == 1)) 1196 && (val.rows () == 1 || val.columns () == 1))
1197 || val.is_range ())) 1197 || val.is_range ()))
1198 { 1198 {
1199 Matrix m = val.matrix_value (); 1199 Matrix m = val.matrix_value ();
1201 //for (int i = 0; i < m.length (); i++) 1201 //for (int i = 0; i < m.length (); i++)
1202 jni_env->SetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ()); 1202 jni_env->SetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ());
1203 jobj = dv; 1203 jobj = dv;
1204 jcls = jni_env->GetObjectClass (jobj); 1204 jcls = jni_env->GetObjectClass (jobj);
1205 } 1205 }
1206 else if (Vjava_convert_matrix 1206 else if (Vjava_matrix_autoconversion
1207 && (val.is_matrix_type () || val.is_range ()) && val.is_real_type ()) 1207 && (val.is_matrix_type () || val.is_range ()) && val.is_real_type ())
1208 { 1208 {
1209 jclass_ref mcls (jni_env, find_octave_class (jni_env, "org/octave/Matrix")); 1209 jclass_ref mcls (jni_env, find_octave_class (jni_env, "org/octave/Matrix"));
1210 dim_vector dims = val.dims (); 1210 dim_vector dims = val.dims ();
1211 jintArray_ref iv (jni_env, jni_env->NewIntArray (dims.length ())); 1211 jintArray_ref iv (jni_env, jni_env->NewIntArray (dims.length ()));
2164 error ("java2mat: Octave was not compiled with Java interface"); 2164 error ("java2mat: Octave was not compiled with Java interface");
2165 return octave_value (); 2165 return octave_value ();
2166 #endif 2166 #endif
2167 } 2167 }
2168 2168
2169 DEFUN (java_convert_matrix, args, nargout, 2169 DEFUN (java_matrix_autoconversion, args, nargout,
2170 "-*- texinfo -*-\n\ 2170 "-*- texinfo -*-\n\
2171 @deftypefn {Built-in Function} {} java_convert_matrix ()\n\ 2171 @deftypefn {Built-in Function} {@var{val} =} java_matrix_autoconversion ()\n\
2172 FIXME: Determine what this variable controls and rename function\n\ 2172 @deftypefnx {Built-in Function} {@var{old_val} =} java_matrix_autoconversion (@var{new_val})\n\
2173 Query or set the internal variable that determines FIXME.\n\ 2173 @deftypefnx {Built-in Function} {} java_matrix_autoconversion (@var{new_val}, \"local\")\n\
2174 @seealso{java_unsigned_conversion, java_debug}\n\ 2174 Query or set the internal variable that controls whether Java arrays are\n\
2175 automatically converted to Octave matrices. The default value is false.\n\
2176 \n\
2177 When called from inside a function with the \"local\" option, the variable is\n\
2178 changed locally for the function and any subroutines it calls. The original\n\
2179 variable value is restored when exiting the function.\n\
2180 @seealso{java_unsigned_autoconversion, debug_java}\n\
2175 @end deftypefn") 2181 @end deftypefn")
2176 { 2182 {
2177 #ifdef HAVE_JAVA 2183 #ifdef HAVE_JAVA
2178 return SET_INTERNAL_VARIABLE (java_convert_matrix); 2184 return SET_INTERNAL_VARIABLE (java_matrix_autoconversion);
2179 #else 2185 #else
2180 error ("java_convert_matrix: Octave was not compiled with Java interface"); 2186 error ("java_matrix_autoconversion: Octave was not compiled with Java interface");
2181 return octave_value (); 2187 return octave_value ();
2182 #endif 2188 #endif
2183 } 2189 }
2184 2190
2185 DEFUN (java_unsigned_conversion, args, nargout, 2191 DEFUN (java_unsigned_autoconversion, args, nargout,
2186 "-*- texinfo -*-\n\ 2192 "-*- texinfo -*-\n\
2187 @deftypefn {Built-in Function} {} java_unsigned_conversion ()\n\ 2193 @deftypefn {Built-in Function} {@var{val} =} java_unsigned_autoconversion ()\n\
2188 FIXME: Determine what this variable controls and rename function\n\ 2194 @deftypefnx {Built-in Function} {@var{old_val} =} java_unsigned_autoconversion (@var{new_val})\n\
2189 Query or set the internal variable that determines FIXME.\n\ 2195 @deftypefnx {Built-in Function} {} java_unsigned_autoconversion (@var{new_val}, \"local\")\n\
2190 @seealso{java_convert_matrix, java_debug}\n\ 2196 Query or set the internal variable that controls how integer classes are\n\
2197 converted when Java matrix autoconversion is enabled. When enabled, Java\n\
2198 arrays of class Byte or Integer are converted to matrices of class uint8 or\n\
2199 uint32 respectively.\n\
2200 \n\
2201 When called from inside a function with the \"local\" option, the variable is\n\
2202 changed locally for the function and any subroutines it calls. The original\n\
2203 variable value is restored when exiting the function.\n\
2204 @seealso{java_matrix_autoconversion, debug_java}\n\
2191 @end deftypefn") 2205 @end deftypefn")
2192 { 2206 {
2193 #ifdef HAVE_JAVA 2207 #ifdef HAVE_JAVA
2194 return SET_INTERNAL_VARIABLE (java_unsigned_conversion); 2208 return SET_INTERNAL_VARIABLE (java_unsigned_autoconversion);
2195 #else 2209 #else
2196 error ("java_unsigned_conversion: Octave was not compiled with Java interface"); 2210 error ("java_unsigned_autoconversion: Octave was not compiled with Java interface");
2197 return octave_value (); 2211 return octave_value ();
2198 #endif 2212 #endif
2199 } 2213 }
2200 2214
2201 DEFUN (java_debug, args, nargout, 2215 DEFUN (debug_java, args, nargout,
2202 "-*- texinfo -*-\n\ 2216 "-*- texinfo -*-\n\
2203 @deftypefn {Built-in Function} {} java_debug ()\n\ 2217 @deftypefn {Built-in Function} {@var{val} =} debug_java ()\n\
2204 FIXME: Determine what this variable controls and rename function\n\ 2218 @deftypefnx {Built-in Function} {@var{old_val} =} debug_java (@var{new_val})\n\
2205 Query or set the internal variable that determines FIXME.\n\ 2219 @deftypefnx {Built-in Function} {} debug_java (@var{new_val}, \"local\")\n\
2206 @seealso{java_convert_matrix, java_unsigned_conversion}\n\ 2220 Query or set the internal variable that determines whether extra debugging\n\
2221 information regarding the initialization of the JVM and any Java exceptions\n\
2222 is printed.\n\
2223 \n\
2224 When called from inside a function with the \"local\" option, the variable is\n\
2225 changed locally for the function and any subroutines it calls. The original\n\
2226 variable value is restored when exiting the function.\n\
2227 @seealso{java_matrix_autoconversion, java_unsigned_autoconversion}\n\
2207 @end deftypefn") 2228 @end deftypefn")
2208 { 2229 {
2209 #ifdef HAVE_JAVA 2230 #ifdef HAVE_JAVA
2210 return SET_INTERNAL_VARIABLE (java_debug); 2231 return SET_INTERNAL_VARIABLE (debug_java);
2211 #else 2232 #else
2212 error ("java_debug: Octave was not compiled with Java interface"); 2233 error ("debug_java: Octave was not compiled with Java interface");
2213 return octave_value (); 2234 return octave_value ();
2214 #endif 2235 #endif
2215 } 2236 }
2216 2237
2217 // Outside of #ifdef HAVE_JAVA because it is desirable to be able to 2238 // Outside of #ifdef HAVE_JAVA because it is desirable to be able to