[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
import kotlin.native.*
import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.*
import kotlinx.cinterop.*
typealias Arena = Int
@@ -28,15 +28,15 @@ typealias Pointer = Int
* @Retain annotation is required to preserve functions from internalization and DCE.
*/
@RetainForTarget("wasm32")
@SymbolName("Konan_js_allocateArena")
@GCUnsafeCall("Konan_js_allocateArena")
external public fun allocateArena(): Arena
@RetainForTarget("wasm32")
@SymbolName("Konan_js_freeArena")
@GCUnsafeCall("Konan_js_freeArena")
external public fun freeArena(arena: Arena)
@RetainForTarget("wasm32")
@SymbolName("Konan_js_pushIntToArena")
@GCUnsafeCall("Konan_js_pushIntToArena")
external public fun pushIntToArena(arena: Arena, value: Int)
const val upperWord = 0xffffffff.toLong() shl 32
@@ -50,15 +50,15 @@ fun doubleLower(value: Double): Int =
(value.toBits() and 0x00000000ffffffff) .toInt()
@RetainForTarget("wasm32")
@SymbolName("ReturnSlot_getDouble")
@GCUnsafeCall("ReturnSlot_getDouble")
external public fun ReturnSlot_getDouble(): Double
@RetainForTarget("wasm32")
@SymbolName("Kotlin_String_utf16pointer")
@GCUnsafeCall("Kotlin_String_utf16pointer")
external public fun stringPointer(message: String): Pointer
@RetainForTarget("wasm32")
@SymbolName("Kotlin_String_utf16length")
@GCUnsafeCall("Kotlin_String_utf16length")
external public fun stringLengthBytes(message: String): Int
typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
@@ -105,19 +105,19 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
}
@RetainForTarget("wasm32")
@SymbolName("Konan_js_getInt")
@GCUnsafeCall("Konan_js_getInt")
external public fun getInt(arena: Arena, obj: Object, propertyPtr: Pointer, propertyLen: Int): Int;
@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;
@RetainForTarget("wasm32")
@SymbolName("Konan_js_setFunction")
@GCUnsafeCall("Konan_js_setFunction")
external public fun setFunction(arena: Arena, obj: Object, propertyName: Pointer, propertyLength: Int , function: Int)
@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 )
fun setter(obj: JsValue, property: String, string: String) {
@@ -5,6 +5,7 @@
package kotlinx.cinterop
import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.GCUnsafeCall
public class ForeignException internal constructor(val nativeException: Any?): Exception() {
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.
@SymbolName("Kotlin_ObjCExport_ExceptionDetails")
@GCUnsafeCall("Kotlin_ObjCExport_ExceptionDetails")
private external fun kotlin_ObjCExport_ExceptionDetails(nativeException: Any): String?
}
@@ -18,11 +18,7 @@
package kotlinx.cinterop
import kotlin.native.*
import kotlin.native.internal.ExportTypeInfo
import kotlin.native.internal.ExportForCppRuntime
import kotlin.native.internal.TypedIntrinsic
import kotlin.native.internal.IntrinsicType
import kotlin.native.internal.FilterExceptions
import kotlin.native.internal.*
interface 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)
// 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?
@ExportForCppRuntime
inline fun <T : Any> interpretObjCPointer(objcPtr: NativePtr): T = interpretObjCPointerOrNull<T>(objcPtr)!!
@SymbolName("Kotlin_Interop_refToObjC")
@GCUnsafeCall("Kotlin_Interop_refToObjC")
external fun Any?.objcPtr(): NativePtr
@SymbolName("Kotlin_Interop_createKotlinObjectHolder")
@GCUnsafeCall("Kotlin_Interop_createKotlinObjectHolder")
external fun createKotlinObjectHolder(any: Any?): NativePtr
// 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
@SymbolName("Kotlin_Interop_unwrapKotlinObjectHolder")
@GCUnsafeCall("Kotlin_Interop_unwrapKotlinObjectHolder")
external internal fun unwrapKotlinObjectHolderImpl(ptr: NativePtr): Any
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() {
@SymbolName("Konan_ObjCInterop_getWeakReference")
@GCUnsafeCall("Konan_ObjCInterop_getWeakReference")
external override fun get(): Any?
}
@SymbolName("Konan_ObjCInterop_initWeakReference")
@GCUnsafeCall("Konan_ObjCInterop_initWeakReference")
private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr)
@kotlin.native.internal.ExportForCppRuntime internal fun makeObjCWeakReferenceImpl(objcPtr: NativePtr): ObjCWeakReferenceImpl {
@@ -191,37 +187,37 @@ private external fun ObjCWeakReferenceImpl.init(objcPtr: NativePtr)
// Konan runtme:
@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
@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?
@PublishedApi
@SymbolName("Kotlin_Interop_CreateObjCObjectHolder")
@GCUnsafeCall("Kotlin_Interop_CreateObjCObjectHolder")
internal external fun createObjCObjectHolder(ptr: NativePtr): Any?
// Objective-C runtime:
@SymbolName("objc_retainAutoreleaseReturnValue")
@GCUnsafeCall("objc_retainAutoreleaseReturnValue")
external fun objc_retainAutoreleaseReturnValue(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_objc_autoreleasePoolPush")
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPush")
external fun objc_autoreleasePoolPush(): NativePtr
@SymbolName("Kotlin_objc_autoreleasePoolPop")
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPop")
external fun objc_autoreleasePoolPop(ptr: NativePtr)
@SymbolName("Kotlin_objc_allocWithZone")
@GCUnsafeCall("Kotlin_objc_allocWithZone")
@FilterExceptions
private external fun objc_allocWithZone(clazz: NativePtr): NativePtr
@SymbolName("Kotlin_objc_retain")
@GCUnsafeCall("Kotlin_objc_retain")
external fun objc_retain(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_objc_release")
@GCUnsafeCall("Kotlin_objc_release")
external fun objc_release(ptr: NativePtr)
@SymbolName("Kotlin_objc_lookUpClass")
@GCUnsafeCall("Kotlin_objc_lookUpClass")
external fun objc_lookUpClass(name: NativePtr): NativePtr
@@ -6,6 +6,7 @@
package kotlinx.cinterop
import kotlin.native.internal.KClassImpl
import kotlin.native.internal.GCUnsafeCall
import kotlin.reflect.KClass
/**
@@ -34,8 +35,8 @@ fun getOriginalKotlinClass(objCProtocol: ObjCProtocol): KClass<*>? {
return KClassImpl<Any>(typeInfo)
}
@SymbolName("Kotlin_ObjCInterop_getTypeInfoForClass")
@GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForClass")
private external fun getTypeInfoForClass(ptr: NativePtr): NativePtr
@SymbolName("Kotlin_ObjCInterop_getTypeInfoForProtocol")
@GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForProtocol")
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()
@FilterExceptions
@SymbolName("Kotlin_ObjCExport_runCompletionSuccess")
@GCUnsafeCall("Kotlin_ObjCExport_runCompletionSuccess")
private external fun runCompletionSuccess(completionHolder: Any, result: Any?)
@FilterExceptions
@SymbolName("Kotlin_ObjCExport_runCompletionFailure")
@GCUnsafeCall("Kotlin_ObjCExport_runCompletionFailure")
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()
@SymbolName("Kotlin_NSArrayAsKList_getSize")
@GCUnsafeCall("Kotlin_NSArrayAsKList_getSize")
private external fun getSize(): Int
@SymbolName("Kotlin_NSArrayAsKList_get")
@GCUnsafeCall("Kotlin_NSArrayAsKList_get")
external override fun get(index: Int): Any?
}
@@ -31,19 +31,19 @@ internal class NSMutableArrayAsKMutableList : AbstractMutableList<Any?>(), ObjCO
override val size: Int get() = getSize()
@SymbolName("Kotlin_NSArrayAsKList_getSize")
@GCUnsafeCall("Kotlin_NSArrayAsKList_getSize")
private external fun getSize(): Int
@SymbolName("Kotlin_NSArrayAsKList_get")
@GCUnsafeCall("Kotlin_NSArrayAsKList_get")
external override fun get(index: Int): Any?
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_add")
@GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_add")
external override fun add(index: Int, element: Any?): Unit
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_removeAt")
@GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_removeAt")
external override fun removeAt(index: Int): Any?
@SymbolName("Kotlin_NSMutableArrayAsKMutableList_set")
@GCUnsafeCall("Kotlin_NSMutableArrayAsKMutableList_set")
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()
@SymbolName("Kotlin_NSSetAsKSet_getSize")
@GCUnsafeCall("Kotlin_NSSetAsKSet_getSize")
private external fun getSize(): Int
@SymbolName("Kotlin_NSSetAsKSet_contains")
@GCUnsafeCall("Kotlin_NSSetAsKSet_contains")
external override fun contains(element: Any?): Boolean
@SymbolName("Kotlin_NSSetAsKSet_getElement")
@GCUnsafeCall("Kotlin_NSSetAsKSet_getElement")
external override fun getElement(element: Any?): Any?
@SymbolName("Kotlin_NSSetAsKSet_iterator")
@GCUnsafeCall("Kotlin_NSSetAsKSet_iterator")
external override fun iterator(): Iterator<Any?>
}
@@ -88,24 +88,24 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
override val size: Int get() = getSize()
@SymbolName("Kotlin_NSDictionaryAsKMap_getSize")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_getSize")
private external fun getSize(): Int
override fun isEmpty(): Boolean = (size == 0)
@SymbolName("Kotlin_NSDictionaryAsKMap_containsKey")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsKey")
override external fun containsKey(key: Any?): Boolean
@SymbolName("Kotlin_NSDictionaryAsKMap_containsValue")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsValue")
override external fun containsValue(value: Any?): Boolean
@SymbolName("Kotlin_NSDictionaryAsKMap_get")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_get")
external override operator fun get(key: Any?): Any?
@SymbolName("Kotlin_NSDictionaryAsKMap_getOrThrowConcurrentModification")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_getOrThrowConcurrentModification")
private external fun getOrThrowConcurrentModification(key: Any?): Any?
@SymbolName("Kotlin_NSDictionaryAsKMap_containsEntry")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_containsEntry")
private external fun containsEntry(key: Any?, value: Any?): Boolean
// Views
@@ -115,7 +115,7 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
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 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)
}
@SymbolName("Kotlin_NSDictionaryAsKMap_valueIterator")
@GCUnsafeCall("Kotlin_NSDictionaryAsKMap_valueIterator")
private external fun valueIterator(): Iterator<Any?>
private inner class Values : AbstractCollection<Any?>() {
@@ -179,7 +179,7 @@ internal class NSDictionaryAsKMap : Map<Any?, Any?>, ObjCObjectWrapper {
internal class NSEnumeratorAsKIterator : AbstractIterator<Any?>() {
@SymbolName("Kotlin_NSEnumeratorAsKIterator_computeNext")
@GCUnsafeCall("Kotlin_NSEnumeratorAsKIterator_computeNext")
override external fun computeNext()
@ExportForCppRuntime
@@ -279,7 +279,7 @@ class ObjCErrorException(
}
@PublishedApi
@SymbolName("Kotlin_ObjCExport_trapOnUndeclaredException")
@GCUnsafeCall("Kotlin_ObjCExport_trapOnUndeclaredException")
@ExportForCppRuntime
internal external fun trapOnUndeclaredException(exception: Throwable)