[K/N][Tests] Migrate dylib-interop-exe tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
83d851dd61
commit
2b2c685827
@@ -0,0 +1,3 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/kt42172.h
|
||||
linkerOpts = -lkt42172
|
||||
@@ -0,0 +1,9 @@
|
||||
#import <objc/NSObject.h>
|
||||
|
||||
typedef void (*Finalizer)(void*);
|
||||
|
||||
@interface WithFinalizer : NSObject
|
||||
|
||||
- (void)setFinalizer:(Finalizer)finalizer arg:(void*)arg;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class, ObsoleteWorkersApi::class)
|
||||
|
||||
import kt42172.*
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun main() {
|
||||
val worker = Worker.start()
|
||||
worker.execute(TransferMode.SAFE, {}) {
|
||||
val withFinalizer = WithFinalizer()
|
||||
val finalizer: Finalizer = staticCFunction { ptr: COpaquePointer? ->
|
||||
ptr?.asStableRef<Any>()?.dispose()
|
||||
println("Executed finalizer")
|
||||
}
|
||||
val arg = StableRef.create(Any()).asCPointer()
|
||||
withFinalizer.setFinalizer(finalizer, arg)
|
||||
}.result
|
||||
worker.requestTermination().result
|
||||
waitWorkerTermination(worker)
|
||||
|
||||
if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) {
|
||||
// Experimental MM by default doesn't run GC neither on worker termination nor on program exit.
|
||||
// Enforce GC on program exit:
|
||||
kotlin.native.runtime.Debugging.forceCheckedShutdown = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "kt42172.h"
|
||||
|
||||
@implementation WithFinalizer {
|
||||
Finalizer finalizer_;
|
||||
void* arg_;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
if (finalizer_) {
|
||||
finalizer_(arg_);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFinalizer:(Finalizer)finalizer arg:(void*)arg {
|
||||
finalizer_ = finalizer;
|
||||
arg_ = arg;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user