31 #if defined (HAVE_CONFIG_H)
35 #if defined (HAVE_WINDOWS_H)
48 #include "builtin-defun-decls.h"
68 #if defined (HAVE_JAVA)
72 #if defined (HAVE_JAVA)
76 #if defined (OCTAVE_USE_WINDOWS_API)
77 # define LIBJVM_FILE_NAME "jvm.dll"
78 #elif defined (__APPLE__)
79 # define LIBJVM_FILE_NAME "libjvm.dylib"
80 # define JAVA_HOME_CMD "/usr/libexec/java_home"
82 # define LIBJVM_FILE_NAME "libjvm.so"
85 #define TO_JOBJECT(obj) reinterpret_cast<jobject> (obj)
86 #define TO_JCLASS(obj) reinterpret_cast<jclass> (obj)
88 #define TO_JNIENV(env) reinterpret_cast<JNIEnv *> (env)
119 operator bool ()
const {
return (
jobj != 0); }
161 box (JNIEnv *jni_env,
void *jobj,
void *jcls_arg =
nullptr);
164 box_more (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg =
nullptr);
176 JNIEXPORT jboolean JNICALL
180 JNIEXPORT
void JNICALL
183 JNIEXPORT
void JNICALL
186 JNIEXPORT
void JNICALL
189 JNIEXPORT jboolean JNICALL
196 static JavaVM *
jvm =
nullptr;
233 vm_args.version = JNI_VERSION_1_6;
236 vm_args.ignoreUnrecognized =
false;
250 void add (
const std::string& opt)
259 if (! js.bad () && ! js.fail ())
263 while (! js.eof () && ! js.fail ())
265 std::getline (js,
line);
267 if (
line.find (
'-') == 0)
270 warning (
"invalid JVM option, skipping: %s",
line.c_str ());
279 if (
vm_args.options !=
nullptr)
281 for (
int i = 0; i <
vm_args.nOptions; i++)
282 delete []
vm_args.options[i].optionString;
344 static std::string java_dir;
346 if (java_dir.empty ())
350 if (java_dir.empty ())
375 std::string classpath;
379 if (! fs.bad () && ! fs.fail ())
383 while (! fs.eof () && ! fs.fail ())
385 std::getline (fs,
line);
386 if (
line.length () > 0 &&
line[0] !=
'#' &&
line[0] !=
'%')
392 int last =
line.find_last_not_of (
" \t\f\v\r\n");
426 std::string
retval = java_dir;
433 std::string jar_file = java_dir + sep +
"octave.jar";
453 std::vector<std::string> cp_list = {
"javaclasspath.txt",
456 for (std::string filename : cp_list)
458 std::string cp_file = filename;
468 retval.append (classpath);
475 cp_file =
'~' + sep + filename;
482 retval.append (classpath);
490 cp_file = java_dir + sep + filename;
496 retval.append (classpath);
502 error (
"octave.jar does not exist: %s", jar_file.c_str ());
505 error (
"initial java dir is empty");
515 #if defined (OCTAVE_USE_WINDOWS_API)
516 std::string subdirs[] = {
"bin/client",
"bin/server"};
518 std::string subdirs[] = {
"jre/lib/server",
"jre/lib",
519 "lib/client",
"lib/server",
520 "jre/lib/amd64/client",
"jre/lib/amd64/server",
521 "jre/lib/i386/client",
"jre/lib/i386/server"
525 for (
size_t i = 0; i <
sizeof (subdirs) /
sizeof (subdirs[0]); i++)
527 std::string candidate = java_home_path +
"/" + subdirs[i]
535 #if defined (OCTAVE_USE_WINDOWS_API)
541 get_regkey_value (HKEY h_rootkey,
const std::string subkey,
546 get_jvm_lib_path_from_registry ()
549 std::string key, jversion, value;
552 key = R
"(software\javasoft\jdk)";
555 bool maybe_version_15_or_newer =
true;
558 if (jversion.empty ())
560 value =
"CurrentVersion";
561 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
564 if (
retval != ERROR_SUCCESS)
567 maybe_version_15_or_newer =
false;
568 key = R
"(software\javasoft\jre)";
569 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
572 if (
retval != ERROR_SUCCESS)
575 key = R
"(software\javasoft\java runtime environment)";
576 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key,
581 if (
retval != ERROR_SUCCESS)
582 error (
"unable to find Java Runtime Environment: %s::%s",
583 key.c_str (), value.c_str ());
585 jversion = regval.
xstring_value (
"initialize_jvm: registry value "
586 R
"("%s" at "%s" must be a string)",
587 value.c_str (), key.c_str ());
590 std::string jvm_lib_path;
591 if (maybe_version_15_or_newer)
594 key = key +
'\\' + jversion;
596 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
599 if (
retval != ERROR_SUCCESS)
600 error (
"unable to find Java Runtime Environment: %s::%s",
601 key.c_str (), value.c_str ());
604 = regval.
xstring_value (R
"(initialize_jvm: registry value "%s" at )"
605 R"("%s" must be a string)",
606 value.c_str (), key.c_str ())
607 + R"(\bin\server\jvm.dll)";
609 if (! jvm_lib_path.empty ())
615 key = R
"(software\javasoft\jre\)" + jversion;
616 value = "RuntimeLib";
617 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
620 if (
retval != ERROR_SUCCESS)
623 key = R
"(software\javasoft\java runtime environment\)" + jversion;
624 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
628 if (
retval != ERROR_SUCCESS)
629 error (
"unable to find Java Runtime Environment: %s::%s",
630 key.c_str (), value.c_str ());
633 = regval.
xstring_value (R
"(initialize_jvm: registry value "%s" at )"
634 R"("%s" must be a string)",
635 value.c_str (), key.c_str ());
637 if (jvm_lib_path.empty ())
638 error (
"unable to find Java Runtime Environment: %s::%s",
639 key.c_str (), value.c_str ());
679 const char *static_locale = setlocale (LC_ALL,
nullptr);
682 locale = std::string (static_locale);
685 std::string jvm_lib_path;
689 (lib.
search (
"JNI_CreateJavaVM"));
691 (lib.
search (
"JNI_GetCreatedJavaVMs"));
693 if (create_vm && get_vm)
694 jvm_lib_path =
"linked in or loaded libraries";
699 if (! java_home_env.empty ())
705 if (jvm_lib_path.empty ())
709 # if defined (__APPLE__)
711 if (jvm_lib_path.empty ())
714 if (libexec_java_home_exists)
719 std::string java_home_cmd = std::string (JAVA_HOME_CMD)
720 +
" --failfast --version 1.6+ 2>/dev/null";
728 std::string found_path = output.substr (0, output.length() - 1);
730 if (!jvm_lib_found.empty ())
731 jvm_lib_path = jvm_lib_found;
737 if (jvm_lib_path.empty ())
739 #if defined (OCTAVE_USE_WINDOWS_API)
740 jvm_lib_path = get_jvm_lib_path_from_registry ();
750 error (
"unable to load Java Runtime Environment from %s",
751 jvm_lib_path.c_str ());
754 (lib.
search (
"JNI_CreateJavaVM"));
756 (lib.
search (
"JNI_GetCreatedJavaVMs"));
759 error (
"unable to find JNI_CreateJavaVM in %s", jvm_lib_path.c_str ());
762 error (
"unable to find JNI_GetCreatedJavaVMs in %s",
763 jvm_lib_path.c_str ());
769 if (get_vm (&
jvm, 1, &nVMs) == 0 && nVMs > 0)
773 switch (
jvm->GetEnv (
reinterpret_cast<void **
> (¤t_env),
778 JavaVMAttachArgs vm_args;
779 vm_args.version = JNI_VERSION_1_6;
780 vm_args.name =
const_cast<char *
> (
"octave");
781 vm_args.group =
nullptr;
782 if (
jvm->AttachCurrentThread (
reinterpret_cast<void **
> (¤t_env),
784 error (
"JVM internal error, unable to attach octave to existing JVM");
788 error (
"JVM internal error, the required JNI version is not supported");
806 #if defined (HAVE_BROKEN_PTHREAD_STACKSIZE)
807 vm_args.
add (
"-Djdk.lang.processReaperUseDefaultStackSize=true");
809 vm_args.
add (
"-Xrs");
816 if (create_vm (&
jvm, ¤t_env, vm_args.
to_args ()) != JNI_OK)
817 error (
"unable to start Java VM in %s", jvm_lib_path.c_str ());
822 setlocale (LC_ALL, locale.c_str ());
840 jvm->DetachCurrentThread ();
842 jvm->DestroyJavaVM ();
863 const char *cstr = jni_env->GetStringUTFChars (s,
nullptr);
865 jni_env->ReleaseStringUTFChars (s, cstr);
878 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
881 if (jni_env->IsInstanceOf (obj, cls))
883 reinterpret_cast<jstring
> (obj));
896 static inline JNIEnv *
899 JNIEnv *env =
nullptr;
902 jvm->GetEnv (
reinterpret_cast<void **
> (&env), JNI_VERSION_1_6);
912 #if defined (HAVE_JAVA)
918 jclass_ref cls (current_env, current_env->FindClass (
"java/lang/String"));
937 #if defined (HAVE_JAVA)
941 std::string cls_cpp = cls_name;
942 std::replace (cls_cpp.begin (), cls_cpp.end (),
'.',
'/');
946 jclass_ref cls (current_env, current_env->FindClass (cls_cpp.c_str ()));
947 if (current_env->ExceptionCheck ())
948 current_env->ExceptionClear ();
956 octave_unused_parameter (cls_name);
966 #if defined (HAVE_JAVA)
978 jni_env->ExceptionDescribe ();
980 jni_env->ExceptionClear ();
982 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
983 jmethodID mID = jni_env->GetMethodID (jcls,
"toString",
984 "()Ljava/lang/String;");
986 reinterpret_cast<jstring
> (jni_env->CallObjectMethod (ex,
990 error (
"[java] %s", msg.c_str ());
1001 static std::string class_loader;
1002 static jclass uiClass =
nullptr;
1004 jclass jcls = jni_env->FindClass (
name);
1006 if (jcls ==
nullptr)
1008 jni_env->ExceptionClear ();
1012 if (class_loader.empty ())
1015 jni_env->FindClass (
"java/lang/System"));
1016 jmethodID mID = jni_env->GetStaticMethodID
1019 "(Ljava/lang/String;)Ljava/lang/String;");
1021 jni_env->NewStringUTF (
"octave.class.loader"));
1022 js =
reinterpret_cast<jstring
> (jni_env->CallStaticObjectMethod
1023 (syscls, mID, jstring (js)));
1025 std::replace (class_loader.begin (), class_loader.end (),
1030 jni_env->FindClass (class_loader.c_str ()));
1034 jni_env->ExceptionClear ();
1037 std::replace (class_loader.begin (), class_loader.end (),
1040 jni_env->FindClass (
"org/openide/util/Lookup"));
1041 jmethodID mID = jni_env->GetStaticMethodID
1042 (jcls2,
"getDefault",
"()Lorg/openide/util/Lookup;");
1044 jni_env->CallStaticObjectMethod (jcls2, mID));
1045 mID = jni_env->GetMethodID (jcls2,
"lookup",
1046 "(Ljava/lang/Class;)Ljava/lang/Object;");
1048 jni_env->FindClass (
"java/lang/ClassLoader"));
1050 jni_env->CallObjectMethod
1051 (lObj, mID, jclass (cLoaderCls)));
1052 mID = jni_env->GetMethodID (cLoaderCls,
"loadClass",
1053 "(Ljava/lang/String;)Ljava/lang/Class;");
1055 jni_env->NewStringUTF (class_loader.c_str ()));
1056 uicls =
reinterpret_cast<jclass
>
1057 (jni_env->CallObjectMethod (cLoader, mID, jstring (js)));
1061 uiClass =
reinterpret_cast<jclass
>
1062 (jni_env->NewGlobalRef (jclass (uicls)));
1067 jmethodID mID = jni_env->GetStaticMethodID
1068 (uiClass,
"findClass",
"(Ljava/lang/String;)Ljava/lang/Class;");
1070 jcls =
reinterpret_cast<jclass
>
1071 (jni_env->CallStaticObjectMethod (uiClass, mID, jstring (js)));
1082 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
1083 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
1084 jmethodID isArray_ID = jni_env->GetMethodID (ccls,
"isArray",
"()Z");
1085 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls,
1087 "()Ljava/lang/Class;");
1093 while (jcls && jni_env->CallBooleanMethod (jcls, isArray_ID))
1095 int len = (jobj ? jni_env->GetArrayLength (jobj) : 0);
1096 if (idx >= dv.
ndims ())
1099 jcls =
reinterpret_cast<jclass
>
1100 (jni_env->CallObjectMethod (jcls, getComponentType_ID));
1102 ?
reinterpret_cast<jobjectArray
> (jni_env->GetObjectArrayElement (jobj,
1116 jclass_ref ocls (jni_env, jni_env->FindClass (
"[I"));
1117 jobjectArray
retval = jni_env->NewObjectArray (idx.
length (), ocls,
nullptr);
1121 for (
int i = 0; i < idx.
length (); i++)
1127 jint *buf = jni_env->GetIntArrayElements (i_array,
nullptr);
1131 for (
int k = 0; k < v.
length (); k++)
1135 jni_env->ReleaseIntArrayElements (i_array, buf, 0);
1136 jni_env->SetObjectArrayElement (
retval, i, i_array);
1160 "org/octave/ClassHelper"));
1161 jmethodID mID = jni_env
1162 ->GetStaticMethodID (helperClass,
"arraySubsref",
1163 "(Ljava/lang/Object;[[I)Ljava/lang/Object;");
1164 resObj = jni_env->CallStaticObjectMethod
1165 (helperClass, mID, jobj, jobject (java_idx));
1178 set_array_elements (JNIEnv *jni_env, jobject jobj,
1188 if (
unbox (jni_env, rhs, rhsObj, rhsCls))
1192 "org/octave/ClassHelper"));
1193 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"arraySubsasgn",
1194 "(Ljava/lang/Object;[[ILjava/lang/Object;)" "Ljava/lang/Object;");
1195 resObj = jni_env->CallStaticObjectMethod
1196 (helperClass, mID, jobj, jobject (java_idx), jobject (rhsObj));
1210 get_invoke_list (JNIEnv *jni_env,
void *jobj_arg)
1214 std::list<std::string> name_list;
1218 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
1219 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
1220 jmethodID getMethods_ID = jni_env->GetMethodID
1221 (ccls,
"getMethods",
"()[Ljava/lang/reflect/Method;");
1222 jmethodID getFields_ID = jni_env->GetMethodID
1223 (ccls,
"getFields",
"()[Ljava/lang/reflect/Field;");
1225 reinterpret_cast<jobjectArray
>
1226 (jni_env->CallObjectMethod (cls, getMethods_ID)));
1228 reinterpret_cast<jobjectArray
>
1229 (jni_env->CallObjectMethod (cls, getFields_ID)));
1230 int mLen = jni_env->GetArrayLength (mList);
1231 int fLen = jni_env->GetArrayLength (fList);
1233 jni_env->FindClass (
"java/lang/reflect/Method"));
1235 jni_env->FindClass (
"java/lang/reflect/Field"));
1236 jmethodID m_getName_ID = jni_env->GetMethodID (mCls,
"getName",
1237 "()Ljava/lang/String;");
1238 jmethodID f_getName_ID = jni_env->GetMethodID (fCls,
"getName",
1239 "()Ljava/lang/String;");
1241 for (
int i = 0; i < mLen; i++)
1243 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
1244 jstring_ref methName (jni_env,
reinterpret_cast<jstring
>
1245 (jni_env->CallObjectMethod (meth,
1250 for (
int i = 0; i < fLen; i++)
1253 jni_env->GetObjectArrayElement (fList, i));
1255 reinterpret_cast<jstring
>
1256 (jni_env->CallObjectMethod
1257 (field, f_getName_ID)));
1266 return v.sort (
true);
1270 convert_to_string (JNIEnv *jni_env, jobject java_object,
bool force,
char type)
1274 if (jni_env && java_object)
1276 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/String"));
1278 if (jni_env->IsInstanceOf (java_object, cls))
1282 cls = jni_env->FindClass (
"[Ljava/lang/String;");
1284 if (jni_env->IsInstanceOf (java_object, cls))
1286 jobjectArray array =
reinterpret_cast<jobjectArray
> (java_object);
1287 int len = jni_env->GetArrayLength (array);
1290 for (
int i = 0; i <
len; i++)
1293 reinterpret_cast<jstring
>
1294 (jni_env->GetObjectArrayElement (array, i)));
1306 cls = jni_env->FindClass (
"java/lang/Object");
1307 jmethodID mID = jni_env->GetMethodID (cls,
"toString",
1308 "()Ljava/lang/String;");
1310 reinterpret_cast<jstring
>
1311 (jni_env->CallObjectMethod (java_object,
1321 error (
"unable to convert Java object to string");
1329 #define TO_JAVA(obj) dynamic_cast<octave_java *> ((obj).internal_rep ())
1342 is_auto_convertible_number (JNIEnv *jni_env, jobject jobj)
1345 cls = jni_env->FindClass (
"java/lang/Double");
1346 if (jni_env->IsInstanceOf (jobj, cls))
1348 cls = jni_env->FindClass (
"java/lang/Float");
1349 if (jni_env->IsInstanceOf (jobj, cls))
1351 cls = jni_env->FindClass (
"java/lang/Byte");
1352 if (jni_env->IsInstanceOf (jobj, cls))
1354 cls = jni_env->FindClass (
"java/lang/Short");
1355 if (jni_env->IsInstanceOf (jobj, cls))
1357 cls = jni_env->FindClass (
"java/lang/Integer");
1358 if (jni_env->IsInstanceOf (jobj, cls))
1360 cls = jni_env->FindClass (
"java/lang/Long");
1361 if (jni_env->IsInstanceOf (jobj, cls))
1388 box (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg)
1400 while (
retval.is_undefined ())
1405 cls = jni_env->FindClass (
"java/lang/Number");
1406 if (jni_env->IsInstanceOf (jobj, cls)
1407 && is_auto_convertible_number (jni_env, jobj))
1409 jmethodID
m = jni_env->GetMethodID (cls,
"doubleValue",
"()D");
1410 retval = jni_env->CallDoubleMethod (jobj,
m);
1414 cls = jni_env->FindClass (
"java/lang/Boolean");
1415 if (jni_env->IsInstanceOf (jobj, cls))
1417 jmethodID
m = jni_env->GetMethodID (cls,
"booleanValue",
"()Z");
1418 retval = (jni_env->CallBooleanMethod (jobj,
m) ? true :
false);
1422 cls = jni_env->FindClass (
"java/lang/String");
1423 if (jni_env->IsInstanceOf (jobj, cls))
1429 cls = jni_env->FindClass (
"java/lang/Character");
1430 if (jni_env->IsInstanceOf (jobj, cls))
1432 jmethodID
m = jni_env->GetMethodID (cls,
"charValue",
"()C");
1433 retval = jni_env->CallCharMethod (jobj,
m);
1438 #define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID) \
1439 cls = jni_env->FindClass (JAVA_ID); \
1440 if (jni_env->IsInstanceOf (jobj, cls)) \
1442 const JAVA_TYPE ## Array jarr = reinterpret_cast<JAVA_TYPE ## Array> (jobj); \
1443 const jsize len = jni_env->GetArrayLength (jarr); \
1444 OCTAVE_ID ## NDArray d (dim_vector (len, 1)); \
1445 JAVA_TYPE *buffer = reinterpret_cast<JAVA_TYPE *> (d.fortran_vec ()); \
1446 jni_env->Get ## JAVA_TYPE_CAP ## ArrayRegion (jarr, 0, len, buffer); \
1460 #undef BOX_PRIMITIVE_ARRAY
1466 if (jni_env->IsInstanceOf (jobj, cls))
1468 jmethodID mID = jni_env->GetMethodID (cls,
"getDims",
"()[I");
1470 reinterpret_cast<jintArray
>
1471 (jni_env->CallObjectMethod (jobj, mID)));
1472 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv),
1475 dims.
resize (jni_env->GetArrayLength (jintArray (iv)));
1477 for (
int i = 0; i < dims.
ndims (); i++)
1478 dims(i) = iv_data[i];
1480 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1481 mID = jni_env->GetMethodID (cls,
"getClassName",
1482 "()Ljava/lang/String;");
1484 reinterpret_cast<jstring
>
1485 (jni_env->CallObjectMethod (jobj, mID)));
1492 mID = jni_env->GetMethodID (cls,
"toDouble",
"()[D");
1494 reinterpret_cast<jdoubleArray
>
1495 (jni_env->CallObjectMethod (jobj,
1497 jni_env->GetDoubleArrayRegion (dv, 0,
m.numel (),
1502 else if (s ==
"byte")
1507 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1509 reinterpret_cast<jbyteArray
>
1510 (jni_env->CallObjectMethod (jobj,
1512 jni_env->GetByteArrayRegion (dv, 0,
m.numel (),
1513 reinterpret_cast<jbyte *
>
1514 (
m.fortran_vec ()));
1521 mID = jni_env->GetMethodID (cls,
"toByte",
"()[B");
1523 reinterpret_cast<jbyteArray
>
1524 (jni_env->CallObjectMethod (jobj,
1526 jni_env->GetByteArrayRegion (dv, 0,
m.numel (),
1527 reinterpret_cast<jbyte *
>
1528 (
m.fortran_vec ()));
1533 else if (s ==
"integer")
1538 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1540 reinterpret_cast<jintArray
>
1541 (jni_env->CallObjectMethod (jobj,
1543 jni_env->GetIntArrayRegion (dv, 0,
m.numel (),
1544 reinterpret_cast<jint *
>
1545 (
m.fortran_vec ()));
1552 mID = jni_env->GetMethodID (cls,
"toInt",
"()[I");
1554 reinterpret_cast<jintArray
>
1555 (jni_env->CallObjectMethod (jobj,
1557 jni_env->GetIntArrayRegion (dv, 0,
m.numel (),
1558 reinterpret_cast<jint *
>
1559 (
m.fortran_vec ()));
1568 if (jni_env->IsInstanceOf (jobj, cls))
1570 jmethodID mID = jni_env->GetMethodID (cls,
"getID",
"()I");
1571 int ID = jni_env->CallIntMethod (jobj, mID);
1588 box_more (JNIEnv *jni_env,
void *jobj_arg,
void *jcls_arg)
1601 if (
retval.is_undefined ())
1603 cls = jni_env->FindClass (
"[D");
1605 if (jni_env->IsInstanceOf (jobj, cls))
1607 jdoubleArray jarr =
reinterpret_cast<jdoubleArray
> (jobj);
1608 int len = jni_env->GetArrayLength (jarr);
1613 jni_env->GetDoubleArrayRegion (jarr, 0,
len,
1622 if (
retval.is_undefined ())
1624 cls = jni_env->FindClass (
"[[D");
1626 if (jni_env->IsInstanceOf (jobj, cls))
1628 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1629 int rows = jni_env->GetArrayLength (jarr);
1636 for (
int r = 0;
r < rows;
r++)
1639 reinterpret_cast<jdoubleArray
>
1640 (jni_env->GetObjectArrayElement
1645 cols = jni_env->GetArrayLength (row);
1646 m.resize (cols, rows);
1648 jni_env->GetDoubleArrayRegion
1649 (row, 0, cols,
m.fortran_vec () +
r * cols);
1658 if (
retval.is_undefined ())
1660 cls = jni_env->FindClass (
"[Ljava/lang/String;");
1662 if (jni_env->IsInstanceOf (jobj, cls))
1664 jobjectArray jarr =
reinterpret_cast<jobjectArray
> (jobj);
1665 int len = jni_env->GetArrayLength (jarr);
1668 for (
int i = 0; i <
len; i++)
1671 reinterpret_cast<jstring
>
1672 (jni_env->GetObjectArrayElement (jarr, i)));
1681 if (
retval.is_undefined ())
1700 jcls = jni_env->GetObjectClass (jobj);
1706 jobj = jni_env->NewStringUTF (s.c_str ());
1707 jcls = jni_env->GetObjectClass (jobj);
1714 jclass_ref scls (jni_env, jni_env->FindClass (
"java/lang/String"));
1715 jobjectArray array = jni_env->NewObjectArray (
n, scls,
nullptr);
1720 (str_arr(i).c_str ()));
1721 jni_env->SetObjectArrayElement (array, i, jstr);
1725 jcls = jni_env->GetObjectClass (jobj);
1732 #define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP) \
1735 const OCTAVE_T ## NDArray v = val.METHOD_T ## array_value (); \
1736 JAVA_T ## Array jarr = jni_env->New ## JAVA_T_CAP ## Array (v.numel ()); \
1737 const JAVA_T *jv = reinterpret_cast<const JAVA_T *> (v.data ()); \
1738 jni_env->Set ## JAVA_T_CAP ## ArrayRegion (jarr, 0, v.numel (), jv); \
1739 jobj = reinterpret_cast<jobject> (jarr); \
1740 jcls = jni_env->GetObjectClass (jobj); \
1770 #undef UNBOX_PRIMITIVE_ARRAY
1777 #define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON) \
1780 const OCTAVE_T ov = val.METHOD_T ## _value (); \
1781 jclass_ref dcls (jni_env, jni_env->FindClass (JAVA_T)); \
1782 const jfieldID fid = jni_env->GetStaticFieldID (dcls, "TYPE", "Ljava/lang/Class;"); \
1783 const jmethodID mid = jni_env->GetMethodID (dcls, "<init>", JAVA_CON); \
1784 jcls = reinterpret_cast<jclass> (jni_env->GetStaticObjectField (dcls, fid)); \
1785 jobj = jni_env->NewObject (dcls, mid, ov); \
1812 #undef UNBOX_PRIMITIVE_SCALAR
1826 jdoubleArray dv = jni_env->NewDoubleArray (
m.numel ());
1827 jni_env->SetDoubleArrayRegion (dv, 0,
m.numel (),
m.fortran_vec ());
1829 jcls = jni_env->GetObjectClass (jobj);
1836 "org/octave/Matrix"));
1839 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv),
nullptr);
1841 for (
int i = 0; i < dims.
ndims (); i++)
1842 iv_data[i] = dims(i);
1844 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
1850 jni_env->SetDoubleArrayRegion (jdoubleArray (dv), 0,
m.numel (),
1852 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([D[I)V");
1853 jobj = jni_env->NewObject (jclass (mcls), mID, jdoubleArray (dv),
1855 jcls = jni_env->GetObjectClass (jobj);
1861 jni_env->SetByteArrayRegion (jbyteArray (bv), 0,
m.numel (),
1862 reinterpret_cast<jbyte *
>
1863 (
m.fortran_vec ()));
1864 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1865 jobj = jni_env->NewObject
1866 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1867 jcls = jni_env->GetObjectClass (jobj);
1873 jni_env->SetByteArrayRegion (jbyteArray (bv), 0,
m.numel (),
1874 reinterpret_cast<jbyte *
>
1875 (
m.fortran_vec ()));
1876 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([B[I)V");
1877 jobj = jni_env->NewObject
1878 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
1879 jcls = jni_env->GetObjectClass (jobj);
1885 jni_env->SetIntArrayRegion (jintArray (v), 0,
m.numel (),
1886 reinterpret_cast<jint *
>
1887 (
m.fortran_vec ()));
1888 jmethodID mID = jni_env->GetMethodID (mcls,
"<init>",
"([I[I)V");
1889 jobj = jni_env->NewObject
1890 (jclass (mcls), mID, jintArray (v), jintArray (iv));
1891 jcls = jni_env->GetObjectClass (jobj);
1895 error (
"cannot convert matrix of type '%s'",
1902 jmethodID mID = jni_env->GetMethodID (rcls,
"<init>",
"(I)V");
1905 jobj = jni_env->NewObject (rcls, mID, ID);
1919 jclass_ref ocls (jni_env, jni_env->FindClass (
"java/lang/Object"));
1920 jclass_ref ccls (jni_env, jni_env->FindClass (
"java/lang/Class"));
1923 jobjs = jni_env->NewObjectArray (args.
length (), ocls,
nullptr);
1926 jclss = jni_env->NewObjectArray (args.
length (), ccls,
nullptr);
1928 for (
int i = 0; i < args.
length (); i++)
1933 found =
unbox (jni_env, args(i), jobj, jcls);
1937 jni_env->SetObjectArrayElement (jobjs, i, jobj);
1938 jni_env->SetObjectArrayElement (jclss, i, jcls);
1952 get_current_thread_ID (JNIEnv *jni_env)
1957 jclass_ref cls (jni_env, jni_env->FindClass (
"java/lang/Thread"));
1958 jmethodID mID = jni_env->GetStaticMethodID (cls,
"currentThread",
1959 "()Ljava/lang/Thread;");
1960 jobject_ref jthread (jni_env, jni_env->CallStaticObjectMethod (cls, mID));
1965 jclass_ref jth_cls (jni_env, jni_env->GetObjectClass (jthread));
1966 mID = jni_env->GetMethodID (jth_cls,
"getId",
"()J");
1967 long result = jni_env->CallLongMethod (jthread, mID);
1980 java_event_hook (
void)
1988 "org/octave/Octave"));
1989 jmethodID mID = current_env->GetStaticMethodID
1990 (cls,
"checkPendingAction",
"()V");
1991 current_env->CallStaticVoidMethod (cls, mID);
2007 initialize_java (
void)
2021 catch (std::string msg)
2023 error (
"%s", msg.c_str ());
2030 JNIEXPORT jboolean JNICALL
2032 jobjectArray argin, jobjectArray argout)
2036 int nargout = env->GetArrayLength (argout);
2037 int nargin = env->GetArrayLength (argin);
2041 for (
int i = 0; i < nargin; i++)
2042 varargin(i) =
box (env, env->GetObjectArrayElement (argin, i),
nullptr);
2048 return unbox (env, varargout, out_objs, out_clss);
2051 JNIEXPORT
void JNICALL
2057 JNIEXPORT
void JNICALL
2066 int len = env->GetArrayLength (args);
2069 for (
int i = 0; i <
len; i++)
2071 jobject_ref jobj (env, env->GetObjectArrayElement (args, i));
2072 oct_args(i) =
box (env, jobj,
nullptr);
2082 && val.
cell_value()(0).is_function_handle ())
2087 for (
int i=1; i<c.
numel (); i++)
2088 oct_args(
len+i-1) = c(i);
2093 error (
"trying to invoke non-invocable object");
2097 JNIEXPORT
void JNICALL
2108 JNIEXPORT jboolean JNICALL
2121 #if ! defined (HAVE_JAVA)
2131 #if defined (HAVE_JAVA)
2137 octave_unused_parameter (jobj);
2138 octave_unused_parameter (jcls);
2152 #if defined (HAVE_JAVA)
2159 octave_unused_parameter (ti);
2167 #if defined (HAVE_JAVA)
2188 const std::list<octave_value_list>& idx,
int nargout)
2190 #if defined (HAVE_JAVA)
2200 if (
type.length () > 1 &&
type[1] ==
'(')
2205 ovl(0) = (idx.front ())(0);
2206 auto it = idx.begin ();
2216 ovl(1) = (idx.front ())(0);
2228 error (
"subsref: Java object cannot be indexed with %c",
type[0]);
2232 if (idx.size () > 1 &&
type.length () > 1)
2239 octave_unused_parameter (
type);
2240 octave_unused_parameter (idx);
2241 octave_unused_parameter (nargout);
2253 const std::list<octave_value_list>& idx,
2256 #if defined (HAVE_JAVA)
2265 if (
type.length () == 1)
2271 ovl(1) = (idx.front ())(0);
2273 F__java_set__ (
ovl);
2278 else if (
type.length () > 2 &&
type[1] ==
'(')
2280 std::list<octave_value_list> new_idx;
2281 auto it = idx.begin ();
2282 new_idx.push_back (*it++);
2283 new_idx.push_back (*it++);
2286 std::list<octave_value_list> next_idx (idx);
2287 next_idx.erase (next_idx.begin ());
2288 next_idx.erase (next_idx.begin ());
2289 u(0).subsasgn (
type.substr (2), next_idx, rhs);
2294 else if (
type[1] ==
'.')
2298 std::list<octave_value_list> next_idx (idx);
2299 next_idx.erase (next_idx.begin ());
2300 u(0).subsasgn (
type.substr (1), next_idx, rhs);
2306 error (
"invalid indexing/assignment on Java object");
2321 error (
"Java object cannot be indexed with %c",
type[0]);
2329 octave_unused_parameter (
type);
2330 octave_unused_parameter (idx);
2331 octave_unused_parameter (rhs);
2344 #if defined (HAVE_JAVA)
2349 return get_invoke_list (current_env,
to_java ());
2366 #if defined (HAVE_JAVA)
2377 octave_unused_parameter (force);
2378 octave_unused_parameter (
type);
2398 os <<
"<Java object: " << java_classname << '>
';
2401 // FIXME: Need routines to actually save/load java objects through Serialize.
2405 octave_java::save_ascii (std::ostream& /* os */)
2407 warning ("save: unable to save java objects, skipping");
2413 octave_java::load_ascii (std::istream& /* is */)
2415 // Silently skip over java object that was not saved
2420 octave_java::save_binary (std::ostream& /* os */, bool /* save_as_floats */)
2422 warning ("save: unable to save java objects, skipping");
2428 octave_java::load_binary (std::istream& /* is */, bool /* swap*/,
2429 octave::mach_info::float_format /* fmt */)
2431 // Silently skip over java object that was not saved
2436 octave_java::save_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */,
2437 bool /* save_as_floats */)
2439 warning ("save: unable to save java objects, skipping");
2445 octave_java::load_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */)
2447 // Silently skip object that was not saved
2452 octave_java::do_javaMethod (void *jni_env_arg, const std::string& name,
2453 const octave_value_list& args)
2455 #if defined (HAVE_JAVA)
2457 octave_value retval;
2459 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
2463 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
2464 if (unbox (jni_env, args, arg_objs, arg_types))
2466 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
2467 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeMethod",
2468 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2469 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
2470 jobjectArray_ref resObj (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
2471 to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
2473 retval = box (jni_env, resObj);
2475 retval = check_exception (jni_env);
2478 octave_set_default_fpucw ();
2485 octave_unused_parameter (jni_env_arg);
2486 octave_unused_parameter (name);
2487 octave_unused_parameter (args);
2489 // This shouldn't happen because construction of
octave_java objects is
2501 #if defined (HAVE_JAVA)
2507 octave_unused_parameter (
name);
2508 octave_unused_parameter (args);
2520 const std::string& class_name,
2521 const std::string&
name,
2524 #if defined (HAVE_JAVA)
2528 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2533 if (
unbox (jni_env, args, arg_objs, arg_types))
2537 "org/octave/ClassHelper"));
2538 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2539 "invokeStaticMethod",
2540 "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2542 jni_env->NewStringUTF (
name.c_str ()));
2544 jni_env->NewStringUTF (
class_name.c_str ()));
2546 jni_env->CallStaticObjectMethod (helperClass,
2550 jobjectArray (arg_objs),
2551 jobjectArray (arg_types)));
2565 octave_unused_parameter (jni_env_arg);
2567 octave_unused_parameter (
name);
2568 octave_unused_parameter (args);
2580 const std::string&
name,
2583 #if defined (HAVE_JAVA)
2590 octave_unused_parameter (
name);
2591 octave_unused_parameter (args);
2605 #if defined (HAVE_JAVA)
2609 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2615 if (
unbox (jni_env, args, arg_objs, arg_types))
2619 "org/octave/ClassHelper"));
2620 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2621 "invokeConstructor",
2622 "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
2624 jni_env->NewStringUTF (
name.c_str ()));
2626 jni_env->CallStaticObjectMethod (helperClass,
2629 jobjectArray (arg_objs),
2630 jobjectArray (arg_types)));
2645 octave_unused_parameter (jni_env_arg);
2646 octave_unused_parameter (
name);
2647 octave_unused_parameter (args);
2661 #if defined (HAVE_JAVA)
2667 octave_unused_parameter (
name);
2668 octave_unused_parameter (args);
2681 #if defined (HAVE_JAVA)
2685 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2691 "org/octave/ClassHelper"));
2692 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"getField",
2693 "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
2696 jni_env->CallStaticObjectMethod (helperClass,
2713 octave_unused_parameter (jni_env_arg);
2714 octave_unused_parameter (
name);
2727 #if defined (HAVE_JAVA)
2733 octave_unused_parameter (
name);
2745 const std::string&
name)
2747 #if defined (HAVE_JAVA)
2751 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2757 "org/octave/ClassHelper"));
2758 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2760 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
2764 jni_env->CallStaticObjectMethod (helperClass, mID,
2779 octave_unused_parameter (jni_env_arg);
2781 octave_unused_parameter (
name);
2793 const std::string&
name)
2795 #if defined (HAVE_JAVA)
2802 octave_unused_parameter (
name);
2816 #if defined (HAVE_JAVA)
2820 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2827 if (
unbox (jni_env, val, jobj, jcls))
2831 "org/octave/ClassHelper"));
2832 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
"setField",
2833 "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
2835 jni_env->CallStaticObjectMethod (helperClass, mID,
to_java (),
2836 jstring (fName), jobject (jobj));
2847 octave_unused_parameter (jni_env_arg);
2848 octave_unused_parameter (
name);
2849 octave_unused_parameter (val);
2862 #if defined (HAVE_JAVA)
2868 octave_unused_parameter (
name);
2869 octave_unused_parameter (val);
2883 #if defined (HAVE_JAVA)
2887 JNIEnv *jni_env =
TO_JNIENV (jni_env_arg);
2894 if (
unbox (jni_env, val, jobj, jcls))
2898 "org/octave/ClassHelper"));
2899 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
2901 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
2903 jni_env->NewStringUTF (
class_name.c_str ()));
2905 jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName),
2906 jstring (fName), jobject (jobj));
2917 octave_unused_parameter (jni_env_arg);
2919 octave_unused_parameter (
name);
2920 octave_unused_parameter (val);
2932 const std::string&
name,
2935 #if defined (HAVE_JAVA)
2942 octave_unused_parameter (
name);
2943 octave_unused_parameter (val);
2956 #if defined (HAVE_JAVA)
2969 java_class = current_env->NewGlobalRef (jcls);
2974 java_class = current_env->NewGlobalRef (jclass (ocls));
2981 jmethodID mID = current_env->GetMethodID (clsCls,
2983 "()Ljava/lang/String;");
2992 octave_unused_parameter (jobj_arg);
2993 octave_unused_parameter (jcls_arg);
3006 #if defined (HAVE_JAVA)
3035 DEFUN (__java_init__, , ,
3043 #if defined (HAVE_JAVA)
3060 DEFUN (__java_exit__, , ,
3069 #if defined (HAVE_JAVA)
3082 DEFUN (javaObject, args, ,
3102 #if defined (HAVE_JAVA)
3107 std::string classname = args(0).xstring_value (
"javaObject: CLASSNAME must be a string");
3114 for (
int i=1; i<args.
length (); i++)
3121 octave_unused_parameter (args);
3137 DEFUN (javaMethod, args, ,
3163 #if defined (HAVE_JAVA)
3168 std::string methodname = args(0).xstring_value (
"javaMethod: METHODNAME must be a string");
3177 for (
int i=2; i<args.
length (); i++)
3180 if (args(1).isjava ())
3185 else if (args(1).is_string ())
3187 std::string cls = args(1).string_value ();
3191 error (
"javaMethod: OBJ must be a Java object or a string");
3197 octave_unused_parameter (args);
3216 DEFUN (__java_get__, args, ,
3238 #if defined (HAVE_JAVA)
3243 std::string
name = args(1).xstring_value (
"__java_get__: NAME must be a string");
3251 if (args(0).isjava ())
3256 else if (args(0).is_string ())
3258 std::string cls = args(0).string_value ();
3262 error (
"__java_get__: OBJ must be a Java object or a string");
3268 octave_unused_parameter (args);
3275 DEFUN (__java_set__, args, ,
3298 #if defined (HAVE_JAVA)
3303 std::string
name = args(1).xstring_value (
"__java_set__: NAME must be a string");
3311 if (args(0).isjava ())
3316 else if (args(0).is_string ())
3318 std::string cls = args(0).string_value ();
3322 error (
"__java_set__: OBJ must be a Java object or a string");
3328 octave_unused_parameter (args);
3335 DEFUN (__java2mat__, args, ,
3341 #if defined (HAVE_JAVA)
3352 if (args(0).isjava ())
3364 octave_unused_parameter (args);
3371 DEFUN (java_matrix_autoconversion, args, nargout,
3387 #if defined (HAVE_JAVA)
3393 octave_unused_parameter (args);
3394 octave_unused_parameter (nargout);
3401 DEFUN (java_unsigned_autoconversion, args, nargout,
3418 #if defined (HAVE_JAVA)
3424 octave_unused_parameter (args);
3425 octave_unused_parameter (nargout);
3432 DEFUN (debug_java, args, nargout,
3447 #if defined (HAVE_JAVA)
3453 octave_unused_parameter (args);
3454 octave_unused_parameter (nargout);
3465 DEFUN (isjava, args, ,
3475 return ovl (args(0).isjava ());
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
void resize(int n, int fill_value=0)
bool isvector(void) const
octave_idx_type ndims(void) const
Number of dimensions.
octave_idx_type length(octave_idx_type n=0) const
java_local_ref(JNIEnv *_env, T obj)
java_local_ref(JNIEnv *_env)
void add(const std::string &opt)
JavaVMInitArgs * to_args()
void read_java_opts(const std::string &filename)
std::list< std::string > java_opts
static void add_event_hook(event_hook_fcn f)
static std::string path_sep_str(void)
std::list< std::string > close(void)
void * search(const std::string &nm, const name_mangler &mangler=name_mangler()) const
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
int exit_status(void) const
std::string stdout_output(void) const
static std::string getenv(const std::string &name)
static std::string get_home_directory(void)
static std::string get_current_directory(void)
int register_type(const std::string &, const std::string &, const octave_value &, bool abort_on_duplicate=false)
octave::refcount< octave_idx_type > count
void newline(std::ostream &os) const
static void register_type(void)
friend class octave_value
static const std::string t_name
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value do_java_set(void *jni_env, const std::string &name, const octave_value &val)
void print(std::ostream &os, bool pr_as_read_syntax=false)
void * to_java(void) const
octave_value do_javaMethod(void *jni_env, const std::string &name, const octave_value_list &args)
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_value do_java_get(void *jni_env, const std::string &name)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool is_instance_of(const std::string &) const
bool is_java_string(void) const
std::string java_classname
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void init(void *jobj, void *jcls)
static octave_value do_javaObject(void *jni_env, const std::string &name, const octave_value_list &args)
std::string class_name(void) const
dim_vector dims(void) const
string_vector map_keys(void) const
octave_value_list & append(const octave_value &val)
octave_idx_type length(void) const
octave_idx_type length(void) const
int32NDArray int32_array_value(void) const
bool iscellstr(void) const
bool is_uint16_type(void) const
bool is_bool_scalar(void) const
bool is_int8_type(void) const
octave_idx_type rows(void) const
octave_idx_type numel(void) const
bool is_string(void) const
bool is_double_type(void) const
Cell cell_value(void) const
bool is_function_handle(void) const
std::string class_name(void) const
bool is_uint32_type(void) const
octave_idx_type columns(void) const
int8NDArray int8_array_value(void) const
bool is_int64_type(void) const
octave_function * function_value(bool silent=false) const
uint8NDArray uint8_array_value(void) const
std::string string_value(bool force=false) const
bool is_matrix_type(void) const
bool is_int32_type(void) const
bool is_uint64_type(void) const
bool is_int16_type(void) const
bool is_range(void) const
NDArray array_value(bool frc_str_conv=false) const
bool is_real_matrix(void) const
std::string xstring_value(const char *fmt,...) const
bool is_real_scalar(void) const
Array< std::string > cellstr_value(void) const
bool is_uint8_type(void) const
Matrix matrix_value(bool frc_str_conv=false) const
bool islogical(void) const
dim_vector dims(void) const
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
#define panic_impossible()
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
void octave_set_default_fpucw(void)
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Z
static char * strsave(const char *s)
std::string fcn_file_dir(void)
std::string dir_sep_str(void)
std::string tilde_expand(const std::string &name)
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
interpreter & __get_interpreter__(const std::string &who)
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
OCTINTERP_API process_execution_result run_command_and_return_output(const std::string &cmd_str)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
static octave_value get_array_elements(JNIEnv *jni_env, jobject jobj, const octave_value_list &idx)
static octave_value check_exception(JNIEnv *jni_env)
#define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID)
static std::map< int, octave_value > listener_map
static long octave_thread_ID
The thread id of the currently executing thread or -1 if this is unknown.
static std::string read_classpath_txt(const std::string &filepath)
Return the classpath in the given file filepath as a string.
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_call(JNIEnv *, jclass, jstring, jobjectArray, jobjectArray)
bool Vjava_unsigned_autoconversion
static std::string get_jvm_lib_path_in_subdir(std::string java_home_path)
java_local_ref< jthrowable > jthrowable_ref
#define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON)
static bool jvm_attached
Whether the current thread is attached to the jvm given by jvm.
JNIEXPORT jboolean JNICALL Java_org_octave_Octave_needThreadedInvokation(JNIEnv *, jclass)
static jobject make_java_index(JNIEnv *jni_env, const octave_value_list &idx)
static int octave_java_refcount
static std::string initial_java_dir(void)
The java initialization directory is given by the environment variable OCTAVE_JAVA_DIR if defined; ot...
static dim_vector compute_array_dimensions(JNIEnv *jni_env, jobject obj)
java_local_ref< jdoubleArray > jdoubleArray_ref
java_local_ref< jobjectArray > jobjectArray_ref
java_local_ref< jclass > jclass_ref
jint(JNICALL * JNI_CreateJavaVM_t)(JavaVM **pvm, JNIEnv **penv, void *args)
static octave::dynamic_library jvm_lib
Need to keep hold of the shared library handle until exit.
java_local_ref< jbyteArray > jbyteArray_ref
static std::map< int, octave_value > octave_ref_map
static void initialize_jvm(void)
Initialize the java virtual machine (jvm) and field jvm if necessary.
static jclass find_octave_class(JNIEnv *jni_env, const char *name)
JNIEXPORT void JNICALL Java_org_octave_Octave_doInvoke(JNIEnv *, jclass, jint, jobjectArray)
static bool unbox(JNIEnv *jni_env, const octave_value &val, jobject_ref &jobj, jclass_ref &jcls)
JNIEXPORT void JNICALL Java_org_octave_Octave_doEvalString(JNIEnv *, jclass, jstring)
java_local_ref< jobject > jobject_ref
bool Vjava_matrix_autoconversion
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)
#define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP)
JNIEXPORT void JNICALL Java_org_octave_OctaveReference_doFinalize(JNIEnv *, jclass, jint)
static JNIEnv * thread_jni_env(void)
}
java_local_ref< jstring > jstring_ref
static void terminate_jvm(void)
Terminate the current jvm, if there is any.
static std::string jstring_to_string(JNIEnv *jni_env, jstring s)
Converts a Java string object to std::string.
static JavaVM * jvm
The pointer to a java virtual machine either created in the current thread or attached this thread to...
java_local_ref< jintArray > jintArray_ref
static octave_value box_more(JNIEnv *jni_env, void *jobj_arg, void *jcls_arg=nullptr)
static std::string initial_class_path(void)
Return the initial classpath.
jint(JNICALL * JNI_GetCreatedJavaVMs_t)(JavaVM **pvm, jsize bufLen, jsize *nVMs)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
#define SET_INTERNAL_VARIABLE(NM)