]> git.saurik.com Git - cycript.git/commitdiff
Fixed GNUstep.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 1 Nov 2009 04:46:49 +0000 (04:46 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 1 Nov 2009 04:46:49 +0000 (04:46 +0000)
Library.cpp
ObjectiveC/Library.mm
cycript.hpp
makefile

index e1ef4fa969b5e3747ca5ba026a9e1e2b700ac5b1..7bc867bd43f9c7c5009094ceb3b1a2ad2a9852b8 100644 (file)
@@ -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;
index d64d6f477215ed29ff0f45c0af4bf02fc101fe2e..81dfe86def7f9db47cc83df2ada9e6ad80ad0562 100644 (file)
 #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<id *>(data)) {
+            if (NSObject *object = *reinterpret_cast<NSObject **>(data)) {
                 JSValueRef value(CYCastJSValue(context, object));
                 if (initialize)
                     [object release];
index a1e1f022d5cff8abdc7b3170835892e64e088483..ff163246c21331827fb73024ce27e7e435092a7b 100644 (file)
@@ -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);
index 06047f1771379832943ac3b618d62c462e3e64f2..4240e51a136e377df3d6c4c5cd5b8c125bb85b3a 100644 (file)
--- 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