return value; \
}
-static JNIEnv *GetJNI(JSContextRef context);
-
#define CYJavaForEachPrimitive \
CYJavaForEachPrimitive_(Z, z, Boolean, Boolean, boolean) \
CYJavaForEachPrimitive_(B, b, Byte, Byte, byte) \
struct CYJavaPackage :
CYPrivate<CYJavaPackage>
{
+ JNIEnv *jni_;
+
typedef std::vector<std::string> Path;
Path package_;
- _finline CYJavaPackage(const Path &package) :
+ _finline CYJavaPackage(JNIEnv *jni, const Path &package) :
+ jni_(jni),
package_(package)
{
}
name << package << '/';
name << next;
- JNIEnv *jni(GetJNI(context));
+ JNIEnv *jni(internal->jni_);
if (auto _class = jni->FindClass(name.str().c_str()))
return CYGetJavaClass(context, CYJavaLocal<jclass>(jni, _class));
jni->ExceptionClear();
package.push_back(next);
- return CYJavaPackage::Make(context, package);
+ return CYJavaPackage::Make(context, jni, package);
} CYCatch(NULL) }
static void Cycript_delete(JNIEnv *env, jclass api, jlong jprotect) { CYJavaTry {
jint CYJavaVersion(JNI_VERSION_1_4);
-static JNIEnv *CYGetCreatedJava(jint (*$JNI_GetCreatedJavaVMs)(JavaVM **, jsize, jsize *)) {
+static JavaVM *CYGetJavaVM(jint (*$JNI_GetCreatedJavaVMs)(JavaVM **, jsize, jsize *)) {
jsize capacity(16);
JavaVM *jvms[capacity];
jsize size;
_jnicall($JNI_GetCreatedJavaVMs(jvms, capacity, &size));
if (size == 0)
return NULL;
- JavaVM *jvm(jvms[0]);
- JNIEnv *jni;
- _jnicall(jvm->GetEnv(reinterpret_cast<void **>(&jni), CYJavaVersion));
- return jni;
+ return jvms[0];
}
-static JNIEnv *GetJNI_(JSContextRef context) {
- static JavaVM *jvm(NULL);
- static JNIEnv *jni(NULL);
-
- if (jni != NULL)
- return jni;
-
+static JavaVM *CYGetJavaVM(JSContextRef context) {
CYPool pool;
void *handle(RTLD_DEFAULT);
std::string library;
dlset($JNI_GetCreatedJavaVMs, "JNI_GetCreatedJavaVMs", handle);
if ($JNI_GetCreatedJavaVMs != NULL) {
- if (JNIEnv *jni = CYGetCreatedJava($JNI_GetCreatedJavaVMs))
- return jni;
+ if (JavaVM *jvm = CYGetJavaVM($JNI_GetCreatedJavaVMs))
+ return jvm;
} else {
std::vector<const char *> guesses;
guesses.push_back(android);
#endif
+ guesses.push_back("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib");
+ //guesses.push_back("/System/Library/Frameworks/JavaVM.framework/JavaVM");
+
guesses.push_back("libart.so");
guesses.push_back("libdvm.so");
guesses.push_back("libjvm.so");
}
}
- _assert(library.size() != 0);
+ if (library.size() == 0)
+ return NULL;
dlset($JNI_GetCreatedJavaVMs, "JNI_GetCreatedJavaVMs", handle);
- if (JNIEnv *jni = CYGetCreatedJava($JNI_GetCreatedJavaVMs))
- return jni;
+ if (JavaVM *jvm = CYGetJavaVM($JNI_GetCreatedJavaVMs))
+ return jvm;
}
std::vector<JavaVMOption> options;
JniInvocation$Init(invocation, NULL);
dlset($JNI_GetCreatedJavaVMs, "JNI_GetCreatedJavaVMs", libnativehelper);
- if (JNIEnv *jni = CYGetCreatedJava($JNI_GetCreatedJavaVMs))
- return jni;
+ if (JavaVM *jvm = CYGetJavaVM($JNI_GetCreatedJavaVMs))
+ return jvm;
}
}
+ JavaVM *jvm;
+ JNIEnv *env;
+
if (void *libandroid_runtime = dlopen("libandroid_runtime.so", RTLD_LAZY | RTLD_GLOBAL)) {
class AndroidRuntime$;
AndroidRuntime$ *(*AndroidRuntime$$init$)(AndroidRuntime$ *self, char *args, unsigned int size)(NULL);
- int (*AndroidRuntime$startVm)(AndroidRuntime$ *self, JavaVM **jvm, JNIEnv **jni)(NULL);
- int (*AndroidRuntime$startReg)(JNIEnv *jni)(NULL);
+ int (*AndroidRuntime$startVm)(AndroidRuntime$ *self, JavaVM **jvm, JNIEnv **env)(NULL);
+ int (*AndroidRuntime$startReg)(JNIEnv *env)(NULL);
int (*AndroidRuntime$addOption)(AndroidRuntime$ *self, const char *option, void *extra)(NULL);
int (*AndroidRuntime$addVmArguments)(AndroidRuntime$ *self, int, const char *const argv[])(NULL);
AndroidRuntime$ *(*AndroidRuntime$finalize)(AndroidRuntime$ *self)(NULL);
int failure;
_assert(AndroidRuntime$startVm != NULL);
- failure = AndroidRuntime$startVm(runtime, &jvm, &jni);
+ failure = AndroidRuntime$startVm(runtime, &jvm, &env);
_assert(failure == 0);
_assert(AndroidRuntime$startReg != NULL);
- failure = AndroidRuntime$startReg(jni);
+ failure = AndroidRuntime$startReg(env);
_assert(failure == 0);
- return jni;
+ return jvm;
}
jint (*$JNI_CreateJavaVM)(JavaVM **jvm, void **, void *);
args.version = CYJavaVersion;
args.nOptions = options.size();
args.options = options.data();
- _jnicall($JNI_CreateJavaVM(&jvm, reinterpret_cast<void **>(&jni), &args));
- return jni;
+ _jnicall($JNI_CreateJavaVM(&jvm, reinterpret_cast<void **>(&env), &args));
+ return jvm;
}
static JNIEnv *GetJNI(JSContextRef context) {
- CYJavaEnv jni(GetJNI_(context));
+ auto jvm(CYGetJavaVM(context));
+ if (jvm == NULL)
+ return NULL;
+
+ JNIEnv *env;
+ _jnicall(jvm->GetEnv(reinterpret_cast<void **>(&env), CYJavaVersion));
+ CYJavaEnv jni(env);
+
auto Cycript$(jni.FindClass("Cycript"));
jni.RegisterNatives(Cycript$, Cycript_, sizeof(Cycript_) / sizeof(Cycript_[0]));
- return jni;
+
+ return env;
}
static JSStaticValue JavaClass_staticValues[3] = {
}
void CYJava_SetupContext(JSContextRef context) {
+ JNIEnv *jni(GetJNI(context));
+ if (jni == NULL)
+ return;
+
JSObjectRef global(CYGetGlobalObject(context));
//JSObjectRef cy(CYCastJSObject(context, CYGetProperty(context, global, cy_s)));
JSObjectRef cycript(CYCastJSObject(context, CYGetProperty(context, global, CYJSString("Cycript"))));
JSObjectRef Java(JSObjectMake(context, NULL, NULL));
CYSetProperty(context, cycript, CYJSString("Java"), Java);
- JSObjectRef Packages(CYJavaPackage::Make(context, CYJavaPackage::Path()));
+ JSObjectRef Packages(CYJavaPackage::Make(context, jni, CYJavaPackage::Path()));
CYSetProperty(context, all, CYJSString("Packages"), Packages);
for (auto name : (const char *[]) {"java", "javax", "android", "com", "net", "org"}) {
# $(GPERF) $< >$@
@CY_JAVA_TRUE@am__append_13 = Java
@CY_JAVA_TRUE@am__append_14 = Java/Execute.cpp
-@CY_JAVA_TRUE@am__append_15 = $(LTJAVA)
-@CY_JAVA_TRUE@am__append_16 = libcycript.jar
-@CY_JAVA_TRUE@am__append_17 = Class libcycript.jar
-@CY_RUBY_TRUE@am__append_18 = Ruby
-@CY_RUBY_TRUE@am__append_19 = Ruby/Execute.cpp
-@CY_RUBY_TRUE@am__append_20 = $(LTRUBY)
-@CY_PYTHON_TRUE@am__append_21 = Python
-@CY_PYTHON_TRUE@am__append_22 = Python/Execute.cpp
-@CY_PYTHON_TRUE@am__append_23 = $(LTPYTHON)
-@CY_OBJECTIVEC_TRUE@am__append_24 = -DCY_OBJECTIVEC
-@CY_OBJECTIVEC_TRUE@am__append_25 = ObjectiveC
-@CY_OBJECTIVEC_TRUE@am__append_26 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm
-@CY_OBJECTIVEC_TRUE@am__append_27 = $(LTOBJECTIVEC)
-@CY_ATTACH_TRUE@am__append_28 = Handler.cpp
-@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_29 = Inject.cpp
-@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_30 = -DCY_ATTACH
+@CY_JAVA_TRUE@am__append_15 = libcycript.jar
+@CY_JAVA_TRUE@am__append_16 = Class libcycript.jar
+@CY_RUBY_TRUE@am__append_17 = Ruby
+@CY_RUBY_TRUE@am__append_18 = Ruby/Execute.cpp
+@CY_RUBY_TRUE@am__append_19 = $(LTRUBY)
+@CY_PYTHON_TRUE@am__append_20 = Python
+@CY_PYTHON_TRUE@am__append_21 = Python/Execute.cpp
+@CY_PYTHON_TRUE@am__append_22 = $(LTPYTHON)
+@CY_OBJECTIVEC_TRUE@am__append_23 = -DCY_OBJECTIVEC
+@CY_OBJECTIVEC_TRUE@am__append_24 = ObjectiveC
+@CY_OBJECTIVEC_TRUE@am__append_25 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm
+@CY_OBJECTIVEC_TRUE@am__append_26 = $(LTOBJECTIVEC)
+@CY_ATTACH_TRUE@am__append_27 = Handler.cpp
+@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_28 = Inject.cpp
+@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_29 = -DCY_ATTACH
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
@CY_EXECUTE_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
-@CY_JAVA_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
-@CY_RUBY_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1)
-@CY_PYTHON_TRUE@am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1)
-@CY_OBJECTIVEC_TRUE@am__DEPENDENCIES_6 = $(am__DEPENDENCIES_1)
+@CY_RUBY_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
+@CY_PYTHON_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1)
+@CY_OBJECTIVEC_TRUE@am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1)
libcycript_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) \
- $(am__DEPENDENCIES_5) $(am__DEPENDENCIES_6)
+ $(am__DEPENDENCIES_5)
am__libcycript_la_SOURCES_DIST = ConvertUTF.c Decode.cpp Driver.cpp \
Error.cpp Highlight.cpp Library.cpp Network.cpp Output.cpp \
Replace.cpp Syntax.cpp Parser.cpp Scanner.cpp Complete.cpp \
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = subdir-objects
CLEANFILES = $(am__append_10) $(am__append_11) $(am__append_12) \
- $(am__append_17) Parser.ypp Scanner.lpp Scanner.cpp \
+ $(am__append_16) Parser.ypp Scanner.lpp Scanner.cpp \
Scanner.output lex.backup Parser.cpp Parser.hpp stack.hh \
Parser.output
SUBDIRS =
ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -DYYDEBUG=1 -DCY_SYSTEM="\"$(CY_SYSTEM)\"" -include \
config.h -include $(srcdir)/unconfig.h $(am__append_8) \
- $(am__append_24) $(am__append_30)
+ $(am__append_23) $(am__append_29)
CY_FLAGS = -fvisibility=hidden $(am__append_1)
AM_CFLAGS = $(CY_FLAGS)
AM_CXXFLAGS = $(CY_FLAGS)
AM_LDFLAGS = $(CY_FLAGS) $(am__append_2)
CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic
datdir = $(libdir)
-dat_DATA = $(am__append_7) $(am__append_16)
+dat_DATA = $(am__append_7) $(am__append_15)
lib_LTLIBRARIES = libcycript.la
libcycript_la_LDFLAGS = $(CY_LDFLAGS)
libcycript_la_LIBADD = $(LTLIBUV) $(LTLIBFFI) $(LTLIBSQLITE3) \
- $(LTLIBGCC) -ldl $(am__append_6) $(am__append_15) \
- $(am__append_20) $(am__append_23) $(am__append_27)
+ $(LTLIBGCC) -ldl $(am__append_6) $(am__append_19) \
+ $(am__append_22) $(am__append_26)
libcycript_la_SOURCES = ConvertUTF.c Decode.cpp Driver.cpp Error.cpp \
Highlight.cpp Library.cpp Network.cpp Output.cpp Replace.cpp \
Syntax.cpp Parser.cpp Scanner.cpp $(am__append_3) \
- $(am__append_5) $(am__append_14) $(am__append_19) \
- $(am__append_22) $(am__append_26) $(am__append_28)
-filters = $(am__append_9) $(am__append_13) $(am__append_18) \
- $(am__append_21) $(am__append_25)
-@CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp $(am__append_29)
+ $(am__append_5) $(am__append_14) $(am__append_18) \
+ $(am__append_21) $(am__append_25) $(am__append_27)
+filters = $(am__append_9) $(am__append_13) $(am__append_17) \
+ $(am__append_20) $(am__append_24)
+@CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp $(am__append_28)
@CY_CONSOLE_TRUE@cycript_LDADD = libcycript.la $(LTLIBREADLINE) $(LTLIBTERMCAP) $(LTLIBGCC) $(PTHREAD_CFLAGS) -ldl
@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@cycript_pie_SOURCES = pie.c
@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@cycript_pie_LDFLAGS = -fno-PIE