[K/N] Replace SymbolName with GCUnsafeCall in stdlib

This commit is contained in:
Pavel Kunyavskiy
2021-09-03 14:58:54 +03:00
committed by Space
parent 05fbed68e2
commit 91c6ee1ebb
6 changed files with 56 additions and 58 deletions
@@ -17,7 +17,7 @@
package kotlinx.wasm.jsinterop package kotlinx.wasm.jsinterop
import kotlin.native.* import kotlin.native.*
import kotlin.native.internal.ExportForCppRuntime import kotlin.native.internal.*
import kotlinx.cinterop.* import kotlinx.cinterop.*
typealias Arena = Int typealias Arena = Int
@@ -28,15 +28,15 @@ typealias Pointer = Int
* @Retain annotation is required to preserve functions from internalization and DCE. * @Retain annotation is required to preserve functions from internalization and DCE.
*/ */
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_allocateArena") @GCUnsafeCall("Konan_js_allocateArena")
external public fun allocateArena(): Arena external public fun allocateArena(): Arena
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_freeArena") @GCUnsafeCall("Konan_js_freeArena")
external public fun freeArena(arena: Arena) external public fun freeArena(arena: Arena)
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_pushIntToArena") @GCUnsafeCall("Konan_js_pushIntToArena")
external public fun pushIntToArena(arena: Arena, value: Int) external public fun pushIntToArena(arena: Arena, value: Int)
const val upperWord = 0xffffffff.toLong() shl 32 const val upperWord = 0xffffffff.toLong() shl 32
@@ -50,15 +50,15 @@ fun doubleLower(value: Double): Int =
(value.toBits() and 0x00000000ffffffff) .toInt() (value.toBits() and 0x00000000ffffffff) .toInt()
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("ReturnSlot_getDouble") @GCUnsafeCall("ReturnSlot_getDouble")
external public fun ReturnSlot_getDouble(): Double external public fun ReturnSlot_getDouble(): Double
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Kotlin_String_utf16pointer") @GCUnsafeCall("Kotlin_String_utf16pointer")
external public fun stringPointer(message: String): Pointer external public fun stringPointer(message: String): Pointer
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Kotlin_String_utf16length") @GCUnsafeCall("Kotlin_String_utf16length")
external public fun stringLengthBytes(message: String): Int external public fun stringLengthBytes(message: String): Int
typealias KtFunction <R> = ((ArrayList<JsValue>)->R) typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
@@ -105,19 +105,19 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
} }
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_getInt") @GCUnsafeCall("Konan_js_getInt")
external public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int; external public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_getProperty") @GCUnsafeCall("Konan_js_getProperty")
external public fun Konan_js_getProperty(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int; external public fun Konan_js_getProperty(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_setFunction") @GCUnsafeCall("Konan_js_setFunction")
external public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int) external public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int)
@RetainForTarget("wasm32") @RetainForTarget("wasm32")
@SymbolName("Konan_js_setString") @GCUnsafeCall("Konan_js_setString")
external public fun setString(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int, stringPtr: Pointer, stringLength: Int ) external public fun setString(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int, stringPtr: Pointer, stringLength: Int )
fun setter(obj: JsValue, property: String, string: String) { fun setter(obj: JsValue, property: String, string: String) {
@@ -5,6 +5,7 @@
package kotlinx.cinterop package kotlinx.cinterop
import kotlin.native.internal.ExportForCppRuntime import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.GCUnsafeCall
public class ForeignException internal constructor(val nativeException: Any?): Exception() { public class ForeignException internal constructor(val nativeException: Any?): Exception() {
override val message: String = nativeException?.let { override val message: String = nativeException?.let {
@@ -12,7 +13,7 @@ public class ForeignException internal constructor(val nativeException: Any?): E
}?: "" }?: ""
// Current implementation expects NSException type only, which is ensured by CodeGenerator. // Current implementation expects NSException type only, which is ensured by CodeGenerator.
@SymbolName("Kotlin_ObjCExport_ExceptionDetails") @GCUnsafeCall("Kotlin_ObjCExport_ExceptionDetails")
private external fun kotlin_ObjCExport_ExceptionDetails(nativeException: Any): String? private external fun kotlin_ObjCExport_ExceptionDetails(nativeException: Any): String?
} }
@@ -18,11 +18,7 @@
package kotlinx.cinterop package kotlinx.cinterop
import kotlin.native.* import kotlin.native.*
import kotlin.native.internal.ExportTypeInfo import kotlin.native.internal.*
import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.TypedIntrinsic
import kotlin.native.internal.IntrinsicType
import kotlin.native.internal.FilterExceptions
interface ObjCObject interface ObjCObject
interface ObjCClass : ObjCObject interface ObjCClass : ObjCObject
@@ -63,16 +59,16 @@ private fun ObjCObjectBase.superInitCheck(superInitCallResult: ObjCObject?) {
internal fun <T : Any?> Any?.uncheckedCast(): T = @Suppress("UNCHECKED_CAST") (this as T) internal fun <T : Any?> Any?.uncheckedCast(): T = @Suppress("UNCHECKED_CAST") (this as T)
// Note: if this is called for non-frozen object on a wrong worker, the program will terminate. // Note: if this is called for non-frozen object on a wrong worker, the program will terminate.
@SymbolName("Kotlin_Interop_refFromObjC") @GCUnsafeCall("Kotlin_Interop_refFromObjC")
external fun <T> interpretObjCPointerOrNull(objcPtr: NativePtr): T? external fun <T> interpretObjCPointerOrNull(objcPtr: NativePtr): T?
@ExportForCppRuntime @ExportForCppRuntime
inline fun <T : Any> interpretObjCPointer(objcPtr: NativePtr): T = interpretObjCPointerOrNull<T>(objcPtr)!! inline fun <T : Any> interpretObjCPointer(objcPtr: NativePtr): T = interpretObjCPointerOrNull<T>(objcPtr)!!
@SymbolName("Kotlin_Interop_refToObjC") @GCUnsafeCall("Kotlin_Interop_refToObjC")
external fun Any?.objcPtr(): NativePtr external fun Any?.objcPtr(): NativePtr
@SymbolName("Kotlin_Interop_createKotlinObjectHolder") @GCUnsafeCall("Kotlin_Interop_createKotlinObjectHolder")
external fun createKotlinObjectHolder(any: Any?): NativePtr external fun createKotlinObjectHolder(any: Any?): NativePtr
// Note: if this is called for non-frozen underlying ref on a wrong worker, the program will terminate. // Note: if this is called for non-frozen underlying ref on a wrong worker, the program will terminate.
@@ -81,7 +77,7 @@ inline fun <reified T : Any> unwrapKotlinObjectHolder(holder: Any?): T {
} }
@PublishedApi @PublishedApi
@SymbolName("Kotlin_Interop_unwrapKotlinObjectHolder") @GCUnsafeCall("Kotlin_Interop_unwrapKotlinObjectHolder")
external internal fun unwrapKotlinObjectHolderImpl(ptr: NativePtr): Any external internal fun unwrapKotlinObjectHolderImpl(ptr: NativePtr): Any
class ObjCObjectVar<T>(rawPtr: NativePtr) : CVariable(rawPtr) { class ObjCObjectVar<T>(rawPtr: NativePtr) : CVariable(rawPtr) {
@@ -175,11 +171,11 @@ internal external fun getMessengerStret(superClass: NativePtr): COpaquePointer?
internal class ObjCWeakReferenceImpl : kotlin.native.ref.WeakReferenceImpl() { internal class ObjCWeakReferenceImpl : kotlin.native.ref.WeakReferenceImpl() {
@SymbolName("Konan_ObjCInterop_getWeakReference") @GCUnsafeCall("Konan_ObjCInterop_getWeakReference")
external override fun get(): Any? external override fun get(): Any?
} }
@SymbolName("Konan_ObjCInterop_initWeakReference") @GCUnsafeCall("Konan_ObjCInterop_initWeakReference")
private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr) private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr)
@kotlin.native.internal.ExportForCppRuntime internal fun makeObjCWeakReferenceImpl(objcPtr: NativePtr): ObjCWeakReferenceImpl { @kotlin.native.internal.ExportForCppRuntime internal fun makeObjCWeakReferenceImpl(objcPtr: NativePtr): ObjCWeakReferenceImpl {
@@ -191,37 +187,37 @@ private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr)
// Konan runtme: // Konan runtme:
@Deprecated("Use plain Kotlin cast of String to NSString", level = DeprecationLevel.ERROR) @Deprecated("Use plain Kotlin cast of String to NSString", level = DeprecationLevel.ERROR)
@SymbolName("Kotlin_Interop_CreateNSStringFromKString") @GCUnsafeCall("Kotlin_Interop_CreateNSStringFromKString")
external fun CreateNSStringFromKString(str: String?): NativePtr external fun CreateNSStringFromKString(str: String?): NativePtr
@Deprecated("Use plain Kotlin cast of NSString to String", level = DeprecationLevel.ERROR) @Deprecated("Use plain Kotlin cast of NSString to String", level = DeprecationLevel.ERROR)
@SymbolName("Kotlin_Interop_CreateKStringFromNSString") @GCUnsafeCall("Kotlin_Interop_CreateKStringFromNSString")
external fun CreateKStringFromNSString(ptr: NativePtr): String? external fun CreateKStringFromNSString(ptr: NativePtr): String?
@PublishedApi @PublishedApi
@SymbolName("Kotlin_Interop_CreateObjCObjectHolder") @GCUnsafeCall("Kotlin_Interop_CreateObjCObjectHolder")
internal external fun createObjCObjectHolder(ptr: NativePtr): Any? internal external fun createObjCObjectHolder(ptr: NativePtr): Any?
// Objective-C runtime: // Objective-C runtime:
@SymbolName("objc_retainAutoreleaseReturnValue") @GCUnsafeCall("objc_retainAutoreleaseReturnValue")
external fun objc_retainAutoreleaseReturnValue(ptr: NativePtr): NativePtr external fun objc_retainAutoreleaseReturnValue(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_objc_autoreleasePoolPush") @GCUnsafeCall("Kotlin_objc_autoreleasePoolPush")
external fun objc_autoreleasePoolPush(): NativePtr external fun objc_autoreleasePoolPush(): NativePtr
@SymbolName("Kotlin_objc_autoreleasePoolPop") @GCUnsafeCall("Kotlin_objc_autoreleasePoolPop")
external fun objc_autoreleasePoolPop(ptr: NativePtr) external fun objc_autoreleasePoolPop(ptr: NativePtr)
@SymbolName("Kotlin_objc_allocWithZone") @GCUnsafeCall("Kotlin_objc_allocWithZone")
@FilterExceptions @FilterExceptions
private external fun objc_allocWithZone(clazz: NativePtr): NativePtr private external fun objc_allocWithZone(clazz: NativePtr): NativePtr
@SymbolName("Kotlin_objc_retain") @GCUnsafeCall("Kotlin_objc_retain")
external fun objc_retain(ptr: NativePtr): NativePtr external fun objc_retain(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_objc_release") @GCUnsafeCall("Kotlin_objc_release")
external fun objc_release(ptr: NativePtr) external fun objc_release(ptr: NativePtr)
@SymbolName("Kotlin_objc_lookUpClass") @GCUnsafeCall("Kotlin_objc_lookUpClass")
external fun objc_lookUpClass(name: NativePtr): NativePtr external fun objc_lookUpClass(name: NativePtr): NativePtr
@@ -6,6 +6,7 @@
package kotlinx.cinterop package kotlinx.cinterop
import kotlin.native.internal.KClassImpl import kotlin.native.internal.KClassImpl
import kotlin.native.internal.GCUnsafeCall
import kotlin.reflect.KClass import kotlin.reflect.KClass
/** /**
@@ -34,8 +35,8 @@ fun getOriginalKotlinClass(objCProtocol: ObjCProtocol): KClass<*>? {
return KClassImpl<Any>(typeInfo) return KClassImpl<Any>(typeInfo)
} }
@SymbolName("Kotlin_ObjCInterop_getTypeInfoForClass") @GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForClass")
private external fun getTypeInfoForClass(ptr: NativePtr): NativePtr private external fun getTypeInfoForClass(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_ObjCInterop_getTypeInfoForProtocol") @GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForProtocol")
private external fun getTypeInfoForProtocol(ptr: NativePtr): NativePtr private external fun getTypeInfoForProtocol(ptr: NativePtr): NativePtr
@@ -61,9 +61,9 @@ internal fun getCoroutineSuspended(): Any = COROUTINE_SUSPENDED
internal fun interceptedContinuation(continuation: Continuation<Any?>): Continuation<Any?> = continuation.intercepted() internal fun interceptedContinuation(continuation: Continuation<Any?>): Continuation<Any?> = continuation.intercepted()
@FilterExceptions @FilterExceptions
@SymbolName("Kotlin_ObjCExport_runCompletionSuccess") @GCUnsafeCall("Kotlin_ObjCExport_runCompletionSuccess")
private external fun runCompletionSuccess(completionHolder: Any, result: Any?) private external fun runCompletionSuccess(completionHolder: Any, result: Any?)
@FilterExceptions @FilterExceptions
@SymbolName("Kotlin_ObjCExport_runCompletionFailure") @GCUnsafeCall("Kotlin_ObjCExport_runCompletionFailure")
private external fun runCompletionFailure(completionHolder: Any, exception: Throwable, exceptionTypes: NativePtr) private external fun runCompletionFailure(completionHolder: Any, exception: Throwable, exceptionTypes: NativePtr)
@@ -20,10 +20,10 @@ internal class NSArrayAsKList : AbstractList<Any?>(), ObjCObjectWrapper {
override val size: Int get() = getSize() override val size: Int get() = getSize()
@SymbolName("Kotlin_NSArrayAsKList_getSize") @GCUnsafeCall("Kotlin_NSArrayAsKList_getSize")
private external fun getSize(): Int private external fun getSize(): Int
@SymbolName("Kotlin_NSArrayAsKList_get") @GCUnsafeCall("Kotlin_NSArrayAsKList_get")
external override fun get(index: Int): Any? external override fun get(index: Int): Any?
} }
@@ -31,19 +31,19 @@ internal class NSMutableArrayAsKMutableList : AbstractMutableList<Any?>(), ObjCO
override val size: Int get() = getSize() override val size: Int get() = getSize()
@SymbolName("Kotlin_NSArrayAsKList_getSize") @GCUnsafeCall("Kotlin_NSArrayAsKList_getSize")
private external fun getSize(): Int private external fun getSize(): Int
@SymbolName("Kotlin_NSArrayAsKList_get") @GCUnsafeCall("Kotlin_NSArrayAsKList_get")
external override fun get(index: Int): Any? external override fun get(index: Int): Any?
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_add") @GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_add")
external override fun add(index: Int, element: Any?): Unit external override fun add(index: Int, element: Any?): Unit
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_removeAt") @GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_removeAt")
external override fun removeAt(index: Int): Any? external override fun removeAt(index: Int): Any?
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_set") @GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_set")
external override fun set(index: Int, element: Any?): Any? external override fun set(index: Int, element: Any?): Any?
} }
@@ -51,16 +51,16 @@ internal class NSSetAsKSet : AbstractSet<Any?>(), KonanSet<Any?>, ObjCObjectWrap
override val size: Int get() = getSize() override val size: Int get() = getSize()
@SymbolName("Kotlin_NSSetAsKSet_getSize") @GCUnsafeCall("Kotlin_NSSetAsKSet_getSize")
private external fun getSize(): Int private external fun getSize(): Int
@SymbolName("Kotlin_NSSetAsKSet_contains") @GCUnsafeCall("Kotlin_NSSetAsKSet_contains")
external override fun contains(element: Any?): Boolean external override fun contains(element: Any?): Boolean
@SymbolName("Kotlin_NSSetAsKSet_getElement") @GCUnsafeCall("Kotlin_NSSetAsKSet_getElement")
external override fun getElement(element: Any?): Any? external override fun getElement(element: Any?): Any?
@SymbolName("Kotlin_NSSetAsKSet_iterator") @GCUnsafeCall("Kotlin_NSSetAsKSet_iterator")
external override fun iterator(): Iterator<Any?> external override fun iterator(): Iterator<Any?>
} }
@@ -88,24 +88,24 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
override val size: Int get() = getSize() override val size: Int get() = getSize()
@SymbolName("Kotlin_NSDictionaryAsKMap_getSize") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_getSize")
private external fun getSize(): Int private external fun getSize(): Int
override fun isEmpty(): Boolean = (size == 0) override fun isEmpty(): Boolean = (size == 0)
@SymbolName("Kotlin_NSDictionaryAsKMap_containsKey") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsKey")
override external fun containsKey(key: Any?): Boolean override external fun containsKey(key: Any?): Boolean
@SymbolName("Kotlin_NSDictionaryAsKMap_containsValue") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsValue")
override external fun containsValue(value: Any?): Boolean override external fun containsValue(value: Any?): Boolean
@SymbolName("Kotlin_NSDictionaryAsKMap_get") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_get")
external override operator fun get(key: Any?): Any? external override operator fun get(key: Any?): Any?
@SymbolName("Kotlin_NSDictionaryAsKMap_getOrThrowConcurrentModification") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_getOrThrowConcurrentModification")
private external fun getOrThrowConcurrentModification(key: Any?): Any? private external fun getOrThrowConcurrentModification(key: Any?): Any?
@SymbolName("Kotlin_NSDictionaryAsKMap_containsEntry") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsEntry")
private external fun containsEntry(key: Any?, value: Any?): Boolean private external fun containsEntry(key: Any?, value: Any?): Boolean
// Views // Views
@@ -115,7 +115,7 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
override val entries: Set<Map.Entry<Any?, Any?>> get() = this.Entries() override val entries: Set<Map.Entry<Any?, Any?>> get() = this.Entries()
@SymbolName("Kotlin_NSDictionaryAsKMap_keyIterator") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_keyIterator")
private external fun keyIterator(): Iterator<Any?> private external fun keyIterator(): Iterator<Any?>
private inner class Keys : AbstractSet<Any?>() { private inner class Keys : AbstractSet<Any?>() {
@@ -127,7 +127,7 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
override fun contains(element: Any?): Boolean = this@NSDictionaryAsKMap.containsKey(element) override fun contains(element: Any?): Boolean = this@NSDictionaryAsKMap.containsKey(element)
} }
@SymbolName("Kotlin_NSDictionaryAsKMap_valueIterator") @GCUnsafeCall("Kotlin_NSDictionaryAsKMap_valueIterator")
private external fun valueIterator(): Iterator<Any?> private external fun valueIterator(): Iterator<Any?>
private inner class Values : AbstractCollection<Any?>() { private inner class Values : AbstractCollection<Any?>() {
@@ -179,7 +179,7 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
internal class NSEnumeratorAsKIterator : AbstractIterator<Any?>() { internal class NSEnumeratorAsKIterator : AbstractIterator<Any?>() {
@SymbolName("Kotlin_NSEnumeratorAsKIterator_computeNext") @GCUnsafeCall("Kotlin_NSEnumeratorAsKIterator_computeNext")
override external fun computeNext() override external fun computeNext()
@ExportForCppRuntime @ExportForCppRuntime
@@ -279,7 +279,7 @@ class ObjCErrorException(
} }
@PublishedApi @PublishedApi
@SymbolName("Kotlin_ObjCExport_trapOnUndeclaredException") @GCUnsafeCall("Kotlin_ObjCExport_trapOnUndeclaredException")
@ExportForCppRuntime @ExportForCppRuntime
internal external fun trapOnUndeclaredException(exception: Throwable) internal external fun trapOnUndeclaredException(exception: Throwable)