]> git.saurik.com Git - cycript.git/commitdiff
The value from +alloc can be a permanent (NSDate).
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 6 Jan 2016 08:03:19 +0000 (00:03 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 6 Jan 2016 08:03:19 +0000 (00:03 -0800)
ObjectiveC/Internal.hpp
ObjectiveC/Library.mm

index 8606d55fa6941e719a2bf17e14e7671648b97749..deb5e5df07df64ae47657b0e686bd52094bc7e71 100644 (file)
@@ -38,11 +38,10 @@ struct Selector_privateData :
 struct Instance :
     CYValue<Instance, id>
 {
-    enum Flags {
-        None          = 0,
-        Permanent     = (1 << 0),
-        Uninitialized = (1 << 1),
-    };
+    typedef unsigned Flags;
+    static const Flags None = 0;
+    static const Flags Permanent = 1 << 0;
+    static const Flags Uninitialized = 1 << 1;
 
     Flags flags_;
 
@@ -53,6 +52,10 @@ struct Instance :
 
     static JSClassRef GetClass(id value, Flags flags);
 
+    _finline bool IsPermanent() const {
+        return (flags_ & Permanent) != 0;
+    }
+
     _finline bool IsUninitialized() const {
         return (flags_ & Uninitialized) != 0;
     }
index 27149126be7317aca39e30e3de5cb2ad9f725019..140b759347e86a2eb59df7641dcdaa19fc04293f 100644 (file)
@@ -353,12 +353,15 @@ Instance::Instance(id value, Flags flags) :
     CYValue(value),
     flags_(flags)
 {
-    if ((flags & Instance::Permanent) == 0)
+    if (IsPermanent());
+    /*else if ([value retainCount] == NSUInteger(-1))
+        flags_ |= Instance::Permanent;*/
+    else
         value_ = [value_ retain];
 }
 
 Instance::~Instance() {
-    if ((flags_ & Permanent) == 0)
+    if (!IsPermanent())
         [value_ release];
 }
 
@@ -1558,10 +1561,12 @@ JSValueRef Object::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool
     if (initialize) {
         Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
 
-        if ((internal->flags_ & Instance::Uninitialized) != 0) {
-            internal->flags_ = static_cast<Instance::Flags>(internal->flags_ & ~Instance::Uninitialized);
-            _assert(internal->value_ == nil);
-            internal->value_ = value;
+        if (internal->IsUninitialized()) {
+            internal->flags_ &= ~Instance::Uninitialized;
+            if (internal->value_ == nil)
+                internal->value_ = value;
+            else
+                _assert(internal->value_ == value);
         }
 
         [value release];
@@ -2449,7 +2454,7 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje
         self = internal->value_;
         _class = nil;
         uninitialized = internal->IsUninitialized();
-        if (uninitialized)
+        if (uninitialized && [internal->value_ retainCount] != NSUInteger(-1))
             internal->value_ = nil;
     } else {
         self = CYCastNSObject(&pool, context, arguments[0]);