From: Jay Freeman (saurik) Date: Sun, 1 Nov 2009 04:46:49 +0000 (+0000) Subject: Fixed GNUstep. X-Git-Tag: v0.9.432~205 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/ba4fa42f039588bbf27e8886dc2e0600d42fe77e Fixed GNUstep. --- diff --git a/Library.cpp b/Library.cpp index e1ef4fa..7bc867b 100644 --- a/Library.cpp +++ b/Library.cpp @@ -186,19 +186,25 @@ const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, JSValueRef val /* Index Offsets {{{ */ size_t CYGetIndex(const CYUTF8String &value) { if (value.data[0] != '0') { - char *end; - size_t index(strtoul(value.data, &end, 10)); - if (value.data + value.size == end) - return index; - } else if (value.data[1] == '\0') + size_t index(0); + for (size_t i(0); i != value.size; ++i) { + if (!DigitRange_[value.data[i]]) + return _not(size_t); + index *= 10; + index += value.data[i] - '0'; + } + return index; + } else if (value.size == 1) return 0; - return _not(size_t); + else + return _not(size_t); } size_t CYGetIndex(apr_pool_t *pool, JSContextRef context, JSStringRef value) { return CYGetIndex(CYPoolUTF8String(pool, context, value)); } +// XXX: this isn't actually right bool CYGetOffset(const char *value, ssize_t &index) { if (value[0] != '0') { char *end; diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index d64d6f4..81dfe86 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -74,13 +74,17 @@ #define method_getTypeEncoding(method) ((method)->method_types) #define method_setImplementation(method, imp) ((void) ((method)->method_imp = (imp))) +#undef objc_getClass +#define objc_getClass GSClassFromName + #define objc_getProtocol GSProtocolFromName #define object_getClass GSObjCClass #define object_getInstanceVariable(object, name, value) ({ \ objc_ivar *ivar(class_getInstanceVariable(object_getClass(object), name)); \ - GSObjCGetVariable(object, ivar_getOffset(ivar), sizeof(void *), value); \ + if (ivar != NULL) \ + GSObjCGetVariable(object, ivar_getOffset(ivar), sizeof(void *), value); \ ivar; \ }) @@ -189,6 +193,8 @@ CYUTF8String CYCastUTF8String(NSString *value) { } /* }}} */ +JSValueRef CYCastJSValue(JSContextRef context, NSObject *value); + void CYThrow(JSContextRef context, NSException *error, JSValueRef *exception) { if (exception == NULL) throw error; @@ -1002,7 +1008,7 @@ NSArray *CYCastNSArray(JSContextRef context, JSPropertyNameArrayRef names) { return array; } -JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry { +JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry { if (value == nil) return CYJSNull(context); else if ([value respondsToSelector:@selector(cy$JSValueInContext:)]) @@ -1073,7 +1079,7 @@ JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry { - (void) setObject:(id)object forKey:(id)key { CYObjectiveTry { // XXX: are NSDictionary keys always NSString *? - CYSetProperty(context_, object_, CYJSString(context_, (NSString *) key), CYCastJSValue(context_, object)); + CYSetProperty(context_, object_, CYJSString(context_, (NSString *) key), CYCastJSValue(context_, (NSString *) object)); } CYObjectiveCatch } - (void) removeObjectForKey:(id)key { CYObjectiveTry { @@ -1117,7 +1123,7 @@ JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry { - (void) addObject:(id)object { CYObjectiveTry { JSValueRef exception(NULL); JSValueRef arguments[1]; - arguments[0] = CYCastJSValue(context_, object); + arguments[0] = CYCastJSValue(context_, (NSObject *) object); JSObjectCallAsFunction(context_, Array_push_, object_, 1, arguments, &exception); CYThrow(context_, exception); } CYObjectiveCatch } @@ -1130,7 +1136,7 @@ JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry { JSValueRef arguments[3]; arguments[0] = CYCastJSValue(context_, index); arguments[1] = CYCastJSValue(context_, 0); - arguments[2] = CYCastJSValue(context_, object); + arguments[2] = CYCastJSValue(context_, (NSObject *) object); JSObjectCallAsFunction(context_, Array_splice_, object_, 3, arguments, &exception); CYThrow(context_, exception); } CYObjectiveCatch } @@ -1157,7 +1163,7 @@ JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry { size_t bounds([self count]); if (index >= bounds) @throw [NSException exceptionWithName:NSRangeException reason:[NSString stringWithFormat:@"*** -[CYJSArray replaceObjectAtIndex:withObject:]: index (%zu) beyond bounds (%zu)", index, bounds] userInfo:nil]; - CYSetProperty(context_, object_, index, CYCastJSValue(context_, object)); + CYSetProperty(context_, object_, index, CYCastJSValue(context_, (NSObject *) object)); } CYObjectiveCatch } @end @@ -1275,7 +1281,7 @@ static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Ty static JSValueRef CYObjectiveC_FromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) { CYPoolTry { switch (type->primitive) { case sig::object_P: - if (id object = *reinterpret_cast(data)) { + if (NSObject *object = *reinterpret_cast(data)) { JSValueRef value(CYCastJSValue(context, object)); if (initialize) [object release]; diff --git a/cycript.hpp b/cycript.hpp index a1e1f02..ff16324 100644 --- a/cycript.hpp +++ b/cycript.hpp @@ -93,7 +93,7 @@ JSValueRef CYGetProperty(JSContextRef context, JSObjectRef object, JSStringRef n void CYSetProperty(JSContextRef context, JSObjectRef object, size_t index, JSValueRef value); void CYSetProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef value, JSPropertyAttributes attributes = kJSPropertyAttributeNone); -JSValueRef CYCastJSValue(JSContextRef context, bool value); +//JSValueRef CYCastJSValue(JSContextRef context, bool value); JSValueRef CYCastJSValue(JSContextRef context, double value); JSValueRef CYCastJSValue(JSContextRef context, int value); JSValueRef CYCastJSValue(JSContextRef context, unsigned int value); diff --git a/makefile b/makefile index 06047f1..4240e51 100644 --- a/makefile +++ b/makefile @@ -49,7 +49,7 @@ uname_p ?= $(shell uname -p) ifeq ($(filter ObjectiveC,$(filters)),) ifneq ($(shell which gnustep-config 2>/dev/null),) -#include GNUstep.mk +include GNUstep.mk endif endif