]> git.saurik.com Git - cycript.git/commitdiff
Try to avoid using encodings when signatures work.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 12 Jan 2014 07:54:44 +0000 (23:54 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 12 Jan 2014 07:56:37 +0000 (23:56 -0800)
Execute.cpp
Internal.hpp
ObjectiveC/Library.mm

index fda1eba7cb64f9a3673120e56bd5b596f6c34eca..25ab02b10969a83c84b923f1135b620d2d54ee93 100644 (file)
@@ -496,15 +496,11 @@ JSObjectRef CYMakePointer(JSContextRef context, void *pointer, size_t length, si
     return JSObjectMake(context, Pointer_, internal);
 }
 
-static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *encoding) {
-    return JSObjectMake(context, Functor_, new cy::Functor(encoding, function));
-}
-
-static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), sig::Signature &signature) {
+static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const sig::Signature &signature) {
     return JSObjectMake(context, Functor_, new cy::Functor(signature, function));
 }
 
-static JSObjectRef CYMakeFunctor(JSContextRef context, const char *symbol, const char *type, void **cache) {
+static JSObjectRef CYMakeFunctor(JSContextRef context, const char *symbol, const char *encoding, void **cache) {
     cy::Functor *internal;
     if (*cache != NULL)
         internal = reinterpret_cast<cy::Functor *>(*cache);
@@ -513,7 +509,7 @@ static JSObjectRef CYMakeFunctor(JSContextRef context, const char *symbol, const
         if (function == NULL)
             return NULL;
 
-        internal = new cy::Functor(type, function);
+        internal = new cy::Functor(encoding, function);
         *cache = internal;
     }
 
@@ -719,10 +715,10 @@ static void FunctionClosure_(ffi_cif *cif, void *result, void **arguments, void
     CYExecuteClosure(cif, result, arguments, arg, &FunctionAdapter_);
 }
 
-Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const char *type, void (*callback)(ffi_cif *, void *, void **, void *)) {
+Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const sig::Signature &signature, void (*callback)(ffi_cif *, void *, void **, void *)) {
     // XXX: in case of exceptions this will leak
     // XXX: in point of fact, this may /need/ to leak :(
-    Closure_privateData *internal(new Closure_privateData(context, function, type));
+    Closure_privateData *internal(new Closure_privateData(context, function, signature));
 
 #if defined(__APPLE__) && defined(__arm__)
     void *executable;
@@ -750,8 +746,8 @@ Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function,
     return internal;
 }
 
-static JSObjectRef CYMakeFunctor(JSContextRef context, JSObjectRef function, const char *type) {
-    Closure_privateData *internal(CYMakeFunctor_(context, function, type, &FunctionClosure_));
+static JSObjectRef CYMakeFunctor(JSContextRef context, JSObjectRef function, const sig::Signature &signature) {
+    Closure_privateData *internal(CYMakeFunctor_(context, function, signature, &FunctionClosure_));
     JSObjectRef object(JSObjectMake(context, Functor_, internal));
     // XXX: see above notes about needing to leak
     JSValueProtect(CYGetJSContext(context), object);
@@ -762,16 +758,16 @@ JSObjectRef CYGetCachedObject(JSContextRef context, JSStringRef name) {
     return CYCastJSObject(context, CYGetProperty(context, CYCastJSObject(context, CYGetProperty(context, CYGetGlobalObject(context), cy_s)), name));
 }
 
-static JSObjectRef CYMakeFunctor(JSContextRef context, JSValueRef value, const char *type) {
+static JSObjectRef CYMakeFunctor(JSContextRef context, JSValueRef value, const sig::Signature &signature) {
     JSObjectRef Function(CYGetCachedObject(context, CYJSString("Function")));
 
     bool function(_jsccall(JSValueIsInstanceOfConstructor, context, value, Function));
     if (function) {
         JSObjectRef function(CYCastJSObject(context, value));
-        return CYMakeFunctor(context, function, type);
+        return CYMakeFunctor(context, function, signature);
     } else {
         void (*function)()(CYCastPointer<void (*)()>(context, value));
-        return CYMakeFunctor(context, function, type);
+        return CYMakeFunctor(context, function, signature);
     }
 }
 
@@ -1212,8 +1208,10 @@ static JSObjectRef Functor_new(JSContextRef context, JSObjectRef object, size_t
     if (count != 2)
         throw CYJSError(context, "incorrect number of arguments to Functor constructor");
     CYPool pool;
-    const char *type(CYPoolCString(pool, context, arguments[1]));
-    return CYMakeFunctor(context, arguments[0], type);
+    const char *encoding(CYPoolCString(pool, context, arguments[1]));
+    sig::Signature signature;
+    sig::Parse(pool, &signature, encoding, &Structor_);
+    return CYMakeFunctor(context, arguments[0], signature);
 } CYCatch(NULL) }
 
 static JSValueRef CYValue_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
index ff45f13b69479f070d19241ad3df17c045aace9e..b4dd4a1b09502e70ed2edb55b3e7d41a19de086b 100644 (file)
@@ -170,7 +170,7 @@ struct Functor :
     sig::Signature signature_;
     ffi_cif cif_;
 
-    Functor(sig::Signature &signature, void (*value)()) :
+    Functor(const sig::Signature &signature, void (*value)()) :
         CYValue(reinterpret_cast<void *>(value))
     {
         sig::Copy(*pool_, signature_, signature);
@@ -197,8 +197,8 @@ struct Closure_privateData :
     JSGlobalContextRef context_;
     JSObjectRef function_;
 
-    Closure_privateData(JSContextRef context, JSObjectRef function, const char *type) :
-        cy::Functor(type, NULL),
+    Closure_privateData(JSContextRef context, JSObjectRef function, const sig::Signature &signature) :
+        cy::Functor(signature, NULL),
         context_(CYGetJSContext(context)),
         function_(function)
     {
@@ -212,7 +212,7 @@ struct Closure_privateData :
     }
 };
 
-Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const char *type, void (*callback)(ffi_cif *, void *, void **, void *));
+Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const sig::Signature &signature, void (*callback)(ffi_cif *, void *, void **, void *));
 void CYExecuteClosure(ffi_cif *cif, void *result, void **arguments, void *arg, JSValueRef (*adapter)(JSContextRef, size_t, JSValueRef[], JSObjectRef));
 
 #endif/*CYCRIPT_INTERNAL_HPP*/
index bb62fc4a70997f41794b7e1616512c97818be226..1904f24e044588f798dda28f4011976392bfe579 100644 (file)
@@ -1549,9 +1549,12 @@ static JSObjectRef CYMakeMessage(JSContextRef context, SEL sel, IMP imp, const c
     return JSObjectMake(context, Message_, internal);
 }
 
-static IMP CYMakeMessage(JSContextRef context, JSValueRef value, const char *type) {
+static IMP CYMakeMessage(JSContextRef context, JSValueRef value, const char *encoding) {
     JSObjectRef function(CYCastJSObject(context, value));
-    Closure_privateData *internal(CYMakeFunctor_(context, function, type, &MessageClosure_));
+    CYPool pool;
+    sig::Signature signature;
+    sig::Parse(pool, &signature, encoding, &Structor_);
+    Closure_privateData *internal(CYMakeFunctor_(context, function, signature, &MessageClosure_));
     // XXX: see notes in Library.cpp about needing to leak
     return reinterpret_cast<IMP>(internal->GetValue());
 }