From: Jay Freeman (saurik) Date: Sun, 3 Jan 2016 10:33:51 +0000 (-0800) Subject: Slightly (sort of) improve proxy objects tracking. X-Git-Tag: v0.9.590~85 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/0e832de422b749cc0e33c2aa067983ad421949bf?ds=sidebyside Slightly (sort of) improve proxy objects tracking. --- diff --git a/Java/Cycript.java b/Java/Cycript.java index 79ebe8e..8fb7817 100644 --- a/Java/Cycript.java +++ b/Java/Cycript.java @@ -80,16 +80,18 @@ public static class Wrapper if (false) return null; else if (method.equals(Object$equals)) + // XXX: this assumes there is only one proxy return proxy == args[0]; else if (method == Object$hashCode) - return System.identityHashCode(proxy); + // XXX: this assumes there is only one wrapper + return hashCode(); else return handle(protect_, method.getName(), args); } } -public static Object proxy(Class proxy, long protect) { - return Proxy.newProxyInstance(proxy.getClassLoader(), new Class[] {proxy}, new Wrapper(protect)); +public static Object proxy(Class proxy, Wrapper wrapper) { + return Proxy.newProxyInstance(proxy.getClassLoader(), new Class[] {proxy}, wrapper); } } diff --git a/Java/Execute.cpp b/Java/Execute.cpp index 688de68..2156045 100644 --- a/Java/Execute.cpp +++ b/Java/Execute.cpp @@ -97,6 +97,15 @@ CYJavaForEachPrimitive #undef CYJavaForEachPrimitive_ }; +template +struct IsJavaPrimitive { static const bool value = false; }; + +#define CYJavaForEachPrimitive_(T, t, Typ, Type, type) \ + template <> \ + struct IsJavaPrimitive { static const bool value = true; }; +CYJavaForEachPrimitive +#undef CYJavaForEachPrimitive_ + // Java References {{{ template struct CYJavaRef { @@ -117,6 +126,7 @@ struct CYJavaRef { return jni_; } + // XXX: this is only needed to support CYJavaEnv relying on C variadics _finline Value_ get() const { return value_; } @@ -394,7 +404,7 @@ CYJavaForEachPrimitive #define CYJavaEnv_(Code) \ template \ - auto Code(Args_ &&... args) const -> decltype(jni->Code(args...)) { \ + auto Code(Args_ &&... args) const -> decltype(jni->Code(cy::Forward(args)...)) { \ return _envcall(jni, Code(cy::Forward(args)...)); \ } @@ -993,11 +1003,9 @@ static JSObjectRef JavaClass_callAsConstructor(JSContextRef context, JSObjectRef jclass _class(table->value_); if (table->interface_ && count == 1) { - JSObjectRef target(CYCastJSObject(context, arguments[0])); auto Cycript$(jni.FindClass("Cycript")); - auto Cycript$Make(jni.GetStaticMethodID(Cycript$, "proxy", "(Ljava/lang/Class;J)Ljava/lang/Object;")); - auto protect(new CYProtect(context, target)); - return CYCastJSObject(context, jni.CallObjectMethod(Cycript$, Cycript$Make, _class, reinterpret_cast(protect))); + auto Cycript$Make(jni.GetStaticMethodID(Cycript$, "proxy", "(Ljava/lang/Class;LCycript$Wrapper;)Ljava/lang/Object;")); + return CYCastJSObject(context, jni.CallObjectMethod(Cycript$, Cycript$Make, _class, CYCastJavaObject(jni, context, CYCastJSObject(context, arguments[0])).get())); } CYJavaSignature bound(count); diff --git a/Utility.hpp b/Utility.hpp index 69d0712..5cfe6ab 100644 --- a/Utility.hpp +++ b/Utility.hpp @@ -49,6 +49,9 @@ inline typename cy::remove_reference::type &&Move(T &&t) { return static_cast::type &&>(t); } +template struct EnableIf {}; +template struct EnableIf { typedef T type; }; + } #endif/*CYCRIPT_UTILITY_HPP*/