[K/N][Tests] Migrate test illegal_sharing_with_weak.kt

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-17 22:12:24 +01:00
parent 647a907204
commit 2d0009ff99
9 changed files with 85 additions and 55 deletions
@@ -1,29 +0,0 @@
@file:OptIn(ObsoleteWorkersApi::class)
import kotlin.native.concurrent.*
import kotlinx.cinterop.autoreleasepool
import objclib.*
fun main() {
autoreleasepool {
run()
}
}
private class NSObjectImpl : NSObject() {
var x = 111
}
fun run() = withWorker {
val obj = NSObjectImpl()
setObject(obj)
println("Before")
val isAlive = try {
execute(TransferMode.SAFE, {}) {
isObjectAliveShouldCrash()
}.result
} catch (e: Throwable) {
false
}
println("After $isAlive")
}
@@ -1,2 +0,0 @@
language = Objective-C
headerFilter = **/objclib.h
@@ -1,13 +0,0 @@
#import <objc/NSObject.h>
static NSObject* __weak globalObject = nil;
void setObject(NSObject* obj) {
globalObject = obj;
}
// Make sure this function persists, because the test expects to find this function in the stack trace.
__attribute__((noinline))
bool isObjectAliveShouldCrash() {
return globalObject != nil;
}