From: Jay Freeman (saurik) Date: Tue, 1 Sep 2009 07:34:01 +0000 (+0000) Subject: Support bridge support variables. X-Git-Tag: v0.9.432~418 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/707bcb93a9381c936f6793366049a9ae4cab450a Support bridge support variables. --- diff --git a/Tweak.mm b/Tweak.mm index fc7007d..43d6f2c 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -131,9 +131,7 @@ class _H { } }; /* }}} */ - -#define _pooled _H _pool([[NSAutoreleasePool alloc] init], true); - +/* APR Pool Helpers {{{ */ void *operator new(size_t size, apr_pool_t *pool) { return apr_palloc(pool, size); } @@ -142,6 +140,27 @@ void *operator new [](size_t size, apr_pool_t *pool) { return apr_palloc(pool, size); } +class CYPool { + private: + apr_pool_t *pool_; + + public: + CYPool() { + apr_pool_create(&pool_, NULL); + } + + ~CYPool() { + apr_pool_destroy(pool_); + } + + operator apr_pool_t *() const { + return pool_; + } +}; +/* }}} */ + +#define _pooled _H _pool([[NSAutoreleasePool alloc] init], true); + static JSContextRef Context_; static JSClassRef Functor_; @@ -675,24 +694,6 @@ JSObjectRef CYMakeFunction(JSContextRef context, void *function, const char *typ return CYMakeFunction(context, reinterpret_cast(function), type); } -static JSValueRef Global_getProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) { _pooled - @try { - NSString *string(CYCastNSString(name)); - if (Class _class = NSClassFromString(string)) - return CYMakeObject(context, _class); - if (NSMutableArray *entry = [Bridge_ objectForKey:string]) - switch ([[entry objectAtIndex:0] intValue]) { - case 0: - return CYMakeFunction(context, [string cy$symbol], [[entry objectAtIndex:1] UTF8String]); - case 1: - _assert(false); - case 2: - return JSEvaluateScript(JSGetContext(), CYString([entry objectAtIndex:1]), NULL, NULL, 0, NULL); - } - return NULL; - } CYCatch -} - void CYSetProperty(JSContextRef context, JSObjectRef object, const char *name, JSValueRef value) { JSValueRef exception(NULL); JSObjectSetProperty(context, object, CYString(name), value, kJSPropertyAttributeNone, &exception); @@ -874,24 +875,6 @@ JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, void *data) { return value; } -class CYPool { - private: - apr_pool_t *pool_; - - public: - CYPool() { - apr_pool_create(&pool_, NULL); - } - - ~CYPool() { - apr_pool_destroy(pool_); - } - - operator apr_pool_t *() const { - return pool_; - } -}; - static JSValueRef CYCallFunction(JSContextRef context, size_t count, const JSValueRef *arguments, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)()) { _pooled @try { if (count != signature->count - 1) @@ -914,6 +897,27 @@ static JSValueRef CYCallFunction(JSContextRef context, size_t count, const JSVal } CYCatch } +static JSValueRef Global_getProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) { _pooled + @try { + NSString *string(CYCastNSString(name)); + if (Class _class = NSClassFromString(string)) + return CYMakeObject(context, _class); + if (NSMutableArray *entry = [Bridge_ objectForKey:string]) + switch ([[entry objectAtIndex:0] intValue]) { + case 0: + return JSEvaluateScript(JSGetContext(), CYString([entry objectAtIndex:1]), NULL, NULL, 0, NULL); + case 1: + return CYMakeFunction(context, [string cy$symbol], [[entry objectAtIndex:1] UTF8String]); + case 2: + CYPool pool; + sig::Signature signature; + sig::Parse(pool, &signature, [[entry objectAtIndex:1] UTF8String]); + return CYFromFFI(context, signature.elements[0].type, [string cy$symbol]); + } + return NULL; + } CYCatch +} + bool stret(ffi_type *ffi_type) { return ffi_type->type == FFI_TYPE_STRUCT && ( ffi_type->size > OBJC_MAX_STRUCT_BY_VALUE || diff --git a/makefile b/makefile index 024cd30..9e874da 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ clean: rm -f $(name).dylib libcyrver.plist: Bridge.def makefile - sed -e 's/^F/0/;s/^V/1/;s/^C/2/' Bridge.def | while read -r line; do \ + sed -e 's/^C/0/;s/^F/1/;s/^V/2/' Bridge.def | while read -r line; do \ if [[ $$line == '' ]]; then \ continue; \ fi; \