ext/load.c in rjb-1.6.1 vs ext/load.c in rjb-1.6.2
- old
+ new
@@ -1,8 +1,8 @@
/*
* Rjb - Ruby <-> Java Bridge
- * Copyright(c) 2004,2005,2006,2009,2010,2011 arton
+ * Copyright(c) 2004,2005,2006,2009,2010,2011,2020 arton
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -36,13 +36,15 @@
#define ALT_JVM_TYPE "classic"
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(__CYGWIN__)
#define JVMDLL "%s/jre/bin/%s/jvm.dll"
+ #define OPENJDK_JVMDLL "%s/bin/%s/jvm.dll"
#define DIRSEPARATOR '/'
#else
#define JVMDLL "%s\\jre\\bin\\%s\\jvm.dll"
+ #define OPENJDK_JVMDLL "%s\\bin\\%s\\jvm.dll"
#define DIRSEPARATOR '\\'
#if defined(_WIN64)
#undef JVM_TYPE
#define JVM_TYPE "server"
#endif
@@ -59,10 +61,11 @@
#define ARCH "ppc"
#undef JVM_TYPE
#define JVM_TYPE "j9vm"
#elif defined(__hpux)
#define JVMDLL "%s/jre/lib/%s/%s/libjvm.sl"
+ #define OPENJDK_JVMDLL "%s/lib/%s/libjvm.sl"
#define ARCH "PA_RISC"
#undef JVM_TYPE
#define JVM_TYPE "server"
#define DIRSEPARATOR '/'
#define CLASSPATH_SEP ':'
@@ -86,10 +89,11 @@
#endif
#ifndef ARCH
#include <sys/systeminfo.h>
#endif
#define JVMDLL "%s/jre/lib/%s/%s/libjvm.so"
+ #define OPENJDK_JVMDLL "%s/lib/%s/libjvm.so"
#define DIRSEPARATOR '/'
#define CLASSPATH_SEP ':'
#endif
#if defined(__APPLE__) && defined(__MACH__)
@@ -121,25 +125,33 @@
int sstat;
VALUE* argv;
size_t i;
int state;
+ if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_str_new2(libpath)) == RUBY_Qfalse)
+ {
+ if (RTEST(ruby_verbose))
+ {
+ fprintf(stderr, "Rjb::load try to find but not exist %s\n", libpath);
+ }
+ return 0;
+ }
#if defined(RUBINIUS)
i = 1;
#else
i = 0;
#endif
- for (; i < COUNTOF(DLLibs); i++)
+ for (; i < COUNTOF(DLLibs); i++)
{
state = 0;
rb_protect(safe_require, rb_str_new2(DLLibs[i]), &state);
#if !defined(RUBINIUS)
if (state || !rb_const_defined_at(rb_cObject, rb_intern(DLNames[i])))
{
if (i > 0)
{
- rb_raise(rb_eRuntimeError, "Constants DL and Fiddle is not defined.");
+ rb_raise(rb_eRuntimeError, "Constants DL or Fiddle is not defined.");
return 0;
}
}
else
#endif
@@ -161,12 +173,12 @@
}
}
}
/* get function pointers of JNI */
#if RJB_RUBY_VERSION_CODE < 190
- getdefaultjavavminitargsfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(GETDEFAULTJVMINITARGS), rb_str_new2("IP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
- createjavavmfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(CREATEJVM), rb_str_new2("IPPP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
+ getdefaultjavavminitargsfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(GETDEFAULTJVMINITARGS), rb_str_new2("IP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
+ createjavavmfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(CREATEJVM), rb_str_new2("IPPP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
#else
getdefaultjavavminitargsfunc = rb_funcall(jvmdll, rb_intern("[]"), 1, rb_str_new2(GETDEFAULTJVMINITARGS));
createjavavmfunc = rb_funcall(jvmdll, rb_intern("[]"), 1, rb_str_new2(CREATEJVM));
#endif
return 1;
@@ -182,10 +194,11 @@
}
#endif
/*
* not completed, only valid under some circumstances.
+ * load priority: OpenJDK -> SunJDK
*/
static int load_jvm(const char* jvmtype)
{
char* libpath;
char* java_home;
@@ -234,30 +247,41 @@
char* p = ALLOCA_N(char, strlen(jh) + 1);
strcpy(p, jh + 1);
*(p + strlen(p) - 1) = '\0';
jh = p;
}
-#endif
+#endif
java_home = ALLOCA_N(char, strlen(jh) + 1);
strcpy(java_home, jh);
if (*(java_home + strlen(jh) - 1) == DIRSEPARATOR)
{
*(java_home + strlen(jh) - 1) = '\0';
}
+#if defined(__APPLE__) && defined(__MACH__)
+ libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home) + 1);
+ sprintf(libpath, JVMDLL, java_home);
+ return open_jvm(libpath);
+#else
#if defined(_WIN32) || defined(__CYGWIN__)
libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home)
+ strlen(jvmtype) + 1);
- sprintf(libpath, JVMDLL, java_home, jvmtype);
-#elif defined(__APPLE__) && defined(__MACH__)
- libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home) + 1);
- sprintf(libpath, JVMDLL, java_home);
#else /* not Windows / MAC OS-X */
libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home)
- + strlen(ARCH) + strlen(jvmtype) + 1);
+ + strlen(ARCH) + strlen(jvmtype) + 1);
+#endif
+ sprintf(libpath, OPENJDK_JVMDLL, java_home, jvmtype);
+ if (open_jvm(libpath))
+ {
+ return 1;
+ }
+#if defined(_WIN32) || defined(__CYGWIN__)
+ return 0;
+#else /* not Windows / MAC OS-X */
sprintf(libpath, JVMDLL, java_home, ARCH, jvmtype);
#endif
return open_jvm(libpath);
+#endif /* __APPLE__ and __MACH */
}
static int load_bridge(JNIEnv* jenv)
{
JNINativeMethod nmethod[1];
@@ -267,11 +291,11 @@
FILE* f;
#if defined(RUBINIUS)
VALUE v = rb_const_get(rb_cObject, rb_intern("RjbConf"));
v = rb_const_get(v, rb_intern("BRIDGE_FILE"));
#else
- VALUE v = rb_const_get_at(rb_const_get(rb_cObject, rb_intern("RjbConf")),
+ VALUE v = rb_const_get_at(rb_const_get(rb_cObject, rb_intern("RjbConf")),
rb_intern("BRIDGE_FILE"));
#endif
bridge = StringValuePtr(v);
#if defined(DOSISH)
bridge = ALLOCA_N(char, strlen(bridge) + 8);
@@ -350,11 +374,11 @@
char* p = ALLOCA_N(char, strlen(libjvm) + 1);
strcpy(p, libjvm + 1);
*(p + strlen(p) - 1) = '\0';
libjvm = p;
}
-#endif
+#endif
if (libjvm == NULL || !open_jvm(libjvm))
{
#if defined(__APPLE__) && defined(__MACH__)
if (!(load_jvm(NULL)))
{
@@ -368,10 +392,10 @@
}
#if defined(__APPLE__) && defined(__MACH__)
}
#endif
}
-
+
#if RJB_RUBY_VERSION_CODE < 190 && !defined(RUBINIUS)
ruby_errinfo = Qnil;
#else
rb_set_errinfo(Qnil);
#endif