Fix Objective-C weak references to Kotlin objects (#1533)
This commit is contained in:
committed by
GitHub
parent
14ba28c5c7
commit
b54685e742
@@ -127,6 +127,11 @@ static inline id AtomicSetAssociatedObject(ObjHeader* obj, id associatedObject)
|
||||
}
|
||||
}
|
||||
|
||||
@interface NSObject (NSObjectPrivateMethods)
|
||||
// Implemented for NSObject in libobjc/NSObject.mm
|
||||
-(BOOL)_tryRetain;
|
||||
@end;
|
||||
|
||||
@interface KotlinBase : NSObject <ConvertibleToKotlin, NSCopying>
|
||||
@end;
|
||||
|
||||
@@ -189,6 +194,20 @@ static inline id AtomicSetAssociatedObject(ObjHeader* obj, id associatedObject)
|
||||
return self;
|
||||
}
|
||||
|
||||
-(BOOL)_tryRetain {
|
||||
ObjHeader* obj = kotlinObj;
|
||||
if (obj->permanent()) {
|
||||
return [super _tryRetain];
|
||||
} else if (!obj->has_meta_object()) {
|
||||
// Then object is being deallocated;
|
||||
// return `NO` as required by _tryRetain semantics:
|
||||
return NO;
|
||||
} else {
|
||||
AddRefFromAssociatedObject(obj);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
-(oneway void)release {
|
||||
ObjHeader* obj = kotlinObj;
|
||||
if (obj->permanent()) {
|
||||
|
||||
Reference in New Issue
Block a user