X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b799113bd4ec270504dd9f552142c1adfd6e583a..d4705d6b345f860379076247f3287aa9d1ed8d5c:/ObjectiveC/Library.mm diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index e430c0c..59006c7 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -32,7 +32,6 @@ #ifdef __APPLE__ #include #include -#include #include #endif @@ -162,10 +161,9 @@ enum { JSValueRef CYSendMessage(CYPool &pool, JSContextRef context, id self, Class super, SEL _cmd, size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception); /* Objective-C Pool Release {{{ */ -apr_status_t CYPoolRelease_(void *data) { +void CYPoolRelease_(void *data) { id object(reinterpret_cast(data)); [object release]; - return APR_SUCCESS; } id CYPoolRelease_(CYPool *pool, id object) { @@ -174,7 +172,7 @@ id CYPoolRelease_(CYPool *pool, id object) { else if (pool == NULL) return [object autorelease]; else { - apr_pool_cleanup_register(*pool, object, &CYPoolRelease_, &apr_pool_cleanup_null); + pool->atexit(CYPoolRelease_); return object; } } @@ -186,15 +184,11 @@ Type_ CYPoolRelease(CYPool *pool, Type_ object) { /* }}} */ /* Objective-C Strings {{{ */ const char *CYPoolCString(CYPool &pool, JSContextRef context, NSString *value) { - if (pool == NULL) - return [value UTF8String]; - else { - size_t size([value maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1); - char *string(new(pool) char[size]); - if (![value getCString:string maxLength:size encoding:NSUTF8StringEncoding]) - throw CYJSError(context, "[NSString getCString:maxLength:encoding:] == NO"); - return string; - } + size_t size([value maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1); + char *string(new(pool) char[size]); + if (![value getCString:string maxLength:size encoding:NSUTF8StringEncoding]) + throw CYJSError(context, "[NSString getCString:maxLength:encoding:] == NO"); + return string; } JSStringRef CYCopyJSString(JSContextRef context, NSString *value) { @@ -519,7 +513,9 @@ struct PropertyAttributes { name = property_getName(property); const char *attributes(property_getAttributes(property)); - for (char *state, *token(apr_strtok(pool_.strdup(attributes), ",", &state)); token != NULL; token = apr_strtok(NULL, ",", &state)) { + for (char *token(pool_.strdup(attributes)), *next; token != NULL; token = next) { + if ((next = strchr(token, ',')) != NULL) + *next++ = '\0'; switch (*token) { case 'R': readonly = true; break; case 'C': copy = true; break; @@ -573,7 +569,6 @@ struct PropertyAttributes { }; #endif -#ifndef __APPLE__ @interface CYWebUndefined : NSObject { } @@ -591,7 +586,6 @@ struct PropertyAttributes { @end #define WebUndefined CYWebUndefined -#endif /* Bridge: CYJSObject {{{ */ @interface CYJSObject : NSMutableDictionary {