[K/N] Add more tests on associated object handling ^KT-56233
This commit is contained in:
committed by
Space Team
parent
dbe14a0a90
commit
87da670319
@@ -22,3 +22,9 @@ extern BOOL deallocLoadWeakDeallocated;
|
||||
@interface DeallocLoadWeak : NSObject
|
||||
-(void)checkWeak;
|
||||
@end
|
||||
|
||||
extern BOOL deallocRetainAndAccessDeallocated;
|
||||
|
||||
@interface DeallocRetainAndAccess : NSObject
|
||||
@property void (^onDealloc)(id);
|
||||
@end
|
||||
|
||||
@@ -116,3 +116,44 @@ fun testKT41811WithGlobal() {
|
||||
|
||||
assertTrue(deallocRetainReleaseDeallocated)
|
||||
}
|
||||
|
||||
var localDeallocRetainAndAccessDeallocated = false
|
||||
|
||||
@Test
|
||||
fun testKT41811WithAccess() {
|
||||
// Legacy MM crashes with an assertion failure.
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
if (!isExperimentalMM())
|
||||
return
|
||||
|
||||
// Attempt to make the state predictable:
|
||||
kotlin.native.internal.GC.collect()
|
||||
|
||||
deallocRetainAndAccessDeallocated = false
|
||||
localDeallocRetainAndAccessDeallocated = false
|
||||
|
||||
createGarbageDeallocRetainAndAccess()
|
||||
|
||||
// Runs [DeallocRetainAndAccess dealloc]:
|
||||
kotlin.native.internal.GC.collect()
|
||||
|
||||
assertTrue(deallocRetainAndAccessDeallocated)
|
||||
assertTrue(localDeallocRetainAndAccessDeallocated)
|
||||
|
||||
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
|
||||
kotlin.native.internal.GC.collect()
|
||||
}
|
||||
|
||||
private fun createGarbageDeallocRetainAndAccess() {
|
||||
autoreleasepool {
|
||||
object : DeallocRetainAndAccess() {
|
||||
init {
|
||||
onDealloc = {
|
||||
assertNull(it)
|
||||
assertFalse(localDeallocRetainAndAccessDeallocated)
|
||||
localDeallocRetainAndAccessDeallocated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,3 +37,20 @@ BOOL deallocLoadWeakDeallocated = NO;
|
||||
deallocLoadWeakDeallocated = YES;
|
||||
}
|
||||
@end
|
||||
|
||||
id retainObject2 = nil;
|
||||
BOOL deallocRetainAndAccessDeallocated = NO;
|
||||
|
||||
@implementation DeallocRetainAndAccess
|
||||
|
||||
- (void)dealloc {
|
||||
retainObject2 = self;
|
||||
assert(_onDealloc != nil);
|
||||
_onDealloc(retainObject2);
|
||||
retainObject2 = nil;
|
||||
|
||||
assert(!deallocRetainAndAccessDeallocated);
|
||||
deallocRetainAndAccessDeallocated = YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user