Explicitly declare stability levels of declarations in kotlinx.cinterop package
* @ExperimentalForeignApi for all declarations that operate on
unmanaged memory (i.e. pointers and references)
* @BetaInteropApi for the rest of the interoperability declarations,
namely Swift/CInterop-specific interfaces and convenience-functions
### Implementation details
* Some typealiases are not marked explicitly because it crashes the compiler,
yet their experimentality is properly propagated
* License header is adjusted where it previously had been existing
* Deprecated with ERROR interop declarations that are deprecated for more than
two years are removed
* WASM target interop declarations are deprecated
* Deliberately make Boolean.toByte and Byte.toBoolean foreign-experimental to scare
people away
^KT-57728 fixed
Merge-request: KT-MR-9788
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
committed by
Space Team
parent
82611ad124
commit
f4e8ae5191
@@ -31,6 +31,7 @@ fun FileWriter.generateAllocWithValue(type: PrimitiveInteropType) {
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : $typeName> NativePlacement.alloc(value: T): ${typeName}VarOf<T> =
|
public fun <T : $typeName> NativePlacement.alloc(value: T): ${typeName}VarOf<T> =
|
||||||
alloc<${typeName}VarOf<T>> { this.value = value }
|
alloc<${typeName}VarOf<T>> { this.value = value }
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the LICENSE file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.jetbrains.kotlin.tools.lib
|
import org.jetbrains.kotlin.tools.lib
|
||||||
@@ -176,7 +165,12 @@ val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
|
|||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs += listOf("-Xskip-prerelease-check")
|
freeCompilerArgs += listOf(
|
||||||
|
"-Xskip-prerelease-check",
|
||||||
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
||||||
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION") // RetainForTarget
|
@file:Suppress("DEPRECATION", "TYPEALIAS_EXPANSION_DEPRECATION") // Everything is scheduled for removal
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlinx.wasm.jsinterop
|
package kotlinx.wasm.jsinterop
|
||||||
|
|
||||||
@@ -22,49 +23,66 @@ import kotlin.native.*
|
|||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
typealias Arena = Int
|
typealias Arena = Int
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
typealias Object = Int
|
typealias Object = Int
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
typealias Pointer = Int
|
typealias Pointer = Int
|
||||||
|
|
||||||
|
private const val WASM_TARGET_IS_DEPRECATED = "K/N WASM target and all related API is deprecated for removal. " +
|
||||||
|
"See https://blog.jetbrains.com/kotlin/2023/02/update-regarding-kotlin-native-targets for additional details"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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")
|
||||||
@GCUnsafeCall("Konan_js_allocateArena")
|
@GCUnsafeCall("Konan_js_allocateArena")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
external public fun allocateArena(): Arena
|
external public fun allocateArena(): Arena
|
||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@GCUnsafeCall("Konan_js_freeArena")
|
@GCUnsafeCall("Konan_js_freeArena")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
external public fun freeArena(arena: Arena)
|
external public fun freeArena(arena: Arena)
|
||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@GCUnsafeCall("Konan_js_pushIntToArena")
|
@GCUnsafeCall("Konan_js_pushIntToArena")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
external public fun pushIntToArena(arena: Arena, value: Int)
|
external public fun pushIntToArena(arena: Arena, value: Int)
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
const val upperWord = 0xffffffff.toLong() shl 32
|
const val upperWord = 0xffffffff.toLong() shl 32
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun doubleUpper(value: Double): Int =
|
fun doubleUpper(value: Double): Int =
|
||||||
((value.toBits() and upperWord) ushr 32) .toInt()
|
((value.toBits() and upperWord) ushr 32) .toInt()
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun doubleLower(value: Double): Int =
|
fun doubleLower(value: Double): Int =
|
||||||
(value.toBits() and 0x00000000ffffffff) .toInt()
|
(value.toBits() and 0x00000000ffffffff) .toInt()
|
||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@GCUnsafeCall("ReturnSlot_getDouble")
|
@GCUnsafeCall("ReturnSlot_getDouble")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
external public fun ReturnSlot_getDouble(): Double
|
external public fun ReturnSlot_getDouble(): Double
|
||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@GCUnsafeCall("Kotlin_String_utf16pointer")
|
@GCUnsafeCall("Kotlin_String_utf16pointer")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
external public fun stringPointer(message: String): Pointer
|
external public fun stringPointer(message: String): Pointer
|
||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
@GCUnsafeCall("Kotlin_String_utf16length")
|
@GCUnsafeCall("Kotlin_String_utf16length")
|
||||||
external public fun stringLengthBytes(message: String): Int
|
external public fun stringLengthBytes(message: String): Int
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
|
typealias KtFunction <R> = ((ArrayList<JsValue>)->R)
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun <R> wrapFunction(func: KtFunction<R>): Int {
|
fun <R> wrapFunction(func: KtFunction<R>): Int {
|
||||||
val ptr: Long = StableRef.create(func).asCPointer().toLong()
|
val ptr: Long = StableRef.create(func).asCPointer().toLong()
|
||||||
return ptr.toInt() // TODO: LP64 unsafe.
|
return ptr.toInt() // TODO: LP64 unsafe.
|
||||||
@@ -72,6 +90,7 @@ fun <R> wrapFunction(func: KtFunction<R>): Int {
|
|||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@ExportForCppRuntime("Konan_js_runLambda")
|
@ExportForCppRuntime("Konan_js_runLambda")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int {
|
fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int {
|
||||||
val arguments = arrayListOf<JsValue>()
|
val arguments = arrayListOf<JsValue>()
|
||||||
for (i in 0 until argumentsArenaSize) {
|
for (i in 0 until argumentsArenaSize) {
|
||||||
@@ -87,6 +106,7 @@ fun runLambda(pointer: Int, argumentsArena: Arena, argumentsArenaSize: Int): Int
|
|||||||
return result.index
|
return result.index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
open class JsValue(val arena: Arena, val index: Object) {
|
open class JsValue(val arena: Arena, val index: Object) {
|
||||||
fun getInt(property: String): Int {
|
fun getInt(property: String): Int {
|
||||||
return getInt(ArenaManager.currentArena, index, stringPointer(property), stringLengthBytes(property))
|
return getInt(ArenaManager.currentArena, index, stringPointer(property), stringLengthBytes(property))
|
||||||
@@ -96,6 +116,7 @@ open class JsValue(val arena: Arena, val index: Object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
||||||
constructor(jsValue: JsValue): this(jsValue.arena, jsValue.index)
|
constructor(jsValue: JsValue): this(jsValue.arena, jsValue.index)
|
||||||
operator fun get(index: Int): JsValue {
|
operator fun get(index: Int): JsValue {
|
||||||
@@ -108,37 +129,46 @@ open class JsArray(arena: Arena, index: Object): JsValue(arena, index) {
|
|||||||
|
|
||||||
@RetainForTarget("wasm32")
|
@RetainForTarget("wasm32")
|
||||||
@GCUnsafeCall("Konan_js_getInt")
|
@GCUnsafeCall("Konan_js_getInt")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
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")
|
||||||
@GCUnsafeCall("Konan_js_getProperty")
|
@GCUnsafeCall("Konan_js_getProperty")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
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")
|
||||||
@GCUnsafeCall("Konan_js_setFunction")
|
@GCUnsafeCall("Konan_js_setFunction")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
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")
|
||||||
@GCUnsafeCall("Konan_js_setString")
|
@GCUnsafeCall("Konan_js_setString")
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
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 )
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun setter(obj: JsValue, property: String, string: String) {
|
fun setter(obj: JsValue, property: String, string: String) {
|
||||||
setString(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), stringPointer(string), stringLengthBytes(string))
|
setString(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), stringPointer(string), stringLengthBytes(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun setter(obj: JsValue, property: String, lambda: KtFunction<Unit>) {
|
fun setter(obj: JsValue, property: String, lambda: KtFunction<Unit>) {
|
||||||
val pointer = wrapFunction(lambda);
|
val pointer = wrapFunction(lambda);
|
||||||
setFunction(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), pointer)
|
setFunction(obj.arena, obj.index, stringPointer(property), stringLengthBytes(property), pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun JsValue.setter(property: String, lambda: KtFunction<Unit>) {
|
fun JsValue.setter(property: String, lambda: KtFunction<Unit>) {
|
||||||
setter(this, property, lambda)
|
setter(this, property, lambda)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
fun JsValue.setter(property: String, string: String) {
|
fun JsValue.setter(property: String, string: String) {
|
||||||
setter(this, property, string)
|
setter(this, property, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(WASM_TARGET_IS_DEPRECATED, level = DeprecationLevel.WARNING)
|
||||||
object ArenaManager {
|
object ArenaManager {
|
||||||
val globalArena = allocateArena()
|
val globalArena = allocateArena()
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.jetbrains.kotlin.tools.lib
|
import org.jetbrains.kotlin.tools.lib
|
||||||
import org.jetbrains.kotlin.tools.solib
|
import org.jetbrains.kotlin.tools.solib
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
@@ -64,10 +54,13 @@ dependencies {
|
|||||||
|
|
||||||
sourceSets.main.get().java.srcDir("src/jvm/kotlin")
|
sourceSets.main.get().java.srcDir("src/jvm/kotlin")
|
||||||
|
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs += listOf(
|
freeCompilerArgs += listOf(
|
||||||
"-opt-in=kotlin.ExperimentalUnsignedTypes",
|
"-opt-in=kotlin.ExperimentalUnsignedTypes",
|
||||||
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
||||||
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
||||||
"-Xskip-prerelease-check"
|
"-Xskip-prerelease-check"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,11 +8,52 @@ package kotlinx.cinterop
|
|||||||
/**
|
/**
|
||||||
* Marker for declarations that depend on numeric types of different bit width on at least two platforms.
|
* Marker for declarations that depend on numeric types of different bit width on at least two platforms.
|
||||||
*
|
*
|
||||||
* @param actualPlatformTypes: Contains platform types represented as `{konanTarget}: {type fqn}`
|
* @param actualPlatformTypes Contains platform types represented as `{konanTarget}: {type fqn}`
|
||||||
* e.g. ["linux_x64: kotlin.Int", "linux_arm64: kotlin.Long"]
|
* e.g. ["linux_x64: kotlin.Int", "linux_arm64: kotlin.Long"]
|
||||||
*/
|
*/
|
||||||
@Suppress("unused") // Is emitted by the Commonizer
|
@Suppress("unused") // Is emitted by the Commonizer
|
||||||
@Target(AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
@Target(AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||||
annotation class UnsafeNumber(val actualPlatformTypes: Array<String>)
|
public annotation class UnsafeNumber(val actualPlatformTypes: Array<String>)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks Objective-C and Swift interoperability API as Beta.
|
||||||
|
*
|
||||||
|
* The marked API has official Beta stability level, is considered to be a vital part of Kotlin/Native
|
||||||
|
* and Kotlin Multiplatform, and is evolved in a backward-compatible manner with the proper migration paths for incompatible changes.
|
||||||
|
*
|
||||||
|
* It may partially lack the concise semantics, documentation, and API to interoperate with Swift and Objective-C features
|
||||||
|
* that do not have a direct Kotlin counterpart.
|
||||||
|
*
|
||||||
|
* This API is recommended to be used for interoperability purposes, but with the API availability scope confined and narrowed down.
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY,
|
||||||
|
AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||||
|
public annotation class BetaInteropApi
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks foreign-memory-related API as experimental.
|
||||||
|
*
|
||||||
|
* Foreign API includes all operations and classifiers that are required for operating with
|
||||||
|
* unmanaged and foreign memory, including but not limited to such declarations as [CPointer], [CPointed], [StableRef], and `Pinned`.
|
||||||
|
*
|
||||||
|
* Such API is considered experimental and has the following known limitations and caveats:
|
||||||
|
* - It is either undocumented or lacks extensive and sound description.
|
||||||
|
* - There is no clear behavioural semantics and explicit mapping between foreign (e.g. C-pointer) concepts
|
||||||
|
* and the corresponding foreign API (e.g. [CPointer]). Such declarations might have an unsound mapping.
|
||||||
|
* - There is no clear semantic difference between similar declarations.
|
||||||
|
* - It lacks best practices and cookbook-like recommendations.
|
||||||
|
*
|
||||||
|
* ABI and API compatibilities are provided on a best-effort basis.
|
||||||
|
* We also do provide a best-effort migration path for binary/source incompatible changes, including the proper deprecation
|
||||||
|
* cycle, migration path, and introducing replacements for the API rather than API breakage.
|
||||||
|
*
|
||||||
|
* This API is recommended to be used for interoperability purposes, but with the API availability scope confined and narrowed down.
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
|
||||||
|
public annotation class ExperimentalForeignApi
|
||||||
|
|||||||
@@ -1,275 +1,326 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("FINAL_UPPER_BOUND", "NOTHING_TO_INLINE")
|
@file:Suppress("FINAL_UPPER_BOUND", "NOTHING_TO_INLINE")
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Byte")
|
@JvmName("plus\$Byte")
|
||||||
inline operator fun <T : ByteVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : ByteVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 1)
|
interpretCPointer(this.rawValue + index * 1)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Byte")
|
@JvmName("plus\$Byte")
|
||||||
inline operator fun <T : ByteVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : ByteVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Byte")
|
@JvmName("get\$Byte")
|
||||||
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Byte")
|
@JvmName("set\$Byte")
|
||||||
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Byte")
|
@JvmName("get\$Byte")
|
||||||
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Byte")
|
@JvmName("set\$Byte")
|
||||||
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Byte> CPointer<ByteVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Short")
|
@JvmName("plus\$Short")
|
||||||
inline operator fun <T : ShortVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : ShortVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 2)
|
interpretCPointer(this.rawValue + index * 2)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Short")
|
@JvmName("plus\$Short")
|
||||||
inline operator fun <T : ShortVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : ShortVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Short")
|
@JvmName("get\$Short")
|
||||||
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Short")
|
@JvmName("set\$Short")
|
||||||
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Short")
|
@JvmName("get\$Short")
|
||||||
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Short")
|
@JvmName("set\$Short")
|
||||||
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Short> CPointer<ShortVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Int")
|
@JvmName("plus\$Int")
|
||||||
inline operator fun <T : IntVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : IntVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 4)
|
interpretCPointer(this.rawValue + index * 4)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Int")
|
@JvmName("plus\$Int")
|
||||||
inline operator fun <T : IntVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : IntVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Int")
|
@JvmName("get\$Int")
|
||||||
inline operator fun <T : Int> CPointer<IntVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Int> CPointer<IntVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Int")
|
@JvmName("set\$Int")
|
||||||
inline operator fun <T : Int> CPointer<IntVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Int> CPointer<IntVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Int")
|
@JvmName("get\$Int")
|
||||||
inline operator fun <T : Int> CPointer<IntVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Int> CPointer<IntVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Int")
|
@JvmName("set\$Int")
|
||||||
inline operator fun <T : Int> CPointer<IntVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Int> CPointer<IntVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Long")
|
@JvmName("plus\$Long")
|
||||||
inline operator fun <T : LongVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : LongVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 8)
|
interpretCPointer(this.rawValue + index * 8)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Long")
|
@JvmName("plus\$Long")
|
||||||
inline operator fun <T : LongVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : LongVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Long")
|
@JvmName("get\$Long")
|
||||||
inline operator fun <T : Long> CPointer<LongVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Long> CPointer<LongVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Long")
|
@JvmName("set\$Long")
|
||||||
inline operator fun <T : Long> CPointer<LongVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Long> CPointer<LongVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Long")
|
@JvmName("get\$Long")
|
||||||
inline operator fun <T : Long> CPointer<LongVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Long> CPointer<LongVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Long")
|
@JvmName("set\$Long")
|
||||||
inline operator fun <T : Long> CPointer<LongVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Long> CPointer<LongVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UByte")
|
@JvmName("plus\$UByte")
|
||||||
inline operator fun <T : UByteVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : UByteVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 1)
|
interpretCPointer(this.rawValue + index * 1)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UByte")
|
@JvmName("plus\$UByte")
|
||||||
inline operator fun <T : UByteVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : UByteVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$UByte")
|
@JvmName("get\$UByte")
|
||||||
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : UByte> CPointer<UByteVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UShort")
|
@JvmName("plus\$UShort")
|
||||||
inline operator fun <T : UShortVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : UShortVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 2)
|
interpretCPointer(this.rawValue + index * 2)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UShort")
|
@JvmName("plus\$UShort")
|
||||||
inline operator fun <T : UShortVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : UShortVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$UShort")
|
@JvmName("get\$UShort")
|
||||||
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$UShort")
|
@JvmName("get\$UShort")
|
||||||
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : UShort> CPointer<UShortVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UInt")
|
@JvmName("plus\$UInt")
|
||||||
inline operator fun <T : UIntVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : UIntVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 4)
|
interpretCPointer(this.rawValue + index * 4)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$UInt")
|
@JvmName("plus\$UInt")
|
||||||
inline operator fun <T : UIntVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : UIntVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$UInt")
|
@JvmName("get\$UInt")
|
||||||
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$UInt")
|
@JvmName("get\$UInt")
|
||||||
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : UInt> CPointer<UIntVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$ULong")
|
@JvmName("plus\$ULong")
|
||||||
inline operator fun <T : ULongVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : ULongVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 8)
|
interpretCPointer(this.rawValue + index * 8)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$ULong")
|
@JvmName("plus\$ULong")
|
||||||
inline operator fun <T : ULongVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : ULongVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$ULong")
|
@JvmName("get\$ULong")
|
||||||
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$ULong")
|
@JvmName("get\$ULong")
|
||||||
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : ULong> CPointer<ULongVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Float")
|
@JvmName("plus\$Float")
|
||||||
inline operator fun <T : FloatVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : FloatVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 4)
|
interpretCPointer(this.rawValue + index * 4)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Float")
|
@JvmName("plus\$Float")
|
||||||
inline operator fun <T : FloatVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : FloatVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Float")
|
@JvmName("get\$Float")
|
||||||
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Float")
|
@JvmName("set\$Float")
|
||||||
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Float")
|
@JvmName("get\$Float")
|
||||||
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Float")
|
@JvmName("set\$Float")
|
||||||
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Float> CPointer<FloatVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Double")
|
@JvmName("plus\$Double")
|
||||||
inline operator fun <T : DoubleVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
inline operator fun <T : DoubleVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * 8)
|
interpretCPointer(this.rawValue + index * 8)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("plus\$Double")
|
@JvmName("plus\$Double")
|
||||||
inline operator fun <T : DoubleVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
inline operator fun <T : DoubleVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Double")
|
@JvmName("get\$Double")
|
||||||
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.get(index: Int): T =
|
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.get(index: Int): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Double")
|
@JvmName("set\$Double")
|
||||||
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.set(index: Int, value: T) {
|
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.set(index: Int, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("get\$Double")
|
@JvmName("get\$Double")
|
||||||
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.get(index: Long): T =
|
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.get(index: Long): T =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@JvmName("set\$Double")
|
@JvmName("set\$Double")
|
||||||
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.set(index: Long, value: T) {
|
inline operator fun <T : Double> CPointer<DoubleVarOf<T>>.set(index: Long, value: T) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generated by:
|
/* Seva: Used to be generated by:
|
||||||
|
|
||||||
|
Seva: It probably means the reasoning of this API and is general applicability should be revisited
|
||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
@Deprecated("Use StableRef<T> instead", ReplaceWith("StableRef<T>"), DeprecationLevel.ERROR)
|
|
||||||
typealias StableObjPtr = StableRef<*>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a way to create a stable handle to any Kotlin object.
|
* This class provides a way to create a stable handle to any Kotlin object.
|
||||||
* After [converting to CPointer][asCPointer] it can be safely passed to native code e.g. to be received
|
* After [converting to CPointer][asCPointer] it can be safely passed to native code e.g. to be received
|
||||||
@@ -28,6 +14,7 @@ typealias StableObjPtr = StableRef<*>
|
|||||||
*/
|
*/
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@kotlin.jvm.JvmInline
|
@kotlin.jvm.JvmInline
|
||||||
|
@ExperimentalForeignApi
|
||||||
public value class StableRef<out T : Any> @PublishedApi internal constructor(
|
public value class StableRef<out T : Any> @PublishedApi internal constructor(
|
||||||
private val stablePtr: COpaquePointer
|
private val stablePtr: COpaquePointer
|
||||||
) {
|
) {
|
||||||
@@ -39,17 +26,7 @@ public value class StableRef<out T : Any> @PublishedApi internal constructor(
|
|||||||
*/
|
*/
|
||||||
fun <T : Any> create(any: T) = StableRef<T>(createStablePointer(any))
|
fun <T : Any> create(any: T) = StableRef<T>(createStablePointer(any))
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates [StableRef] from given raw value.
|
|
||||||
*
|
|
||||||
* @param value must be a [value] of some [StableRef]
|
|
||||||
*/
|
|
||||||
@Deprecated("Use CPointer<*>.asStableRef<T>() instead", ReplaceWith("ptr.asStableRef<T>()"),
|
|
||||||
DeprecationLevel.ERROR)
|
|
||||||
fun fromValue(value: COpaquePointer) = value.asStableRef<Any>()
|
|
||||||
}
|
}
|
||||||
@Deprecated("Use .asCPointer() instead", ReplaceWith("this.asCPointer()"), DeprecationLevel.ERROR)
|
|
||||||
val value: COpaquePointer get() = this.asCPointer()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the handle to C pointer.
|
* Converts the handle to C pointer.
|
||||||
@@ -75,4 +52,5 @@ public value class StableRef<out T : Any> @PublishedApi internal constructor(
|
|||||||
/**
|
/**
|
||||||
* Converts to [StableRef] this opaque pointer produced by [StableRef.asCPointer].
|
* Converts to [StableRef] this opaque pointer produced by [StableRef.asCPointer].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline fun <reified T : Any> CPointer<*>.asStableRef(): StableRef<T> = StableRef<T>(this).also { it.get() }
|
inline fun <reified T : Any> CPointer<*>.asStableRef(): StableRef<T> = StableRef<T>(this).also { it.get() }
|
||||||
|
|||||||
@@ -1,21 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
|
import kotlin.native.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entity which has an associated native pointer.
|
* The entity which has an associated native pointer.
|
||||||
* Subtypes are supposed to represent interpretations of the pointed data or code.
|
* Subtypes are supposed to represent interpretations of the pointed data or code.
|
||||||
@@ -24,12 +15,14 @@ package kotlinx.cinterop
|
|||||||
*
|
*
|
||||||
* TODO: the behavior of [equals], [hashCode] and [toString] differs on Native and JVM backends.
|
* TODO: the behavior of [equals], [hashCode] and [toString] differs on Native and JVM backends.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public open class NativePointed internal constructor(rawPtr: NonNullNativePtr) {
|
public open class NativePointed internal constructor(rawPtr: NonNullNativePtr) {
|
||||||
var rawPtr = rawPtr.toNativePtr()
|
var rawPtr = rawPtr.toNativePtr()
|
||||||
internal set
|
internal set
|
||||||
}
|
}
|
||||||
|
|
||||||
// `null` value of `NativePointed?` is mapped to `nativeNullPtr`.
|
// `null` value of `NativePointed?` is mapped to `nativeNullPtr`.
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val NativePointed?.rawPtr: NativePtr
|
public val NativePointed?.rawPtr: NativePtr
|
||||||
get() = if (this != null) this.rawPtr else nativeNullPtr
|
get() = if (this != null) this.rawPtr else nativeNullPtr
|
||||||
|
|
||||||
@@ -38,21 +31,27 @@ public val NativePointed?.rawPtr: NativePtr
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : NativePointed> interpretPointed(ptr: NativePtr): T = interpretNullablePointed<T>(ptr)!!
|
public inline fun <reified T : NativePointed> interpretPointed(ptr: NativePtr): T = interpretNullablePointed<T>(ptr)!!
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
private class OpaqueNativePointed(rawPtr: NativePtr) : NativePointed(rawPtr.toNonNull())
|
private class OpaqueNativePointed(rawPtr: NativePtr) : NativePointed(rawPtr.toNonNull())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun interpretOpaquePointed(ptr: NativePtr): NativePointed = interpretPointed<OpaqueNativePointed>(ptr)
|
public fun interpretOpaquePointed(ptr: NativePtr): NativePointed = interpretPointed<OpaqueNativePointed>(ptr)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun interpretNullableOpaquePointed(ptr: NativePtr): NativePointed? = interpretNullablePointed<OpaqueNativePointed>(ptr)
|
public fun interpretNullableOpaquePointed(ptr: NativePtr): NativePointed? = interpretNullablePointed<OpaqueNativePointed>(ptr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the interpretation of the pointed data or code.
|
* Changes the interpretation of the pointed data or code.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : NativePointed> NativePointed.reinterpret(): T = interpretPointed(this.rawPtr)
|
public inline fun <reified T : NativePointed> NativePointed.reinterpret(): T = interpretPointed(this.rawPtr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C data or code.
|
* C data or code.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CPointed(rawPtr: NativePtr) : NativePointed(rawPtr.toNonNull())
|
public abstract class CPointed(rawPtr: NativePtr) : NativePointed(rawPtr.toNonNull())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,9 +63,10 @@ public abstract class CPointed(rawPtr: NativePtr) : NativePointed(rawPtr.toNonNu
|
|||||||
* Passing [CValues] has nearly the same semantics as passing by value: the C function receives
|
* Passing [CValues] has nearly the same semantics as passing by value: the C function receives
|
||||||
* the pointer to the temporary copy of these values, and the caller can't observe the modifications to this copy.
|
* the pointer to the temporary copy of these values, and the caller can't observe the modifications to this copy.
|
||||||
* The copy is valid until the C function returns.
|
* The copy is valid until the C function returns.
|
||||||
* There are also other implementations of [CValuesRef] that provide temporary pointer,
|
* There are other implementations of [CValuesRef] that provide temporary pointer,
|
||||||
* e.g. Kotlin Native specific [refTo] functions to pass primitive arrays directly to native.
|
* e.g. Kotlin Native specific [refTo] functions to pass primitive arrays directly to native.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CValuesRef<T : CPointed> {
|
public abstract class CValuesRef<T : CPointed> {
|
||||||
/**
|
/**
|
||||||
* If this reference is [CPointer], returns this pointer, otherwise
|
* If this reference is [CPointer], returns this pointer, otherwise
|
||||||
@@ -79,6 +79,7 @@ public abstract class CValuesRef<T : CPointed> {
|
|||||||
* The (possibly empty) sequence of immutable C values.
|
* The (possibly empty) sequence of immutable C values.
|
||||||
* It is self-contained and doesn't depend on native memory.
|
* It is self-contained and doesn't depend on native memory.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CValues<T : CVariable> : CValuesRef<T>() {
|
public abstract class CValues<T : CVariable> : CValuesRef<T>() {
|
||||||
/**
|
/**
|
||||||
* Copies the values to [placement] and returns the pointer to the copy.
|
* Copies the values to [placement] and returns the pointer to the copy.
|
||||||
@@ -126,6 +127,7 @@ public abstract class CValues<T : CVariable> : CValuesRef<T>() {
|
|||||||
public abstract fun place(placement: CPointer<T>): CPointer<T>
|
public abstract fun place(placement: CPointer<T>): CPointer<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CVariable> CValues<T>.placeTo(scope: AutofreeScope) = this.getPointer(scope)
|
public fun <T : CVariable> CValues<T>.placeTo(scope: AutofreeScope) = this.getPointer(scope)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,11 +136,13 @@ public fun <T : CVariable> CValues<T>.placeTo(scope: AutofreeScope) = this.getPo
|
|||||||
*
|
*
|
||||||
* TODO: consider providing an adapter instead of subtyping [CValues].
|
* TODO: consider providing an adapter instead of subtyping [CValues].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CValue<T : CVariable> : CValues<T>()
|
public abstract class CValue<T : CVariable> : CValues<T>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C pointer.
|
* C pointer.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class CPointer<T : CPointed> internal constructor(@PublishedApi internal val value: NonNullNativePtr) : CValuesRef<T>() {
|
public class CPointer<T : CPointed> internal constructor(@PublishedApi internal val value: NonNullNativePtr) : CValuesRef<T>() {
|
||||||
|
|
||||||
// TODO: replace by [value].
|
// TODO: replace by [value].
|
||||||
@@ -165,6 +169,7 @@ public class CPointer<T : CPointed> internal constructor(@PublishedApi internal
|
|||||||
/**
|
/**
|
||||||
* Returns the pointer to this data or code.
|
* Returns the pointer to this data or code.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val <T : CPointed> T.ptr: CPointer<T>
|
public val <T : CPointed> T.ptr: CPointer<T>
|
||||||
get() = interpretCPointer(this.rawPtr)!!
|
get() = interpretCPointer(this.rawPtr)!!
|
||||||
|
|
||||||
@@ -173,32 +178,47 @@ public val <T : CPointed> T.ptr: CPointer<T>
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline val <reified T : CPointed> CPointer<T>.pointed: T
|
public inline val <reified T : CPointed> CPointer<T>.pointed: T
|
||||||
get() = interpretPointed<T>(this.rawValue)
|
get() = interpretPointed<T>(this.rawValue)
|
||||||
|
|
||||||
// `null` value of `CPointer?` is mapped to `nativeNullPtr`
|
// `null` value of `CPointer?` is mapped to `nativeNullPtr`
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val CPointer<*>?.rawValue: NativePtr
|
public val CPointer<*>?.rawValue: NativePtr
|
||||||
get() = if (this != null) this.rawValue else nativeNullPtr
|
get() = if (this != null) this.rawValue else nativeNullPtr
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> CPointer<*>.reinterpret(): CPointer<T> = interpretCPointer(this.rawValue)!!
|
public fun <T : CPointed> CPointer<*>.reinterpret(): CPointer<T> = interpretCPointer(this.rawValue)!!
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> CPointer<T>?.toLong() = this.rawValue.toLong()
|
public fun <T : CPointed> CPointer<T>?.toLong() = this.rawValue.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> Long.toCPointer(): CPointer<T>? = interpretCPointer(nativeNullPtr + this)
|
public fun <T : CPointed> Long.toCPointer(): CPointer<T>? = interpretCPointer(nativeNullPtr + this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [CPointed] without any specified interpretation.
|
* The [CPointed] without any specified interpretation.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class COpaque(rawPtr: NativePtr) : CPointed(rawPtr) // TODO: should it correspond to COpaquePointer?
|
public abstract class COpaque(rawPtr: NativePtr) : CPointed(rawPtr) // TODO: should it correspond to COpaquePointer?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pointer with an opaque type.
|
* The pointer with an opaque type.
|
||||||
*/
|
*/
|
||||||
public typealias COpaquePointer = CPointer<out CPointed> // FIXME
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
|
/*
|
||||||
|
* This typealias should be marked as @ExperimentalForeignApi
|
||||||
|
* but such marking starts crashing the compiler (due to typealias handling bug).
|
||||||
|
* We are not blocked by this behaviour because any declaration mentioning
|
||||||
|
* `COpaquePointer` will trigger `ExperimentalForeignApi` error due to typealias expansion
|
||||||
|
* in opt-in propagation mechanism.
|
||||||
|
*/
|
||||||
|
public typealias COpaquePointer = CPointer<out CPointed> // FIXME (the comment is about the typealias, not its opt-in annotation)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variable containing a [COpaquePointer].
|
* The variable containing a [COpaquePointer].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias COpaquePointerVar = CPointerVarOf<COpaquePointer>
|
public typealias COpaquePointerVar = CPointerVarOf<COpaquePointer>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,6 +227,7 @@ public typealias COpaquePointerVar = CPointerVarOf<COpaquePointer>
|
|||||||
* The non-abstract subclasses should represent the (complete) C data type and thus specify size and alignment.
|
* The non-abstract subclasses should represent the (complete) C data type and thus specify size and alignment.
|
||||||
* Each such subclass must have a companion object which is a [Type].
|
* Each such subclass must have a companion object which is a [Type].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CVariable(rawPtr: NativePtr) : CPointed(rawPtr) {
|
public abstract class CVariable(rawPtr: NativePtr) : CPointed(rawPtr) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,18 +248,22 @@ public abstract class CVariable(rawPtr: NativePtr) : CPointed(rawPtr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> sizeOf() = typeOf<T>().size
|
public inline fun <reified T : CVariable> sizeOf() = typeOf<T>().size
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> alignOf() = typeOf<T>().align
|
public inline fun <reified T : CVariable> alignOf() = typeOf<T>().align
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the member of this [CStructVar] which is located by given offset in bytes.
|
* Returns the member of this [CStructVar] which is located by given offset in bytes.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CPointed> CStructVar.memberAt(offset: Long): T {
|
public inline fun <reified T : CPointed> CStructVar.memberAt(offset: Long): T {
|
||||||
return interpretPointed<T>(this.rawPtr + offset)
|
return interpretPointed<T>(this.rawPtr + offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> CStructVar.arrayMemberAt(offset: Long): CArrayPointer<T> {
|
public inline fun <reified T : CVariable> CStructVar.arrayMemberAt(offset: Long): CArrayPointer<T> {
|
||||||
return interpretCPointer<T>(this.rawPtr + offset)!!
|
return interpretCPointer<T>(this.rawPtr + offset)!!
|
||||||
}
|
}
|
||||||
@@ -246,6 +271,7 @@ public inline fun <reified T : CVariable> CStructVar.arrayMemberAt(offset: Long)
|
|||||||
/**
|
/**
|
||||||
* The C struct-typed variable located in memory.
|
* The C struct-typed variable located in memory.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CStructVar(rawPtr: NativePtr) : CVariable(rawPtr) {
|
public abstract class CStructVar(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@@ -255,6 +281,7 @@ public abstract class CStructVar(rawPtr: NativePtr) : CVariable(rawPtr) {
|
|||||||
/**
|
/**
|
||||||
* The C primitive-typed variable located in memory.
|
* The C primitive-typed variable located in memory.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
sealed class CPrimitiveVar(rawPtr: NativePtr) : CVariable(rawPtr) {
|
sealed class CPrimitiveVar(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
// aligning by size is obviously enough
|
// aligning by size is obviously enough
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -267,11 +294,13 @@ public interface CEnum {
|
|||||||
public val value: Any
|
public val value: Any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class CEnumVar(rawPtr: NativePtr) : CPrimitiveVar(rawPtr)
|
public abstract class CEnumVar(rawPtr: NativePtr) : CPrimitiveVar(rawPtr)
|
||||||
|
|
||||||
// generics below are used for typedef support
|
// generics below are used for typedef support
|
||||||
// these classes are not supposed to be used directly, instead the typealiases are provided.
|
// these classes are not supposed to be used directly, instead the typealiases are provided.
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class BooleanVarOf<T : Boolean>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class BooleanVarOf<T : Boolean>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -279,6 +308,7 @@ public class BooleanVarOf<T : Boolean>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr
|
|||||||
companion object : Type(1)
|
companion object : Type(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class ByteVarOf<T : Byte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class ByteVarOf<T : Byte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -286,6 +316,7 @@ public class ByteVarOf<T : Byte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(1)
|
companion object : Type(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class ShortVarOf<T : Short>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class ShortVarOf<T : Short>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -293,6 +324,7 @@ public class ShortVarOf<T : Short>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(2)
|
companion object : Type(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class IntVarOf<T : Int>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class IntVarOf<T : Int>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -300,6 +332,7 @@ public class IntVarOf<T : Int>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(4)
|
companion object : Type(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class LongVarOf<T : Long>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class LongVarOf<T : Long>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -307,6 +340,7 @@ public class LongVarOf<T : Long>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(8)
|
companion object : Type(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class UByteVarOf<T : UByte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class UByteVarOf<T : UByte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -314,6 +348,7 @@ public class UByteVarOf<T : UByte>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(1)
|
companion object : Type(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class UShortVarOf<T : UShort>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class UShortVarOf<T : UShort>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -321,6 +356,7 @@ public class UShortVarOf<T : UShort>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr)
|
|||||||
companion object : Type(2)
|
companion object : Type(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class UIntVarOf<T : UInt>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class UIntVarOf<T : UInt>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -328,6 +364,7 @@ public class UIntVarOf<T : UInt>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(4)
|
companion object : Type(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class ULongVarOf<T : ULong>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class ULongVarOf<T : ULong>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -335,6 +372,7 @@ public class ULongVarOf<T : ULong>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(8)
|
companion object : Type(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class FloatVarOf<T : Float>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class FloatVarOf<T : Float>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -342,6 +380,7 @@ public class FloatVarOf<T : Float>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
|||||||
companion object : Type(4)
|
companion object : Type(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class DoubleVarOf<T : Double>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
public class DoubleVarOf<T : Double>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -349,18 +388,30 @@ public class DoubleVarOf<T : Double>(rawPtr: NativePtr) : CPrimitiveVar(rawPtr)
|
|||||||
companion object : Type(8)
|
companion object : Type(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias BooleanVar = BooleanVarOf<Boolean>
|
public typealias BooleanVar = BooleanVarOf<Boolean>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias ByteVar = ByteVarOf<Byte>
|
public typealias ByteVar = ByteVarOf<Byte>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias ShortVar = ShortVarOf<Short>
|
public typealias ShortVar = ShortVarOf<Short>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias IntVar = IntVarOf<Int>
|
public typealias IntVar = IntVarOf<Int>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias LongVar = LongVarOf<Long>
|
public typealias LongVar = LongVarOf<Long>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias UByteVar = UByteVarOf<UByte>
|
public typealias UByteVar = UByteVarOf<UByte>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias UShortVar = UShortVarOf<UShort>
|
public typealias UShortVar = UShortVarOf<UShort>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias UIntVar = UIntVarOf<UInt>
|
public typealias UIntVar = UIntVarOf<UInt>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias ULongVar = ULongVarOf<ULong>
|
public typealias ULongVar = ULongVarOf<ULong>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias FloatVar = FloatVarOf<Float>
|
public typealias FloatVar = FloatVarOf<Float>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias DoubleVar = DoubleVarOf<Double>
|
public typealias DoubleVar = DoubleVarOf<Double>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Boolean> BooleanVarOf<T>.value: T
|
public var <T : Boolean> BooleanVarOf<T>.value: T
|
||||||
get() {
|
get() {
|
||||||
@@ -369,47 +420,59 @@ public var <T : Boolean> BooleanVarOf<T>.value: T
|
|||||||
}
|
}
|
||||||
set(value) = nativeMemUtils.putByte(this, value.toByte())
|
set(value) = nativeMemUtils.putByte(this, value.toByte())
|
||||||
|
|
||||||
|
// TODO remove these boolean <-> byte declarations
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun Boolean.toByte(): Byte = if (this) 1 else 0
|
public inline fun Boolean.toByte(): Byte = if (this) 1 else 0
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun Byte.toBoolean() = (this.toInt() != 0)
|
public inline fun Byte.toBoolean() = (this.toInt() != 0)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Byte> ByteVarOf<T>.value: T
|
public var <T : Byte> ByteVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getByte(this) as T
|
get() = nativeMemUtils.getByte(this) as T
|
||||||
set(value) = nativeMemUtils.putByte(this, value)
|
set(value) = nativeMemUtils.putByte(this, value)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Short> ShortVarOf<T>.value: T
|
public var <T : Short> ShortVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getShort(this) as T
|
get() = nativeMemUtils.getShort(this) as T
|
||||||
set(value) = nativeMemUtils.putShort(this, value)
|
set(value) = nativeMemUtils.putShort(this, value)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Int> IntVarOf<T>.value: T
|
public var <T : Int> IntVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getInt(this) as T
|
get() = nativeMemUtils.getInt(this) as T
|
||||||
set(value) = nativeMemUtils.putInt(this, value)
|
set(value) = nativeMemUtils.putInt(this, value)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Long> LongVarOf<T>.value: T
|
public var <T : Long> LongVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getLong(this) as T
|
get() = nativeMemUtils.getLong(this) as T
|
||||||
set(value) = nativeMemUtils.putLong(this, value)
|
set(value) = nativeMemUtils.putLong(this, value)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : UByte> UByteVarOf<T>.value: T
|
public var <T : UByte> UByteVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getByte(this).toUByte() as T
|
get() = nativeMemUtils.getByte(this).toUByte() as T
|
||||||
set(value) = nativeMemUtils.putByte(this, value.toByte())
|
set(value) = nativeMemUtils.putByte(this, value.toByte())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : UShort> UShortVarOf<T>.value: T
|
public var <T : UShort> UShortVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getShort(this).toUShort() as T
|
get() = nativeMemUtils.getShort(this).toUShort() as T
|
||||||
set(value) = nativeMemUtils.putShort(this, value.toShort())
|
set(value) = nativeMemUtils.putShort(this, value.toShort())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : UInt> UIntVarOf<T>.value: T
|
public var <T : UInt> UIntVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getInt(this).toUInt() as T
|
get() = nativeMemUtils.getInt(this).toUInt() as T
|
||||||
set(value) = nativeMemUtils.putInt(this, value.toInt())
|
set(value) = nativeMemUtils.putInt(this, value.toInt())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : ULong> ULongVarOf<T>.value: T
|
public var <T : ULong> ULongVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getLong(this).toULong() as T
|
get() = nativeMemUtils.getLong(this).toULong() as T
|
||||||
@@ -417,17 +480,20 @@ public var <T : ULong> ULongVarOf<T>.value: T
|
|||||||
|
|
||||||
// TODO: ensure native floats have the appropriate binary representation
|
// TODO: ensure native floats have the appropriate binary representation
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Float> FloatVarOf<T>.value: T
|
public var <T : Float> FloatVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getFloat(this) as T
|
get() = nativeMemUtils.getFloat(this) as T
|
||||||
set(value) = nativeMemUtils.putFloat(this, value)
|
set(value) = nativeMemUtils.putFloat(this, value)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Double> DoubleVarOf<T>.value: T
|
public var <T : Double> DoubleVarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getDouble(this) as T
|
get() = nativeMemUtils.getDouble(this) as T
|
||||||
set(value) = nativeMemUtils.putDouble(this, value)
|
set(value) = nativeMemUtils.putDouble(this, value)
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class CPointerVarOf<T : CPointer<*>>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
public class CPointerVarOf<T : CPointer<*>>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@@ -437,11 +503,13 @@ public class CPointerVarOf<T : CPointer<*>>(rawPtr: NativePtr) : CVariable(rawPt
|
|||||||
/**
|
/**
|
||||||
* The C data variable containing the pointer to `T`.
|
* The C data variable containing the pointer to `T`.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias CPointerVar<T> = CPointerVarOf<CPointer<T>>
|
public typealias CPointerVar<T> = CPointerVarOf<CPointer<T>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of this variable.
|
* The value of this variable.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
public inline var <P : CPointer<*>> CPointerVarOf<P>.value: P?
|
public inline var <P : CPointer<*>> CPointerVarOf<P>.value: P?
|
||||||
get() = interpretCPointer<CPointed>(nativeMemUtils.getNativePtr(this)) as P?
|
get() = interpretCPointer<CPointed>(nativeMemUtils.getNativePtr(this)) as P?
|
||||||
@@ -452,12 +520,14 @@ public inline var <P : CPointer<*>> CPointerVarOf<P>.value: P?
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline var <reified T : CPointed, reified P : CPointer<T>> CPointerVarOf<P>.pointed: T?
|
public inline var <reified T : CPointed, reified P : CPointer<T>> CPointerVarOf<P>.pointed: T?
|
||||||
get() = this.value?.pointed
|
get() = this.value?.pointed
|
||||||
set(value) {
|
set(value) {
|
||||||
this.value = value?.ptr as P?
|
this.value = value?.ptr as P?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline operator fun <reified T : CVariable> CPointer<T>.get(index: Long): T {
|
public inline operator fun <reified T : CVariable> CPointer<T>.get(index: Long): T {
|
||||||
val offset = if (index == 0L) {
|
val offset = if (index == 0L) {
|
||||||
0L // optimization for JVM impl which uses reflection for now.
|
0L // optimization for JVM impl which uses reflection for now.
|
||||||
@@ -467,40 +537,50 @@ public inline operator fun <reified T : CVariable> CPointer<T>.get(index: Long):
|
|||||||
return interpretPointed(this.rawValue + offset)
|
return interpretPointed(this.rawValue + offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline operator fun <reified T : CVariable> CPointer<T>.get(index: Int): T = this.get(index.toLong())
|
public inline operator fun <reified T : CVariable> CPointer<T>.get(index: Int): T = this.get(index.toLong())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
@JvmName("plus\$CPointer")
|
@JvmName("plus\$CPointer")
|
||||||
public inline operator fun <T : CPointerVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
public inline operator fun <T : CPointerVarOf<*>> CPointer<T>?.plus(index: Long): CPointer<T>? =
|
||||||
interpretCPointer(this.rawValue + index * pointerSize)
|
interpretCPointer(this.rawValue + index * pointerSize)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
@JvmName("plus\$CPointer")
|
@JvmName("plus\$CPointer")
|
||||||
public inline operator fun <T : CPointerVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
public inline operator fun <T : CPointerVarOf<*>> CPointer<T>?.plus(index: Int): CPointer<T>? =
|
||||||
this + index.toLong()
|
this + index.toLong()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.get(index: Int): T? =
|
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.get(index: Int): T? =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.set(index: Int, value: T?) {
|
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.set(index: Int, value: T?) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.get(index: Long): T? =
|
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.get(index: Long): T? =
|
||||||
(this + index)!!.pointed.value
|
(this + index)!!.pointed.value
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.set(index: Long, value: T?) {
|
public inline operator fun <T : CPointer<*>> CPointer<CPointerVarOf<T>>.set(index: Long, value: T?) {
|
||||||
(this + index)!!.pointed.value = value
|
(this + index)!!.pointed.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias CArrayPointer<T> = CPointer<T>
|
public typealias CArrayPointer<T> = CPointer<T>
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias CArrayPointerVar<T> = CPointerVar<T>
|
public typealias CArrayPointerVar<T> = CPointerVar<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The C function.
|
* The C function.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class CFunction<T : Function<*>>(rawPtr: NativePtr) : CPointed(rawPtr)
|
public class CFunction<T : Function<*>>(rawPtr: NativePtr) : CPointed(rawPtr)
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public interface NativePlacement {
|
public interface NativePlacement {
|
||||||
|
|
||||||
public fun alloc(size: Long, align: Int): NativePointed
|
public fun alloc(size: Long, align: Int): NativePointed
|
||||||
@@ -23,21 +13,27 @@ public interface NativePlacement {
|
|||||||
public fun alloc(size: Int, align: Int): NativePointed = alloc(size.toLong(), align)
|
public fun alloc(size: Int, align: Int): NativePointed = alloc(size.toLong(), align)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public interface NativeFreeablePlacement : NativePlacement {
|
public interface NativeFreeablePlacement : NativePlacement {
|
||||||
public fun free(mem: NativePtr)
|
public fun free(mem: NativePtr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun NativeFreeablePlacement.free(pointer: CPointer<*>) = this.free(pointer.rawValue)
|
public fun NativeFreeablePlacement.free(pointer: CPointer<*>) = this.free(pointer.rawValue)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun NativeFreeablePlacement.free(pointed: NativePointed) = this.free(pointed.rawPtr)
|
public fun NativeFreeablePlacement.free(pointed: NativePointed) = this.free(pointed.rawPtr)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public object nativeHeap : NativeFreeablePlacement {
|
public object nativeHeap : NativeFreeablePlacement {
|
||||||
override fun alloc(size: Long, align: Int) = nativeMemUtils.alloc(size, align)
|
override fun alloc(size: Long, align: Int) = nativeMemUtils.alloc(size, align)
|
||||||
|
|
||||||
override fun free(mem: NativePtr) = nativeMemUtils.free(mem)
|
override fun free(mem: NativePtr) = nativeMemUtils.free(mem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
private typealias Deferred = () -> Unit
|
private typealias Deferred = () -> Unit
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public open class DeferScope {
|
public open class DeferScope {
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -65,10 +61,12 @@ public open class DeferScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public abstract class AutofreeScope : DeferScope(), NativePlacement {
|
public abstract class AutofreeScope : DeferScope(), NativePlacement {
|
||||||
abstract override fun alloc(size: Long, align: Int): NativePointed
|
abstract override fun alloc(size: Long, align: Int): NativePointed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public open class ArenaBase(private val parent: NativeFreeablePlacement = nativeHeap) : AutofreeScope() {
|
public open class ArenaBase(private val parent: NativeFreeablePlacement = nativeHeap) : AutofreeScope() {
|
||||||
|
|
||||||
private var lastChunk: NativePointed? = null
|
private var lastChunk: NativePointed? = null
|
||||||
@@ -97,6 +95,7 @@ public open class ArenaBase(private val parent: NativeFreeablePlacement = native
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class Arena(parent: NativeFreeablePlacement = nativeHeap) : ArenaBase(parent) {
|
public class Arena(parent: NativeFreeablePlacement = nativeHeap) : ArenaBase(parent) {
|
||||||
fun clear() = this.clearImpl()
|
fun clear() = this.clearImpl()
|
||||||
}
|
}
|
||||||
@@ -106,12 +105,14 @@ public class Arena(parent: NativeFreeablePlacement = nativeHeap) : ArenaBase(par
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.alloc(): T =
|
public inline fun <reified T : CVariable> NativePlacement.alloc(): T =
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
alloc(typeOf<T>()).reinterpret()
|
alloc(typeOf<T>()).reinterpret()
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ExperimentalForeignApi
|
||||||
internal fun NativePlacement.alloc(type: CVariable.Type): NativePointed =
|
internal fun NativePlacement.alloc(type: CVariable.Type): NativePointed =
|
||||||
alloc(type.size, type.align)
|
alloc(type.size, type.align)
|
||||||
|
|
||||||
@@ -120,6 +121,7 @@ internal fun NativePlacement.alloc(type: CVariable.Type): NativePointed =
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.alloc(initialize: T.() -> Unit): T =
|
public inline fun <reified T : CVariable> NativePlacement.alloc(initialize: T.() -> Unit): T =
|
||||||
alloc<T>().also { it.initialize() }
|
alloc<T>().also { it.initialize() }
|
||||||
|
|
||||||
@@ -128,6 +130,7 @@ public inline fun <reified T : CVariable> NativePlacement.alloc(initialize: T.()
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long): CArrayPointer<T> =
|
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long): CArrayPointer<T> =
|
||||||
alloc(sizeOf<T>() * length, alignOf<T>()).reinterpret<T>().ptr
|
alloc(sizeOf<T>() * length, alignOf<T>()).reinterpret<T>().ptr
|
||||||
|
|
||||||
@@ -136,6 +139,7 @@ public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Lon
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int): CArrayPointer<T> =
|
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int): CArrayPointer<T> =
|
||||||
allocArray(length.toLong())
|
allocArray(length.toLong())
|
||||||
|
|
||||||
@@ -144,6 +148,7 @@ public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long,
|
public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long,
|
||||||
initializer: T.(index: Long)->Unit): CArrayPointer<T> {
|
initializer: T.(index: Long)->Unit): CArrayPointer<T> {
|
||||||
val res = allocArray<T>(length)
|
val res = allocArray<T>(length)
|
||||||
@@ -160,6 +165,7 @@ public inline fun <reified T : CVariable> NativePlacement.allocArray(length: Lon
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> NativePlacement.allocArray(
|
public inline fun <reified T : CVariable> NativePlacement.allocArray(
|
||||||
length: Int, initializer: T.(index: Int)->Unit): CArrayPointer<T> = allocArray(length.toLong()) { index ->
|
length: Int, initializer: T.(index: Int)->Unit): CArrayPointer<T> = allocArray(length.toLong()) { index ->
|
||||||
this.initializer(index.toInt())
|
this.initializer(index.toInt())
|
||||||
@@ -169,6 +175,7 @@ public inline fun <reified T : CVariable> NativePlacement.allocArray(
|
|||||||
/**
|
/**
|
||||||
* Allocates C array of pointers to given elements.
|
* Allocates C array of pointers to given elements.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(elements: List<T?>): CArrayPointer<CPointerVar<T>> {
|
public fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(elements: List<T?>): CArrayPointer<CPointerVar<T>> {
|
||||||
val res = allocArray<CPointerVar<T>>(elements.size)
|
val res = allocArray<CPointerVar<T>>(elements.size)
|
||||||
elements.forEachIndexed { index, value ->
|
elements.forEachIndexed { index, value ->
|
||||||
@@ -180,12 +187,14 @@ public fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(elements: List<
|
|||||||
/**
|
/**
|
||||||
* Allocates C array of pointers to given elements.
|
* Allocates C array of pointers to given elements.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(vararg elements: T?) =
|
public fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(vararg elements: T?) =
|
||||||
allocArrayOfPointersTo(listOf(*elements))
|
allocArrayOfPointersTo(listOf(*elements))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates C array of given values.
|
* Allocates C array of given values.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CPointer<*>>
|
public inline fun <reified T : CPointer<*>>
|
||||||
NativePlacement.allocArrayOf(vararg elements: T?): CArrayPointer<CPointerVarOf<T>> {
|
NativePlacement.allocArrayOf(vararg elements: T?): CArrayPointer<CPointerVarOf<T>> {
|
||||||
return allocArrayOf(listOf(*elements))
|
return allocArrayOf(listOf(*elements))
|
||||||
@@ -194,6 +203,7 @@ public inline fun <reified T : CPointer<*>>
|
|||||||
/**
|
/**
|
||||||
* Allocates C array of given values.
|
* Allocates C array of given values.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CPointer<*>>
|
public inline fun <reified T : CPointer<*>>
|
||||||
NativePlacement.allocArrayOf(elements: List<T?>): CArrayPointer<CPointerVarOf<T>> {
|
NativePlacement.allocArrayOf(elements: List<T?>): CArrayPointer<CPointerVarOf<T>> {
|
||||||
|
|
||||||
@@ -206,12 +216,14 @@ public inline fun <reified T : CPointer<*>>
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun NativePlacement.allocArrayOf(elements: ByteArray): CArrayPointer<ByteVar> {
|
public fun NativePlacement.allocArrayOf(elements: ByteArray): CArrayPointer<ByteVar> {
|
||||||
val result = allocArray<ByteVar>(elements.size)
|
val result = allocArray<ByteVar>(elements.size)
|
||||||
nativeMemUtils.putByteArray(elements, result.pointed, elements.size)
|
nativeMemUtils.putByteArray(elements, result.pointed, elements.size)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun NativePlacement.allocArrayOf(vararg elements: Float): CArrayPointer<FloatVar> {
|
public fun NativePlacement.allocArrayOf(vararg elements: Float): CArrayPointer<FloatVar> {
|
||||||
val res = allocArray<FloatVar>(elements.size)
|
val res = allocArray<FloatVar>(elements.size)
|
||||||
var index = 0
|
var index = 0
|
||||||
@@ -222,10 +234,12 @@ public fun NativePlacement.allocArrayOf(vararg elements: Float): CArrayPointer<F
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> NativePlacement.allocPointerTo() = alloc<CPointerVar<T>>()
|
public fun <T : CPointed> NativePlacement.allocPointerTo() = alloc<CPointerVar<T>>()
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal class ZeroValue<T: CVariable>(private val sizeBytes: Int, private val alignBytes: Int): CValue<T>() {
|
@ExperimentalForeignApi
|
||||||
|
internal class ZeroValue<T : CVariable>(private val sizeBytes: Int, private val alignBytes: Int) : CValue<T>() {
|
||||||
// Optimization to avoid unneeded virtual calls in base class implementation.
|
// Optimization to avoid unneeded virtual calls in base class implementation.
|
||||||
override fun getPointer(scope: AutofreeScope): CPointer<T> {
|
override fun getPointer(scope: AutofreeScope): CPointer<T> {
|
||||||
return place(interpretCPointer(scope.alloc(size, align).rawPtr)!!)
|
return place(interpretCPointer(scope.alloc(size, align).rawPtr)!!)
|
||||||
@@ -241,12 +255,16 @@ internal class ZeroValue<T: CVariable>(private val sizeBytes: Int, private val a
|
|||||||
|
|
||||||
}
|
}
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <T : CVariable> zeroValue(size: Int, align: Int): CValue<T> = ZeroValue(size, align)
|
public inline fun <T : CVariable> zeroValue(size: Int, align: Int): CValue<T> = ZeroValue(size, align)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> zeroValue(): CValue<T> = zeroValue<T>(sizeOf<T>().toInt(), alignOf<T>())
|
public inline fun <reified T : CVariable> zeroValue(): CValue<T> = zeroValue<T>(sizeOf<T>().toInt(), alignOf<T>())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> cValue(): CValue<T> = zeroValue<T>()
|
public inline fun <reified T : CVariable> cValue(): CValue<T> = zeroValue<T>()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CVariable> CPointed.readValues(size: Int, align: Int): CValues<T> {
|
public fun <T : CVariable> CPointed.readValues(size: Int, align: Int): CValues<T> {
|
||||||
val bytes = ByteArray(size)
|
val bytes = ByteArray(size)
|
||||||
nativeMemUtils.getByteArray(this, bytes, size)
|
nativeMemUtils.getByteArray(this, bytes, size)
|
||||||
@@ -265,9 +283,11 @@ public fun <T : CVariable> CPointed.readValues(size: Int, align: Int): CValues<T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> T.readValues(count: Int): CValues<T> =
|
public inline fun <reified T : CVariable> T.readValues(count: Int): CValues<T> =
|
||||||
this.readValues<T>(size = count * sizeOf<T>().toInt(), align = alignOf<T>())
|
this.readValues<T>(size = count * sizeOf<T>().toInt(), align = alignOf<T>())
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CVariable> CPointed.readValue(size: Long, align: Int): CValue<T> {
|
public fun <T : CVariable> CPointed.readValue(size: Long, align: Int): CValue<T> {
|
||||||
val bytes = ByteArray(size.toInt())
|
val bytes = ByteArray(size.toInt())
|
||||||
nativeMemUtils.getByteArray(this, bytes, size.toInt())
|
nativeMemUtils.getByteArray(this, bytes, size.toInt())
|
||||||
@@ -287,19 +307,24 @@ public fun <T : CVariable> CPointed.readValue(size: Long, align: Int): CValue<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@PublishedApi internal fun <T : CVariable> CPointed.readValue(type: CVariable.Type): CValue<T> =
|
@PublishedApi
|
||||||
readValue(type.size, type.align)
|
@ExperimentalForeignApi
|
||||||
|
internal fun <T : CVariable> CPointed.readValue(type: CVariable.Type): CValue<T> =
|
||||||
|
readValue(type.size, type.align)
|
||||||
|
|
||||||
// Note: can't be declared as property due to possible clash with a struct field.
|
// Note: can't be declared as property due to possible clash with a struct field.
|
||||||
// TODO: find better name.
|
// TODO: find better name.
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CStructVar> T.readValue(): CValue<T> = this.readValue(typeOf<T>())
|
public inline fun <reified T : CStructVar> T.readValue(): CValue<T> = this.readValue(typeOf<T>())
|
||||||
|
|
||||||
public fun <T: CVariable> CValue<T>.write(location: NativePtr) {
|
@ExperimentalForeignApi
|
||||||
|
public fun <T : CVariable> CValue<T>.write(location: NativePtr) {
|
||||||
this.place(interpretCPointer(location)!!)
|
this.place(interpretCPointer(location)!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: optimize
|
// TODO: optimize
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CVariable> CValues<T>.getBytes(): ByteArray = memScoped {
|
public fun <T : CVariable> CValues<T>.getBytes(): ByteArray = memScoped {
|
||||||
val result = ByteArray(size)
|
val result = ByteArray(size)
|
||||||
nativeMemUtils.getByteArray(
|
nativeMemUtils.getByteArray(
|
||||||
@@ -313,18 +338,22 @@ public fun <T : CVariable> CValues<T>.getBytes(): ByteArray = memScoped {
|
|||||||
/**
|
/**
|
||||||
* Calls the [block] with temporary copy of this value as receiver.
|
* Calls the [block] with temporary copy of this value as receiver.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CStructVar, R> CValue<T>.useContents(block: T.() -> R): R = memScoped {
|
public inline fun <reified T : CStructVar, R> CValue<T>.useContents(block: T.() -> R): R = memScoped {
|
||||||
this@useContents.placeTo(memScope).pointed.block()
|
this@useContents.placeTo(memScope).pointed.block()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CStructVar> CValue<T>.copy(modify: T.() -> Unit): CValue<T> = useContents {
|
public inline fun <reified T : CStructVar> CValue<T>.copy(modify: T.() -> Unit): CValue<T> = useContents {
|
||||||
this.modify()
|
this.modify()
|
||||||
this.readValue()
|
this.readValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CStructVar> cValue(initialize: T.() -> Unit): CValue<T> =
|
public inline fun <reified T : CStructVar> cValue(initialize: T.() -> Unit): CValue<T> =
|
||||||
zeroValue<T>().copy(modify = initialize)
|
zeroValue<T>().copy(modify = initialize)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <reified T : CVariable> createValues(count: Int, initializer: T.(index: Int) -> Unit) = memScoped {
|
public inline fun <reified T : CVariable> createValues(count: Int, initializer: T.(index: Int) -> Unit) = memScoped {
|
||||||
val array = allocArray<T>(count, initializer)
|
val array = allocArray<T>(count, initializer)
|
||||||
array[0].readValues(count)
|
array[0].readValues(count)
|
||||||
@@ -334,7 +363,8 @@ public inline fun <reified T : CVariable> createValues(count: Int, initializer:
|
|||||||
/**
|
/**
|
||||||
* Returns sequence of immutable values [CValues] to pass them to C code.
|
* Returns sequence of immutable values [CValues] to pass them to C code.
|
||||||
*/
|
*/
|
||||||
fun cValuesOf(vararg elements: Byte): CValues<ByteVar> = object : CValues<ByteVar>() {
|
@ExperimentalForeignApi
|
||||||
|
public fun cValuesOf(vararg elements: Byte): CValues<ByteVar> = object : CValues<ByteVar>() {
|
||||||
// Optimization to avoid unneeded virtual calls in base class implementation.
|
// Optimization to avoid unneeded virtual calls in base class implementation.
|
||||||
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
|
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
|
||||||
return place(interpretCPointer(scope.alloc(size, align).rawPtr)!!)
|
return place(interpretCPointer(scope.alloc(size, align).rawPtr)!!)
|
||||||
@@ -348,34 +378,49 @@ fun cValuesOf(vararg elements: Byte): CValues<ByteVar> = object : CValues<ByteVa
|
|||||||
override val align get() = 1
|
override val align get() = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun cValuesOf(vararg elements: Short): CValues<ShortVar> =
|
public fun cValuesOf(vararg elements: Short): CValues<ShortVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun cValuesOf(vararg elements: Int): CValues<IntVar> =
|
public fun cValuesOf(vararg elements: Int): CValues<IntVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun cValuesOf(vararg elements: Long): CValues<LongVar> =
|
public fun cValuesOf(vararg elements: Long): CValues<LongVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun cValuesOf(vararg elements: Float): CValues<FloatVar> =
|
public fun cValuesOf(vararg elements: Float): CValues<FloatVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun cValuesOf(vararg elements: Double): CValues<DoubleVar> =
|
public fun cValuesOf(vararg elements: Double): CValues<DoubleVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> cValuesOf(vararg elements: CPointer<T>?): CValues<CPointerVar<T>> =
|
public fun <T : CPointed> cValuesOf(vararg elements: CPointer<T>?): CValues<CPointerVar<T>> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun ByteArray.toCValues() = cValuesOf(*this)
|
public fun ByteArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun ShortArray.toCValues() = cValuesOf(*this)
|
public fun ShortArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun IntArray.toCValues() = cValuesOf(*this)
|
public fun IntArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun LongArray.toCValues() = cValuesOf(*this)
|
public fun LongArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun FloatArray.toCValues() = cValuesOf(*this)
|
public fun FloatArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun DoubleArray.toCValues() = cValuesOf(*this)
|
public fun DoubleArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> Array<CPointer<T>?>.toCValues() = cValuesOf(*this)
|
public fun <T : CPointed> Array<CPointer<T>?>.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : CPointed> List<CPointer<T>?>.toCValues() = this.toTypedArray().toCValues()
|
public fun <T : CPointed> List<CPointer<T>?>.toCValues() = this.toTypedArray().toCValues()
|
||||||
|
|
||||||
private class CString(val bytes: ByteArray): CValues<ByteVar>() {
|
@ExperimentalForeignApi
|
||||||
|
private class CString(val bytes: ByteArray) : CValues<ByteVar>() {
|
||||||
override val size get() = bytes.size + 1
|
override val size get() = bytes.size + 1
|
||||||
override val align get() = 1
|
override val align get() = 1
|
||||||
|
|
||||||
@@ -390,7 +435,8 @@ private class CString(val bytes: ByteArray): CValues<ByteVar>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object EmptyCString: CValues<ByteVar>() {
|
@ExperimentalForeignApi
|
||||||
|
private object EmptyCString : CValues<ByteVar>() {
|
||||||
override val size get() = 1
|
override val size get() = 1
|
||||||
override val align get() = 1
|
override val align get() = 1
|
||||||
|
|
||||||
@@ -402,6 +448,7 @@ private object EmptyCString: CValues<ByteVar>() {
|
|||||||
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
|
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
|
||||||
return placement
|
return placement
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun place(placement: CPointer<ByteVar>): CPointer<ByteVar> {
|
override fun place(placement: CPointer<ByteVar>): CPointer<ByteVar> {
|
||||||
placement[0] = 0.toByte()
|
placement[0] = 0.toByte()
|
||||||
return placement
|
return placement
|
||||||
@@ -411,12 +458,14 @@ private object EmptyCString: CValues<ByteVar>() {
|
|||||||
/**
|
/**
|
||||||
* @return the value of zero-terminated UTF-8-encoded C string constructed from given [kotlin.String].
|
* @return the value of zero-terminated UTF-8-encoded C string constructed from given [kotlin.String].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val String.cstr: CValues<ByteVar>
|
public val String.cstr: CValues<ByteVar>
|
||||||
get() = if (isEmpty()) EmptyCString else CString(encodeToUtf8(this))
|
get() = if (isEmpty()) EmptyCString else CString(encodeToUtf8(this))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the value of zero-terminated UTF-8-encoded C string constructed from given [kotlin.String].
|
* @return the value of zero-terminated UTF-8-encoded C string constructed from given [kotlin.String].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val String.utf8: CValues<ByteVar>
|
public val String.utf8: CValues<ByteVar>
|
||||||
get() = CString(encodeToUtf8(this))
|
get() = CString(encodeToUtf8(this))
|
||||||
|
|
||||||
@@ -424,6 +473,7 @@ public val String.utf8: CValues<ByteVar>
|
|||||||
* Convert this list of Kotlin strings to C array of C strings,
|
* Convert this list of Kotlin strings to C array of C strings,
|
||||||
* allocating memory for the array and C strings with given [AutofreeScope].
|
* allocating memory for the array and C strings with given [AutofreeScope].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun List<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>> =
|
public fun List<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>> =
|
||||||
autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) })
|
autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) })
|
||||||
|
|
||||||
@@ -431,10 +481,12 @@ public fun List<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<C
|
|||||||
* Convert this array of Kotlin strings to C array of C strings,
|
* Convert this array of Kotlin strings to C array of C strings,
|
||||||
* allocating memory for the array and C strings with given [AutofreeScope].
|
* allocating memory for the array and C strings with given [AutofreeScope].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun Array<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>> =
|
public fun Array<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>> =
|
||||||
autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) })
|
autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) })
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
private class U16CString(val chars: CharArray): CValues<UShortVar>() {
|
private class U16CString(val chars: CharArray): CValues<UShortVar>() {
|
||||||
override val size get() = 2 * (chars.size + 1)
|
override val size get() = 2 * (chars.size + 1)
|
||||||
|
|
||||||
@@ -456,16 +508,19 @@ private class U16CString(val chars: CharArray): CValues<UShortVar>() {
|
|||||||
/**
|
/**
|
||||||
* @return the value of zero-terminated UTF-16-encoded C string constructed from given [kotlin.String].
|
* @return the value of zero-terminated UTF-16-encoded C string constructed from given [kotlin.String].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val String.wcstr: CValues<UShortVar>
|
public val String.wcstr: CValues<UShortVar>
|
||||||
get() = U16CString(this.toCharArray())
|
get() = U16CString(this.toCharArray())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the value of zero-terminated UTF-16-encoded C string constructed from given [kotlin.String].
|
* @return the value of zero-terminated UTF-16-encoded C string constructed from given [kotlin.String].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val String.utf16: CValues<UShortVar>
|
public val String.utf16: CValues<UShortVar>
|
||||||
get() = U16CString(this.toCharArray())
|
get() = U16CString(this.toCharArray())
|
||||||
|
|
||||||
private class U32CString(val chars: CharArray): CValues<IntVar>() {
|
@ExperimentalForeignApi
|
||||||
|
private class U32CString(val chars: CharArray) : CValues<IntVar>() {
|
||||||
override val size get() = 4 * (chars.size + 1)
|
override val size get() = 4 * (chars.size + 1)
|
||||||
|
|
||||||
override val align get() = 4
|
override val align get() = 4
|
||||||
@@ -499,6 +554,7 @@ private class U32CString(val chars: CharArray): CValues<IntVar>() {
|
|||||||
/**
|
/**
|
||||||
* @return the value of zero-terminated UTF-32-encoded C string constructed from given [kotlin.String].
|
* @return the value of zero-terminated UTF-32-encoded C string constructed from given [kotlin.String].
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public val String.utf32: CValues<IntVar>
|
public val String.utf32: CValues<IntVar>
|
||||||
get() = U32CString(this.toCharArray())
|
get() = U32CString(this.toCharArray())
|
||||||
|
|
||||||
@@ -507,16 +563,19 @@ public val String.utf32: CValues<IntVar>
|
|||||||
/**
|
/**
|
||||||
* @return the [kotlin.String] decoded from given zero-terminated UTF-8-encoded C string.
|
* @return the [kotlin.String] decoded from given zero-terminated UTF-8-encoded C string.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<ByteVar>.toKStringFromUtf8(): String = this.toKStringFromUtf8Impl()
|
public fun CPointer<ByteVar>.toKStringFromUtf8(): String = this.toKStringFromUtf8Impl()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the [kotlin.String] decoded from given zero-terminated UTF-8-encoded C string.
|
* @return the [kotlin.String] decoded from given zero-terminated UTF-8-encoded C string.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<ByteVar>.toKString(): String = this.toKStringFromUtf8()
|
public fun CPointer<ByteVar>.toKString(): String = this.toKStringFromUtf8()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the [kotlin.String] decoded from given zero-terminated UTF-16-encoded C string.
|
* @return the [kotlin.String] decoded from given zero-terminated UTF-16-encoded C string.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<ShortVar>.toKStringFromUtf16(): String {
|
public fun CPointer<ShortVar>.toKStringFromUtf16(): String {
|
||||||
val nativeBytes = this
|
val nativeBytes = this
|
||||||
|
|
||||||
@@ -536,6 +595,7 @@ public fun CPointer<ShortVar>.toKStringFromUtf16(): String {
|
|||||||
/**
|
/**
|
||||||
* @return the [kotlin.String] decoded from given zero-terminated UTF-32-encoded C string.
|
* @return the [kotlin.String] decoded from given zero-terminated UTF-32-encoded C string.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<IntVar>.toKStringFromUtf32(): String {
|
public fun CPointer<IntVar>.toKStringFromUtf32(): String {
|
||||||
val nativeBytes = this
|
val nativeBytes = this
|
||||||
|
|
||||||
@@ -565,6 +625,7 @@ public fun CPointer<IntVar>.toKStringFromUtf32(): String {
|
|||||||
return chars.concatToString()
|
return chars.concatToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a string from the bytes in UTF-8 encoding in this array.
|
* Decodes a string from the bytes in UTF-8 encoding in this array.
|
||||||
* Bytes following the first occurrence of `0` byte, if it occurs, are not decoded.
|
* Bytes following the first occurrence of `0` byte, if it occurs, are not decoded.
|
||||||
@@ -572,6 +633,7 @@ public fun CPointer<IntVar>.toKStringFromUtf32(): String {
|
|||||||
* Malformed byte sequences are replaced by the replacement char `\uFFFD`.
|
* Malformed byte sequences are replaced by the replacement char `\uFFFD`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun ByteArray.toKString() : String {
|
public fun ByteArray.toKString() : String {
|
||||||
val realEndIndex = realEndIndex(this, 0, this.size)
|
val realEndIndex = realEndIndex(this, 0, this.size)
|
||||||
return decodeToString(0, realEndIndex)
|
return decodeToString(0, realEndIndex)
|
||||||
@@ -590,6 +652,7 @@ public fun ByteArray.toKString() : String {
|
|||||||
* @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true.
|
* @throws CharacterCodingException if the byte array contains malformed UTF-8 byte sequence and [throwOnInvalidSequence] is true.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun ByteArray.toKString(
|
public fun ByteArray.toKString(
|
||||||
startIndex: Int = 0,
|
startIndex: Int = 0,
|
||||||
endIndex: Int = this.size,
|
endIndex: Int = this.size,
|
||||||
@@ -617,6 +680,7 @@ private fun checkBoundsIndexes(startIndex: Int, endIndex: Int, size: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class MemScope : ArenaBase() {
|
public class MemScope : ArenaBase() {
|
||||||
|
|
||||||
val memScope: MemScope
|
val memScope: MemScope
|
||||||
@@ -632,6 +696,7 @@ public class MemScope : ArenaBase() {
|
|||||||
* Runs given [block] providing allocation of memory
|
* Runs given [block] providing allocation of memory
|
||||||
* which will be automatically disposed at the end of this scope.
|
* which will be automatically disposed at the end of this scope.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public inline fun <R> memScoped(block: MemScope.()->R): R {
|
public inline fun <R> memScoped(block: MemScope.()->R): R {
|
||||||
val memScope = MemScope()
|
val memScope = MemScope()
|
||||||
try {
|
try {
|
||||||
@@ -641,6 +706,7 @@ public inline fun <R> memScoped(block: MemScope.()->R): R {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun COpaquePointer.readBytes(count: Int): ByteArray {
|
public fun COpaquePointer.readBytes(count: Int): ByteArray {
|
||||||
val result = ByteArray(count)
|
val result = ByteArray(count)
|
||||||
nativeMemUtils.getByteArray(this.reinterpret<ByteVar>().pointed, result, count)
|
nativeMemUtils.getByteArray(this.reinterpret<ByteVar>().pointed, result, count)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ package kotlinx.cinterop
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Boolean> NativePlacement.alloc(value: T): BooleanVarOf<T> =
|
public fun <T : Boolean> NativePlacement.alloc(value: T): BooleanVarOf<T> =
|
||||||
alloc<BooleanVarOf<T>> { this.value = value }
|
alloc<BooleanVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ public fun <T : Boolean> NativePlacement.alloc(value: T): BooleanVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Byte> NativePlacement.alloc(value: T): ByteVarOf<T> =
|
public fun <T : Byte> NativePlacement.alloc(value: T): ByteVarOf<T> =
|
||||||
alloc<ByteVarOf<T>> { this.value = value }
|
alloc<ByteVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ public fun <T : Byte> NativePlacement.alloc(value: T): ByteVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Short> NativePlacement.alloc(value: T): ShortVarOf<T> =
|
public fun <T : Short> NativePlacement.alloc(value: T): ShortVarOf<T> =
|
||||||
alloc<ShortVarOf<T>> { this.value = value }
|
alloc<ShortVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ public fun <T : Short> NativePlacement.alloc(value: T): ShortVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Int> NativePlacement.alloc(value: T): IntVarOf<T> =
|
public fun <T : Int> NativePlacement.alloc(value: T): IntVarOf<T> =
|
||||||
alloc<IntVarOf<T>> { this.value = value }
|
alloc<IntVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -40,6 +44,7 @@ public fun <T : Int> NativePlacement.alloc(value: T): IntVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Long> NativePlacement.alloc(value: T): LongVarOf<T> =
|
public fun <T : Long> NativePlacement.alloc(value: T): LongVarOf<T> =
|
||||||
alloc<LongVarOf<T>> { this.value = value }
|
alloc<LongVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -47,6 +52,7 @@ public fun <T : Long> NativePlacement.alloc(value: T): LongVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : UByte> NativePlacement.alloc(value: T): UByteVarOf<T> =
|
public fun <T : UByte> NativePlacement.alloc(value: T): UByteVarOf<T> =
|
||||||
alloc<UByteVarOf<T>> { this.value = value }
|
alloc<UByteVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -54,6 +60,7 @@ public fun <T : UByte> NativePlacement.alloc(value: T): UByteVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : UShort> NativePlacement.alloc(value: T): UShortVarOf<T> =
|
public fun <T : UShort> NativePlacement.alloc(value: T): UShortVarOf<T> =
|
||||||
alloc<UShortVarOf<T>> { this.value = value }
|
alloc<UShortVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -61,6 +68,7 @@ public fun <T : UShort> NativePlacement.alloc(value: T): UShortVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : UInt> NativePlacement.alloc(value: T): UIntVarOf<T> =
|
public fun <T : UInt> NativePlacement.alloc(value: T): UIntVarOf<T> =
|
||||||
alloc<UIntVarOf<T>> { this.value = value }
|
alloc<UIntVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -68,6 +76,7 @@ public fun <T : UInt> NativePlacement.alloc(value: T): UIntVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : ULong> NativePlacement.alloc(value: T): ULongVarOf<T> =
|
public fun <T : ULong> NativePlacement.alloc(value: T): ULongVarOf<T> =
|
||||||
alloc<ULongVarOf<T>> { this.value = value }
|
alloc<ULongVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -75,6 +84,7 @@ public fun <T : ULong> NativePlacement.alloc(value: T): ULongVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Float> NativePlacement.alloc(value: T): FloatVarOf<T> =
|
public fun <T : Float> NativePlacement.alloc(value: T): FloatVarOf<T> =
|
||||||
alloc<FloatVarOf<T>> { this.value = value }
|
alloc<FloatVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
@@ -82,6 +92,7 @@ public fun <T : Float> NativePlacement.alloc(value: T): FloatVarOf<T> =
|
|||||||
* Allocates variable with given value type and initializes it with given value.
|
* Allocates variable with given value type and initializes it with given value.
|
||||||
*/
|
*/
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun <T : Double> NativePlacement.alloc(value: T): DoubleVarOf<T> =
|
public fun <T : Double> NativePlacement.alloc(value: T): DoubleVarOf<T> =
|
||||||
alloc<DoubleVarOf<T>> { this.value = value }
|
alloc<DoubleVarOf<T>> { this.value = value }
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -1,13 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.internal.ExportForCppRuntime
|
import kotlin.native.internal.ExportForCppRuntime
|
||||||
import kotlin.native.internal.GCUnsafeCall
|
import kotlin.native.internal.GCUnsafeCall
|
||||||
|
|
||||||
public class ForeignException internal constructor(val nativeException: Any?): Exception() {
|
@BetaInteropApi
|
||||||
|
public class ForeignException internal constructor(val nativeException: Any?) : Exception() {
|
||||||
override val message: String = nativeException?.let {
|
override val message: String = nativeException?.let {
|
||||||
kotlin_ObjCExport_ExceptionDetails(nativeException)
|
kotlin_ObjCExport_ExceptionDetails(nativeException)
|
||||||
}?: ""
|
}?: ""
|
||||||
@@ -18,5 +20,7 @@ public class ForeignException internal constructor(val nativeException: Any?): E
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
@BetaInteropApi
|
||||||
|
@ExperimentalForeignApi
|
||||||
internal fun CreateForeignException(payload: NativePtr): Throwable
|
internal fun CreateForeignException(payload: NativePtr): Throwable
|
||||||
= ForeignException(interpretObjCPointerOrNull<Any?>(payload))
|
= ForeignException(interpretObjCPointerOrNull<Any?>(payload))
|
||||||
|
|||||||
+25
-13
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
@@ -20,48 +9,71 @@ import kotlin.native.internal.TypedIntrinsic
|
|||||||
import kotlin.native.internal.IntrinsicType
|
import kotlin.native.internal.IntrinsicType
|
||||||
import kotlin.native.internal.ExportForCompiler
|
import kotlin.native.internal.ExportForCompiler
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <R> CPointer<CFunction<() -> R>>.invoke(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <R> CPointer<CFunction<() -> R>>.invoke(): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, R> CPointer<CFunction<(P1) -> R>>.invoke(p1: P1): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, R> CPointer<CFunction<(P1) -> R>>.invoke(p1: P1): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, R> CPointer<CFunction<(P1, P2) -> R>>.invoke(p1: P1, p2: P2): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, R> CPointer<CFunction<(P1, P2) -> R>>.invoke(p1: P1, p2: P2): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, R> CPointer<CFunction<(P1, P2, P3) -> R>>.invoke(p1: P1, p2: P2, p3: P3): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, R> CPointer<CFunction<(P1, P2, P3) -> R>>.invoke(p1: P1, p2: P2, p3: P3): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, R> CPointer<CFunction<(P1, P2, P3, P4) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, R> CPointer<CFunction<(P1, P2, P3, P4) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, R> CPointer<CFunction<(P1, P2, P3, P4, P5) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, R> CPointer<CFunction<(P1, P2, P3, P4, P5) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_FUNPTR_INVOKE) external operator fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, R> CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R>>.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,9 +7,14 @@ package kotlinx.cinterop
|
|||||||
|
|
||||||
import kotlinx.cinterop.CStructVar
|
import kotlinx.cinterop.CStructVar
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
interface SkiaRefCnt
|
interface SkiaRefCnt
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
interface CPlusPlusClass
|
interface CPlusPlusClass
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
abstract class ManagedType<T : CStructVar>(val cpp: T)
|
abstract class ManagedType<T : CStructVar>(val cpp: T)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
val <T : CStructVar> ManagedType<T>.ptr: CPointer<T> get() = this.cpp.ptr
|
val <T : CStructVar> ManagedType<T>.ptr: CPointer<T> get() = this.cpp.ptr
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
@@ -139,6 +128,7 @@ internal object nativeMemUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<UShortVar>.toKStringFromUtf16(): String {
|
public fun CPointer<UShortVar>.toKStringFromUtf16(): String {
|
||||||
val nativeBytes = this
|
val nativeBytes = this
|
||||||
|
|
||||||
@@ -155,8 +145,10 @@ public fun CPointer<UShortVar>.toKStringFromUtf16(): String {
|
|||||||
return chars.concatToString()
|
return chars.concatToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<ShortVar>.toKString(): String = this.toKStringFromUtf16()
|
public fun CPointer<ShortVar>.toKString(): String = this.toKStringFromUtf16()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun CPointer<UShortVar>.toKString(): String = this.toKStringFromUtf16()
|
public fun CPointer<UShortVar>.toKString(): String = this.toKStringFromUtf16()
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_interop_malloc")
|
@GCUnsafeCall("Kotlin_interop_malloc")
|
||||||
@@ -165,7 +157,10 @@ private external fun malloc(size: Long, align: Int): NativePtr
|
|||||||
@GCUnsafeCall("Kotlin_interop_free")
|
@GCUnsafeCall("Kotlin_interop_free")
|
||||||
private external fun cfree(ptr: NativePtr)
|
private external fun cfree(ptr: NativePtr)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_READ_BITS)
|
@TypedIntrinsic(IntrinsicType.INTEROP_READ_BITS)
|
||||||
external fun readBits(ptr: NativePtr, offset: Long, size: Int, signed: Boolean): Long
|
external fun readBits(ptr: NativePtr, offset: Long, size: Int, signed: Boolean): Long
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_WRITE_BITS)
|
@TypedIntrinsic(IntrinsicType.INTEROP_WRITE_BITS)
|
||||||
external fun writeBits(ptr: NativePtr, offset: Long, size: Int, value: Long)
|
external fun writeBits(ptr: NativePtr, offset: Long, size: Int, value: Long)
|
||||||
|
|||||||
+4
-14
@@ -1,20 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.native.internal.GCUnsafeCall
|
import kotlin.native.internal.GCUnsafeCall
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.internal.reinterpret
|
import kotlin.native.internal.reinterpret
|
||||||
@@ -22,17 +10,21 @@ import kotlin.native.internal.VolatileLambda
|
|||||||
import kotlin.native.internal.TypedIntrinsic
|
import kotlin.native.internal.TypedIntrinsic
|
||||||
import kotlin.native.internal.IntrinsicType
|
import kotlin.native.internal.IntrinsicType
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
typealias NativePtr = kotlin.native.internal.NativePtr
|
typealias NativePtr = kotlin.native.internal.NativePtr
|
||||||
internal typealias NonNullNativePtr = kotlin.native.internal.NonNullNativePtr
|
internal typealias NonNullNativePtr = kotlin.native.internal.NonNullNativePtr
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
@ExperimentalForeignApi
|
||||||
internal inline fun NativePtr.toNonNull() = this.reinterpret<NativePtr, NonNullNativePtr>()
|
internal inline fun NativePtr.toNonNull() = this.reinterpret<NativePtr, NonNullNativePtr>()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline val nativeNullPtr: NativePtr
|
inline val nativeNullPtr: NativePtr
|
||||||
get() = NativePtr.NULL
|
get() = NativePtr.NULL
|
||||||
|
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun <T : CVariable> typeOf(): CVariable.Type = throw Error("typeOf() is called with erased argument")
|
fun <T : CVariable> typeOf(): CVariable.Type = throw Error("typeOf() is called with erased argument")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,23 +32,29 @@ fun <T : CVariable> typeOf(): CVariable.Type = throw Error("typeOf() is called w
|
|||||||
*
|
*
|
||||||
* @param T must not be abstract
|
* @param T must not be abstract
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
||||||
external fun <T : NativePointed> interpretNullablePointed(ptr: NativePtr): T?
|
external fun <T : NativePointed> interpretNullablePointed(ptr: NativePtr): T?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs type cast of the [CPointer] from the given raw pointer.
|
* Performs type cast of the [CPointer] from the given raw pointer.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
||||||
external fun <T : CPointed> interpretCPointer(rawValue: NativePtr): CPointer<T>?
|
external fun <T : CPointed> interpretCPointer(rawValue: NativePtr): CPointer<T>?
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
||||||
external fun NativePointed.getRawPointer(): NativePtr
|
external fun NativePointed.getRawPointer(): NativePtr
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
@TypedIntrinsic(IntrinsicType.IDENTITY)
|
||||||
external fun CPointer<*>.getRawValue(): NativePtr
|
external fun CPointer<*>.getRawValue(): NativePtr
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)"
|
internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)"
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND")
|
@Suppress("FINAL_UPPER_BOUND")
|
||||||
public class Vector128VarOf<T : Vector128>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
public class Vector128VarOf<T : Vector128>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@@ -64,8 +62,10 @@ public class Vector128VarOf<T : Vector128>(rawPtr: NativePtr) : CVariable(rawPtr
|
|||||||
companion object : Type(size = 16, align = 16)
|
companion object : Type(size = 16, align = 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public typealias Vector128Var = Vector128VarOf<Vector128>
|
public typealias Vector128Var = Vector128VarOf<Vector128>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
@Suppress("FINAL_UPPER_BOUND", "UNCHECKED_CAST")
|
||||||
public var <T : Vector128> Vector128VarOf<T>.value: T
|
public var <T : Vector128> Vector128VarOf<T>.value: T
|
||||||
get() = nativeMemUtils.getVector(this) as T
|
get() = nativeMemUtils.getVector(this) as T
|
||||||
@@ -77,48 +77,71 @@ public var <T : Vector128> Vector128VarOf<T>.value: T
|
|||||||
* @param function must be *static*, i.e. an (unbound) reference to a Kotlin function or
|
* @param function must be *static*, i.e. an (unbound) reference to a Kotlin function or
|
||||||
* a closure which doesn't capture any variable
|
* a closure which doesn't capture any variable
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <R> staticCFunction(@VolatileLambda function: () -> R): CPointer<CFunction<() -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <R> staticCFunction(@VolatileLambda function: () -> R): CPointer<CFunction<() -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, R> staticCFunction(@VolatileLambda function: (P1) -> R): CPointer<CFunction<(P1) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, R> staticCFunction(@VolatileLambda function: (P1) -> R): CPointer<CFunction<(P1) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, R> staticCFunction(@VolatileLambda function: (P1, P2) -> R): CPointer<CFunction<(P1, P2) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, R> staticCFunction(@VolatileLambda function: (P1, P2) -> R): CPointer<CFunction<(P1, P2) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, R> staticCFunction(@VolatileLambda function: (P1, P2, P3) -> R): CPointer<CFunction<(P1, P2, P3) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, R> staticCFunction(@VolatileLambda function: (P1, P2, P3) -> R): CPointer<CFunction<(P1, P2, P3) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4) -> R): CPointer<CFunction<(P1, P2, P3, P4) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4) -> R): CPointer<CFunction<(P1, P2, P3, P4) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21) -> R>>
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R>>
|
@TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) external fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, R> staticCFunction(@VolatileLambda function: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R): CPointer<CFunction<(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22) -> R>>
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
@@ -24,48 +13,67 @@ import kotlin.native.internal.IntrinsicType
|
|||||||
internal fun encodeToUtf8(str: String): ByteArray = str.encodeToByteArray()
|
internal fun encodeToUtf8(str: String): ByteArray = str.encodeToByteArray()
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_CString_toKStringFromUtf8Impl")
|
@GCUnsafeCall("Kotlin_CString_toKStringFromUtf8Impl")
|
||||||
|
@ExperimentalForeignApi
|
||||||
internal external fun CPointer<ByteVar>.toKStringFromUtf8Impl(): String
|
internal external fun CPointer<ByteVar>.toKStringFromUtf8Impl(): String
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_BITS_TO_FLOAT)
|
@TypedIntrinsic(IntrinsicType.INTEROP_BITS_TO_FLOAT)
|
||||||
external fun bitsToFloat(bits: Int): Float
|
external fun bitsToFloat(bits: Int): Float
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_BITS_TO_DOUBLE)
|
@TypedIntrinsic(IntrinsicType.INTEROP_BITS_TO_DOUBLE)
|
||||||
external fun bitsToDouble(bits: Long): Double
|
external fun bitsToDouble(bits: Long): Double
|
||||||
|
|
||||||
// TODO: deprecate.
|
@Deprecated("Deprecated without replacement as part of the obsolete interop API", level = DeprecationLevel.WARNING)
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_SIGN_EXTEND)
|
@TypedIntrinsic(IntrinsicType.INTEROP_SIGN_EXTEND)
|
||||||
external inline fun <reified R : Number> Number.signExtend(): R
|
external inline fun <reified R : Number> Number.signExtend(): R
|
||||||
|
|
||||||
// TODO: deprecate.
|
@Deprecated("Deprecated without replacement as part of the obsolete interop API", level = DeprecationLevel.WARNING)
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_NARROW)
|
@TypedIntrinsic(IntrinsicType.INTEROP_NARROW)
|
||||||
external inline fun <reified R : Number> Number.narrow(): R
|
external inline fun <reified R : Number> Number.narrow(): R
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Byte.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Byte.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Short.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Short.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Int.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Int.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Long.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> Long.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UByte.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UByte.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UShort.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UShort.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UInt.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> UInt.convert(): R
|
||||||
|
@ExperimentalForeignApi
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> ULong.convert(): R
|
@TypedIntrinsic(IntrinsicType.INTEROP_CONVERT) external inline fun <reified R : Any> ULong.convert(): R
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE)
|
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
internal annotation class JvmName(val name: String)
|
internal annotation class JvmName(val name: String)
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun cValuesOf(vararg elements: UByte): CValues<UByteVar> =
|
fun cValuesOf(vararg elements: UByte): CValues<UByteVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun cValuesOf(vararg elements: UShort): CValues<UShortVar> =
|
fun cValuesOf(vararg elements: UShort): CValues<UShortVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun cValuesOf(vararg elements: UInt): CValues<UIntVar> =
|
fun cValuesOf(vararg elements: UInt): CValues<UIntVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun cValuesOf(vararg elements: ULong): CValues<ULongVar> =
|
fun cValuesOf(vararg elements: ULong): CValues<ULongVar> =
|
||||||
createValues(elements.size) { index -> this.value = elements[index] }
|
createValues(elements.size) { index -> this.value = elements[index] }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UByteArray.toCValues() = cValuesOf(*this)
|
fun UByteArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UShortArray.toCValues() = cValuesOf(*this)
|
fun UShortArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UIntArray.toCValues() = cValuesOf(*this)
|
fun UIntArray.toCValues() = cValuesOf(*this)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun ULongArray.toCValues() = cValuesOf(*this)
|
fun ULongArray.toCValues() = cValuesOf(*this)
|
||||||
+50
-27
@@ -1,30 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("NOTHING_TO_INLINE")
|
@file:Suppress("NOTHING_TO_INLINE")
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
import kotlin.native.internal.InternalForKotlinNative
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
interface ObjCObject
|
interface ObjCObject
|
||||||
|
@BetaInteropApi
|
||||||
interface ObjCClass : ObjCObject
|
interface ObjCClass : ObjCObject
|
||||||
|
@BetaInteropApi
|
||||||
interface ObjCClassOf<T : ObjCObject> : ObjCClass // TODO: T should be added to ObjCClass and all meta-classes instead.
|
interface ObjCClassOf<T : ObjCObject> : ObjCClass // TODO: T should be added to ObjCClass and all meta-classes instead.
|
||||||
|
@BetaInteropApi
|
||||||
typealias ObjCObjectMeta = ObjCClass
|
typealias ObjCObjectMeta = ObjCClass
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
interface ObjCProtocol : ObjCObject
|
interface ObjCProtocol : ObjCObject
|
||||||
|
|
||||||
@ExportTypeInfo("theForeignObjCObjectTypeInfo")
|
@ExportTypeInfo("theForeignObjCObjectTypeInfo")
|
||||||
@@ -32,13 +29,17 @@ interface ObjCProtocol : ObjCObject
|
|||||||
@kotlin.native.internal.Frozen
|
@kotlin.native.internal.Frozen
|
||||||
internal open class ForeignObjCObject : kotlin.native.internal.ObjCObjectWrapper
|
internal open class ForeignObjCObject : kotlin.native.internal.ObjCObjectWrapper
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
abstract class ObjCObjectBase protected constructor() : ObjCObject {
|
abstract class ObjCObjectBase protected constructor() : ObjCObject {
|
||||||
@Target(AnnotationTarget.CONSTRUCTOR)
|
@Target(AnnotationTarget.CONSTRUCTOR)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
annotation class OverrideInit
|
annotation class OverrideInit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
abstract class ObjCObjectBaseMeta protected constructor() : ObjCObjectBase(), ObjCObjectMeta {}
|
abstract class ObjCObjectBaseMeta protected constructor() : ObjCObjectBase(), ObjCObjectMeta {}
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
fun optional(): Nothing = throw RuntimeException("Do not call me!!!")
|
fun optional(): Nothing = throw RuntimeException("Do not call me!!!")
|
||||||
|
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
@@ -48,6 +49,7 @@ fun optional(): Nothing = throw RuntimeException("Do not call me!!!")
|
|||||||
@TypedIntrinsic(IntrinsicType.OBJC_INIT_BY)
|
@TypedIntrinsic(IntrinsicType.OBJC_INIT_BY)
|
||||||
external fun <T : ObjCObjectBase> T.initBy(constructorCall: T): T
|
external fun <T : ObjCObjectBase> T.initBy(constructorCall: T): T
|
||||||
|
|
||||||
|
@BetaInteropApi
|
||||||
@kotlin.native.internal.ExportForCompiler
|
@kotlin.native.internal.ExportForCompiler
|
||||||
private fun ObjCObjectBase.superInitCheck(superInitCallResult: ObjCObject?) {
|
private fun ObjCObjectBase.superInitCheck(superInitCallResult: ObjCObject?) {
|
||||||
if (superInitCallResult == null)
|
if (superInitCallResult == null)
|
||||||
@@ -60,20 +62,25 @@ 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.
|
||||||
|
@ExperimentalForeignApi
|
||||||
@GCUnsafeCall("Kotlin_Interop_refFromObjC")
|
@GCUnsafeCall("Kotlin_Interop_refFromObjC")
|
||||||
external fun <T> interpretObjCPointerOrNull(objcPtr: NativePtr): T?
|
external fun <T> interpretObjCPointerOrNull(objcPtr: NativePtr): T?
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline fun <T : Any> interpretObjCPointer(objcPtr: NativePtr): T = interpretObjCPointerOrNull<T>(objcPtr)!!
|
inline fun <T : Any> interpretObjCPointer(objcPtr: NativePtr): T = interpretObjCPointerOrNull<T>(objcPtr)!!
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_Interop_refToObjC")
|
@GCUnsafeCall("Kotlin_Interop_refToObjC")
|
||||||
external fun Any?.objcPtr(): NativePtr
|
@ExperimentalForeignApi
|
||||||
|
public external fun Any?.objcPtr(): NativePtr
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_Interop_createKotlinObjectHolder")
|
@GCUnsafeCall("Kotlin_Interop_createKotlinObjectHolder")
|
||||||
external fun createKotlinObjectHolder(any: Any?): NativePtr
|
@ExperimentalForeignApi
|
||||||
|
public 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.
|
||||||
inline fun <reified T : Any> unwrapKotlinObjectHolder(holder: Any?): T {
|
@BetaInteropApi
|
||||||
|
public inline fun <reified T : Any> unwrapKotlinObjectHolder(holder: Any?): T {
|
||||||
return unwrapKotlinObjectHolderImpl(holder!!.objcPtr()) as T
|
return unwrapKotlinObjectHolderImpl(holder!!.objcPtr()) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,23 +88,28 @@ inline fun <reified T : Any> unwrapKotlinObjectHolder(holder: Any?): T {
|
|||||||
@GCUnsafeCall("Kotlin_Interop_unwrapKotlinObjectHolder")
|
@GCUnsafeCall("Kotlin_Interop_unwrapKotlinObjectHolder")
|
||||||
external internal fun unwrapKotlinObjectHolderImpl(ptr: NativePtr): Any
|
external internal fun unwrapKotlinObjectHolderImpl(ptr: NativePtr): Any
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
class ObjCObjectVar<T>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
class ObjCObjectVar<T>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
companion object : CVariable.Type(pointerSize.toLong(), pointerSize)
|
companion object : CVariable.Type(pointerSize.toLong(), pointerSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
class ObjCNotImplementedVar<T : Any?>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
class ObjCNotImplementedVar<T : Any?>(rawPtr: NativePtr) : CVariable(rawPtr) {
|
||||||
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
@Deprecated("Use sizeOf<T>() or alignOf<T>() instead.")
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
companion object : CVariable.Type(pointerSize.toLong(), pointerSize)
|
companion object : CVariable.Type(pointerSize.toLong(), pointerSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
var <T : Any?> ObjCNotImplementedVar<T>.value: T
|
var <T : Any?> ObjCNotImplementedVar<T>.value: T
|
||||||
get() = TODO()
|
get() = TODO()
|
||||||
set(_) = TODO()
|
set(_) = TODO()
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
typealias ObjCStringVarOf<T> = ObjCNotImplementedVar<T>
|
typealias ObjCStringVarOf<T> = ObjCNotImplementedVar<T>
|
||||||
|
@ExperimentalForeignApi
|
||||||
typealias ObjCBlockVar<T> = ObjCNotImplementedVar<T>
|
typealias ObjCBlockVar<T> = ObjCNotImplementedVar<T>
|
||||||
|
|
||||||
@TypedIntrinsic(IntrinsicType.OBJC_CREATE_SUPER_STRUCT)
|
@TypedIntrinsic(IntrinsicType.OBJC_CREATE_SUPER_STRUCT)
|
||||||
@@ -106,27 +118,33 @@ internal external fun createObjCSuperStruct(receiver: NativePtr, superClass: Nat
|
|||||||
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class ExternalObjCClass(val protocolGetter: String = "", val binaryName: String = "")
|
@InternalForKotlinNative
|
||||||
|
public annotation class ExternalObjCClass(val protocolGetter: String = "", val binaryName: String = "")
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class ObjCMethod(val selector: String, val encoding: String, val isStret: Boolean = false)
|
@InternalForKotlinNative
|
||||||
|
public annotation class ObjCMethod(val selector: String, val encoding: String, val isStret: Boolean = false)
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class ObjCDirect(val symbol: String)
|
@InternalForKotlinNative
|
||||||
|
public annotation class ObjCDirect(val symbol: String)
|
||||||
|
|
||||||
@Target(AnnotationTarget.CONSTRUCTOR)
|
@Target(AnnotationTarget.CONSTRUCTOR)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class ObjCConstructor(val initSelector: String, val designated: Boolean)
|
@InternalForKotlinNative
|
||||||
|
public annotation class ObjCConstructor(val initSelector: String, val designated: Boolean)
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class ObjCFactory(val selector: String, val encoding: String, val isStret: Boolean = false)
|
@InternalForKotlinNative
|
||||||
|
public annotation class ObjCFactory(val selector: String, val encoding: String, val isStret: Boolean = false)
|
||||||
|
|
||||||
@Target(AnnotationTarget.FILE)
|
@Target(AnnotationTarget.FILE)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class InteropStubs()
|
@InternalForKotlinNative
|
||||||
|
public annotation class InteropStubs()
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@@ -193,20 +211,25 @@ internal external fun createObjCObjectHolder(ptr: NativePtr): Any?
|
|||||||
// Objective-C runtime:
|
// Objective-C runtime:
|
||||||
|
|
||||||
@GCUnsafeCall("objc_retainAutoreleaseReturnValue")
|
@GCUnsafeCall("objc_retainAutoreleaseReturnValue")
|
||||||
external fun objc_retainAutoreleaseReturnValue(ptr: NativePtr): NativePtr
|
@ExperimentalForeignApi
|
||||||
|
public external fun objc_retainAutoreleaseReturnValue(ptr: NativePtr): NativePtr
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPush")
|
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPush")
|
||||||
external fun objc_autoreleasePoolPush(): NativePtr
|
@ExperimentalForeignApi
|
||||||
|
public external fun objc_autoreleasePoolPush(): NativePtr
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPop")
|
@GCUnsafeCall("Kotlin_objc_autoreleasePoolPop")
|
||||||
external fun objc_autoreleasePoolPop(ptr: NativePtr)
|
@ExperimentalForeignApi
|
||||||
|
public external fun objc_autoreleasePoolPop(ptr: NativePtr)
|
||||||
|
|
||||||
@GCUnsafeCall("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
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_retain")
|
@GCUnsafeCall("Kotlin_objc_retain")
|
||||||
external fun objc_retain(ptr: NativePtr): NativePtr
|
@ExperimentalForeignApi
|
||||||
|
public external fun objc_retain(ptr: NativePtr): NativePtr
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_release")
|
@GCUnsafeCall("Kotlin_objc_release")
|
||||||
external fun objc_release(ptr: NativePtr)
|
@ExperimentalForeignApi
|
||||||
|
public external fun objc_release(ptr: NativePtr)
|
||||||
|
|||||||
+8
-5
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the LICENSE file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.internal.KClassImpl
|
import kotlin.native.internal.KClassImpl
|
||||||
@@ -15,7 +15,8 @@ import kotlin.reflect.KClass
|
|||||||
*
|
*
|
||||||
* Otherwise returns `null`.
|
* Otherwise returns `null`.
|
||||||
*/
|
*/
|
||||||
fun getOriginalKotlinClass(objCClass: ObjCClass): KClass<*>? {
|
@BetaInteropApi
|
||||||
|
public fun getOriginalKotlinClass(objCClass: ObjCClass): KClass<*>? {
|
||||||
val typeInfo = getTypeInfoForClass(objCClass.objcPtr())
|
val typeInfo = getTypeInfoForClass(objCClass.objcPtr())
|
||||||
if (typeInfo.isNull()) return null
|
if (typeInfo.isNull()) return null
|
||||||
|
|
||||||
@@ -28,7 +29,8 @@ fun getOriginalKotlinClass(objCClass: ObjCClass): KClass<*>? {
|
|||||||
*
|
*
|
||||||
* Otherwise returns `null`.
|
* Otherwise returns `null`.
|
||||||
*/
|
*/
|
||||||
fun getOriginalKotlinClass(objCProtocol: ObjCProtocol): KClass<*>? {
|
@BetaInteropApi
|
||||||
|
public fun getOriginalKotlinClass(objCProtocol: ObjCProtocol): KClass<*>? {
|
||||||
val typeInfo = getTypeInfoForProtocol(objCProtocol.objcPtr())
|
val typeInfo = getTypeInfoForProtocol(objCProtocol.objcPtr())
|
||||||
if (typeInfo.isNull()) return null
|
if (typeInfo.isNull()) return null
|
||||||
|
|
||||||
@@ -40,3 +42,4 @@ private external fun getTypeInfoForClass(ptr: NativePtr): NativePtr
|
|||||||
|
|
||||||
@GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForProtocol")
|
@GCUnsafeCall("Kotlin_ObjCInterop_getTypeInfoForProtocol")
|
||||||
private external fun getTypeInfoForProtocol(ptr: NativePtr): NativePtr
|
private external fun getTypeInfoForProtocol(ptr: NativePtr): NativePtr
|
||||||
|
|
||||||
|
|||||||
+14
-21
@@ -1,22 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
inline fun <R> autoreleasepool(block: () -> R): R {
|
@BetaInteropApi
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
|
public inline fun <R> autoreleasepool(block: () -> R): R {
|
||||||
val pool = objc_autoreleasePoolPush()
|
val pool = objc_autoreleasePoolPush()
|
||||||
return try {
|
return try {
|
||||||
block()
|
block()
|
||||||
@@ -25,11 +16,10 @@ inline fun <R> autoreleasepool(block: () -> R): R {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Use plain Kotlin cast", ReplaceWith("this as T"), DeprecationLevel.ERROR)
|
|
||||||
fun <T : ObjCObject> ObjCObject.reinterpret() = @Suppress("DEPRECATION") this.uncheckedCast<T>()
|
|
||||||
|
|
||||||
// TODO: null checks
|
// TODO: null checks
|
||||||
var <T> ObjCObjectVar<T>.value: T
|
@BetaInteropApi
|
||||||
|
@ExperimentalForeignApi
|
||||||
|
public var <T> ObjCObjectVar<T>.value: T
|
||||||
@Suppress("DEPRECATION") get() =
|
@Suppress("DEPRECATION") get() =
|
||||||
interpretObjCPointerOrNull<T>(nativeMemUtils.getNativePtr(this)).uncheckedCast<T>()
|
interpretObjCPointerOrNull<T>(nativeMemUtils.getNativePtr(this)).uncheckedCast<T>()
|
||||||
|
|
||||||
@@ -41,7 +31,8 @@ var <T> ObjCObjectVar<T>.value: T
|
|||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
annotation class ObjCAction
|
@BetaInteropApi
|
||||||
|
public annotation class ObjCAction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes Kotlin property in Objective-C class settable through Objective-C dispatch
|
* Makes Kotlin property in Objective-C class settable through Objective-C dispatch
|
||||||
@@ -49,7 +40,8 @@ annotation class ObjCAction
|
|||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.PROPERTY)
|
@Target(AnnotationTarget.PROPERTY)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
annotation class ObjCOutlet
|
@BetaInteropApi
|
||||||
|
public annotation class ObjCOutlet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes Kotlin subclass of Objective-C class visible for runtime lookup
|
* Makes Kotlin subclass of Objective-C class visible for runtime lookup
|
||||||
@@ -60,4 +52,5 @@ annotation class ObjCOutlet
|
|||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
annotation class ExportObjCClass(val name: String = "")
|
@BetaInteropApi
|
||||||
|
public annotation class ExportObjCClass(val name: String = "")
|
||||||
|
|||||||
@@ -1,23 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.native.internal.GCUnsafeCall
|
import kotlin.native.internal.GCUnsafeCall
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
data class Pinned<out T : Any> internal constructor(private val stablePtr: COpaquePointer) {
|
data class Pinned<out T : Any> internal constructor(private val stablePtr: COpaquePointer) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +25,10 @@ data class Pinned<out T : Any> internal constructor(private val stablePtr: COpaq
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun <T : Any> T.pin() = Pinned<T>(createStablePointer(this))
|
fun <T : Any> T.pin() = Pinned<T>(createStablePointer(this))
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
inline fun <T : Any, R> T.usePinned(block: (Pinned<T>) -> R): R {
|
inline fun <T : Any, R> T.usePinned(block: (Pinned<T>) -> R): R {
|
||||||
val pinned = this.pin()
|
val pinned = this.pin()
|
||||||
return try {
|
return try {
|
||||||
@@ -45,43 +38,68 @@ inline fun <T : Any, R> T.usePinned(block: (Pinned<T>) -> R): R {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<ByteArray>.addressOf(index: Int): CPointer<ByteVar> = this.get().addressOfElement(index)
|
fun Pinned<ByteArray>.addressOf(index: Int): CPointer<ByteVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun ByteArray.refTo(index: Int): CValuesRef<ByteVar> = this.usingPinned { addressOf(index) }
|
fun ByteArray.refTo(index: Int): CValuesRef<ByteVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<String>.addressOf(index: Int): CPointer<COpaque> = this.get().addressOfElement(index)
|
fun Pinned<String>.addressOf(index: Int): CPointer<COpaque> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun String.refTo(index: Int): CValuesRef<COpaque> = this.usingPinned { addressOf(index) }
|
fun String.refTo(index: Int): CValuesRef<COpaque> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<CharArray>.addressOf(index: Int): CPointer<COpaque> = this.get().addressOfElement(index)
|
fun Pinned<CharArray>.addressOf(index: Int): CPointer<COpaque> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun CharArray.refTo(index: Int): CValuesRef<COpaque> = this.usingPinned { addressOf(index) }
|
fun CharArray.refTo(index: Int): CValuesRef<COpaque> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<ShortArray>.addressOf(index: Int): CPointer<ShortVar> = this.get().addressOfElement(index)
|
fun Pinned<ShortArray>.addressOf(index: Int): CPointer<ShortVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun ShortArray.refTo(index: Int): CValuesRef<ShortVar> = this.usingPinned { addressOf(index) }
|
fun ShortArray.refTo(index: Int): CValuesRef<ShortVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<IntArray>.addressOf(index: Int): CPointer<IntVar> = this.get().addressOfElement(index)
|
fun Pinned<IntArray>.addressOf(index: Int): CPointer<IntVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun IntArray.refTo(index: Int): CValuesRef<IntVar> = this.usingPinned { addressOf(index) }
|
fun IntArray.refTo(index: Int): CValuesRef<IntVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<LongArray>.addressOf(index: Int): CPointer<LongVar> = this.get().addressOfElement(index)
|
fun Pinned<LongArray>.addressOf(index: Int): CPointer<LongVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun LongArray.refTo(index: Int): CValuesRef<LongVar> = this.usingPinned { addressOf(index) }
|
fun LongArray.refTo(index: Int): CValuesRef<LongVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
// TODO: pinning of unsigned arrays involves boxing as they are inline classes wrapping signed arrays.
|
// TODO: pinning of unsigned arrays involves boxing as they are inline classes wrapping signed arrays.
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<UByteArray>.addressOf(index: Int): CPointer<UByteVar> = this.get().addressOfElement(index)
|
fun Pinned<UByteArray>.addressOf(index: Int): CPointer<UByteVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UByteArray.refTo(index: Int): CValuesRef<UByteVar> = this.usingPinned { addressOf(index) }
|
fun UByteArray.refTo(index: Int): CValuesRef<UByteVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<UShortArray>.addressOf(index: Int): CPointer<UShortVar> = this.get().addressOfElement(index)
|
fun Pinned<UShortArray>.addressOf(index: Int): CPointer<UShortVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UShortArray.refTo(index: Int): CValuesRef<UShortVar> = this.usingPinned { addressOf(index) }
|
fun UShortArray.refTo(index: Int): CValuesRef<UShortVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<UIntArray>.addressOf(index: Int): CPointer<UIntVar> = this.get().addressOfElement(index)
|
fun Pinned<UIntArray>.addressOf(index: Int): CPointer<UIntVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun UIntArray.refTo(index: Int): CValuesRef<UIntVar> = this.usingPinned { addressOf(index) }
|
fun UIntArray.refTo(index: Int): CValuesRef<UIntVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<ULongArray>.addressOf(index: Int): CPointer<ULongVar> = this.get().addressOfElement(index)
|
fun Pinned<ULongArray>.addressOf(index: Int): CPointer<ULongVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun ULongArray.refTo(index: Int): CValuesRef<ULongVar> = this.usingPinned { addressOf(index) }
|
fun ULongArray.refTo(index: Int): CValuesRef<ULongVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<FloatArray>.addressOf(index: Int): CPointer<FloatVar> = this.get().addressOfElement(index)
|
fun Pinned<FloatArray>.addressOf(index: Int): CPointer<FloatVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun FloatArray.refTo(index: Int): CValuesRef<FloatVar> = this.usingPinned { addressOf(index) }
|
fun FloatArray.refTo(index: Int): CValuesRef<FloatVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun Pinned<DoubleArray>.addressOf(index: Int): CPointer<DoubleVar> = this.get().addressOfElement(index)
|
fun Pinned<DoubleArray>.addressOf(index: Int): CPointer<DoubleVar> = this.get().addressOfElement(index)
|
||||||
|
@ExperimentalForeignApi
|
||||||
fun DoubleArray.refTo(index: Int): CValuesRef<DoubleVar> = this.usingPinned { addressOf(index) }
|
fun DoubleArray.refTo(index: Int): CValuesRef<DoubleVar> = this.usingPinned { addressOf(index) }
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
private inline fun <T : Any, P : CPointed> T.usingPinned(
|
private inline fun <T : Any, P : CPointed> T.usingPinned(
|
||||||
crossinline block: Pinned<T>.() -> CPointer<P>
|
crossinline block: Pinned<T>.() -> CPointer<P>
|
||||||
) = object : CValuesRef<P>() {
|
) = object : CValuesRef<P>() {
|
||||||
|
|||||||
+8
@@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
package kotlinx.cinterop.internal
|
package kotlinx.cinterop.internal
|
||||||
|
|
||||||
|
import kotlin.native.internal.InternalForKotlinNative
|
||||||
|
|
||||||
|
@InternalForKotlinNative
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class CStruct(val spelling: String) {
|
annotation class CStruct(val spelling: String) {
|
||||||
@@ -38,6 +42,7 @@ annotation class CStruct(val spelling: String) {
|
|||||||
AnnotationTarget.PROPERTY_GETTER,
|
AnnotationTarget.PROPERTY_GETTER,
|
||||||
AnnotationTarget.PROPERTY_SETTER
|
AnnotationTarget.PROPERTY_SETTER
|
||||||
)
|
)
|
||||||
|
@InternalForKotlinNative
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
public annotation class CCall(val id: String) {
|
public annotation class CCall(val id: String) {
|
||||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||||
@@ -77,6 +82,7 @@ public annotation class CCall(val id: String) {
|
|||||||
* Collection of annotations that allow to store
|
* Collection of annotations that allow to store
|
||||||
* constant values.
|
* constant values.
|
||||||
*/
|
*/
|
||||||
|
@InternalForKotlinNative
|
||||||
public object ConstantValue {
|
public object ConstantValue {
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
annotation class Byte(val value: kotlin.Byte)
|
annotation class Byte(val value: kotlin.Byte)
|
||||||
@@ -106,6 +112,7 @@ public object ConstantValue {
|
|||||||
* Denotes property that is an alias to some enum entry.
|
* Denotes property that is an alias to some enum entry.
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@InternalForKotlinNative
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
public annotation class CEnumEntryAlias(val entryName: String)
|
public annotation class CEnumEntryAlias(val entryName: String)
|
||||||
|
|
||||||
@@ -113,5 +120,6 @@ public annotation class CEnumEntryAlias(val entryName: String)
|
|||||||
* Stores instance size of the type T: CEnumVar.
|
* Stores instance size of the type T: CEnumVar.
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@InternalForKotlinNative
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.BINARY)
|
||||||
public annotation class CEnumVarTypeSize(val size: Int)
|
public annotation class CEnumVarTypeSize(val size: Int)
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o.
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the LICENSE file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
@@ -24,3 +13,10 @@ dependencies {
|
|||||||
implementation project(":kotlin-native:Interop:Indexer")
|
implementation project(":kotlin-native:Interop:Indexer")
|
||||||
implementation project(":kotlin-native:Interop:StubGenerator")
|
implementation project(":kotlin-native:Interop:StubGenerator")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions.freeCompilerArgs = [
|
||||||
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
||||||
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
+2
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.kotlin.native.interop.gen
|
package org.jetbrains.kotlin.native.interop.gen
|
||||||
|
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
||||||
import org.jetbrains.kotlin.native.interop.indexer.*
|
import org.jetbrains.kotlin.native.interop.indexer.*
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
@@ -114,6 +115,7 @@ class StubIrTextEmitter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
out("@file:Suppress(${suppress.joinToString { it.quoteAsKotlinLiteral() }})")
|
out("@file:Suppress(${suppress.joinToString { it.quoteAsKotlinLiteral() }})")
|
||||||
|
out("@file:OptIn(ExperimentalForeignApi::class)")
|
||||||
if (pkgName != "") {
|
if (pkgName != "") {
|
||||||
out("package ${context.validPackageName}")
|
out("package ${context.validPackageName}")
|
||||||
out("")
|
out("")
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cpp.CppConsumerPlugin
|
import org.jetbrains.kotlin.cpp.CppConsumerPlugin
|
||||||
import org.jetbrains.kotlin.cpp.CppUsage
|
import org.jetbrains.kotlin.cpp.CppUsage
|
||||||
import org.jetbrains.kotlin.cpp.DependencyHandlerExKt
|
import org.jetbrains.kotlin.cpp.DependencyHandlerExKt
|
||||||
import org.jetbrains.kotlin.tools.NativePluginKt
|
import org.jetbrains.kotlin.tools.NativePluginKt
|
||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
buildscript {
|
buildscript {
|
||||||
apply from: "../../kotlin-native/gradle/kotlinGradlePlugin.gradle"
|
apply from: "../../kotlin-native/gradle/kotlinGradlePlugin.gradle"
|
||||||
apply plugin: 'project-report'
|
apply plugin: 'project-report'
|
||||||
@@ -31,7 +34,12 @@ sourceSets {
|
|||||||
|
|
||||||
compileCompilerKotlin {
|
compileCompilerKotlin {
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
kotlinOptions.freeCompilerArgs += ['-opt-in=kotlin.RequiresOptIn', '-opt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI', '-Xskip-prerelease-check']
|
kotlinOptions.freeCompilerArgs += [
|
||||||
|
'-opt-in=kotlin.RequiresOptIn',
|
||||||
|
'-opt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI',
|
||||||
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
||||||
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
||||||
|
'-Xskip-prerelease-check']
|
||||||
}
|
}
|
||||||
|
|
||||||
compileCli_bcKotlin {
|
compileCli_bcKotlin {
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ if (!isExperimentalMM) {
|
|||||||
|
|
||||||
tasks.withType(KonanCompileNativeBinary).configureEach {
|
tasks.withType(KonanCompileNativeBinary).configureEach {
|
||||||
extraOpts "-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion"
|
extraOpts "-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion"
|
||||||
|
extraOpts "-opt-in=kotlinx.cinterop.ExperimentalForeignApi"
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
package codegen.bridges.nativePointed
|
package codegen.bridges.nativePointed
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
package codegen.funInterface.kt43887
|
package codegen.funInterface.kt43887
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package codegen.intrinsics.interop_convert
|
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
package codegen.intrinsics.interop_convert
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
|
||||||
|
|
||||||
package codegen.intrinsics.interop_sourceCodeStruct
|
package codegen.intrinsics.interop_sourceCodeStruct
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
@@ -5,8 +8,8 @@ import kotlinx.cinterop.internal.*
|
|||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
|
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
|
||||||
// (however defining structs this way is still strongly discouraged, please define
|
// Used by auto-generated code, user-defined structs should be declared via
|
||||||
// structs in C headers or .def files instead).
|
// structs in C headers or .def files instead.
|
||||||
|
|
||||||
@CStruct("struct { int p0; int p1; }")
|
@CStruct("struct { int p0; int p1; }")
|
||||||
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use
|
||||||
|
* of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import signext_zeroext_interop_input.*
|
import signext_zeroext_interop_input.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import auxiliaryCppSources.*
|
import auxiliaryCppSources.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import sysstat.*
|
import sysstat.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cstdlib.*
|
import cstdlib.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cstdio.*
|
import cstdio.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import platform.posix.printf
|
import platform.posix.printf
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import carrayPointers.*
|
import carrayPointers.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import bitfields.*
|
import bitfields.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import sockets.*
|
import sockets.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cenums.*
|
import cenums.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import cfunptr.*
|
import cfunptr.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import cglobals.*
|
import cglobals.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import cmacros.*
|
import cmacros.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import platform.GLUT.*
|
import platform.GLUT.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import structAnonym.*
|
import structAnonym.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cstructs.*
|
import cstructs.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import ctoKString.*
|
import ctoKString.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cunion.*
|
import cunion.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import cvalues.*
|
import cvalues.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.*
|
import kotlin.native.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
@file:Suppress("OPT_IN_USAGE_ERROR")
|
@file:Suppress("OPT_IN_USAGE_ERROR")
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
@file:Suppress("OPT_IN_USAGE_ERROR")
|
@file:Suppress("OPT_IN_USAGE_ERROR")
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlin.random.*
|
import kotlin.random.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlinx.cinterop.staticCFunction
|
import kotlinx.cinterop.staticCFunction
|
||||||
import cCallback.runAndCatch
|
import cCallback.runAndCatch
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// This test mostly checks frontend behaviour.
|
// This test mostly checks frontend behaviour.
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cForwardDeclarations.*
|
import cForwardDeclarations.*
|
||||||
import cnames.structs.StructDeclared
|
import cnames.structs.StructDeclared
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// This test mostly checks frontend behaviour.
|
// This test mostly checks frontend behaviour.
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import cForwardDeclarationsTwoLibs1.*
|
import cForwardDeclarationsTwoLibs1.*
|
||||||
import cForwardDeclarationsTwoLibs2.*
|
import cForwardDeclarationsTwoLibs2.*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import library.*
|
import library.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kt51925.*
|
import kt51925.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:OptIn(FreezingIsDeprecated::class)
|
@file:OptIn(FreezingIsDeprecated::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
package runtime.atomics.atomic_smoke
|
package runtime.atomics.atomic_smoke
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(ExperimentalStdlibApi::class, FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
|
@file:OptIn(ExperimentalStdlibApi::class, FreezingIsDeprecated::class,
|
||||||
|
kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.basic.cleaner_basic
|
package runtime.basic.cleaner_basic
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.basic.simd
|
package runtime.basic.simd
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.collections.array5
|
package runtime.collections.array5
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.interop.interop_alloc_value
|
package runtime.interop.interop_alloc_value
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
|
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
import kotlin.native.runtime.GC
|
import kotlin.native.runtime.GC
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class)
|
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.memory.stable_ref_cross_thread_check
|
package runtime.memory.stable_ref_cross_thread_check
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.text.utf8
|
package runtime.text.utf8
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class, ObsoleteWorkersApi::class)
|
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.workers.worker10
|
package runtime.workers.worker10
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class)
|
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package runtime.workers.worker8
|
package runtime.workers.worker8
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import kotlin.native.internal.ExportForCppRuntime
|
|||||||
import kotlin.native.internal.ExportTypeInfo
|
import kotlin.native.internal.ExportTypeInfo
|
||||||
import kotlin.native.internal.GCUnsafeCall
|
import kotlin.native.internal.GCUnsafeCall
|
||||||
import kotlin.native.internal.NativePtrArray
|
import kotlin.native.internal.NativePtrArray
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
|
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package kotlin.concurrent
|
package kotlin.concurrent
|
||||||
|
|
||||||
import kotlinx.cinterop.NativePtr
|
import kotlinx.cinterop.NativePtr
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
import kotlin.reflect.*
|
import kotlin.reflect.*
|
||||||
import kotlin.concurrent.*
|
import kotlin.concurrent.*
|
||||||
@@ -306,6 +307,7 @@ public class AtomicReference<T> {
|
|||||||
@Frozen
|
@Frozen
|
||||||
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
|
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
|
||||||
@SinceKotlin("1.9")
|
@SinceKotlin("1.9")
|
||||||
|
@ExperimentalForeignApi
|
||||||
public class AtomicNativePtr(@Volatile public var value: NativePtr) {
|
public class AtomicNativePtr(@Volatile public var value: NativePtr) {
|
||||||
/**
|
/**
|
||||||
* Atomically sets the value to the given [new value][newValue] and returns the old value.
|
* Atomically sets the value to the given [new value][newValue] and returns the old value.
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native
|
package kotlin.native
|
||||||
|
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import kotlinx.cinterop.NativePtr
|
import kotlinx.cinterop.NativePtr
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
import kotlin.reflect.*
|
import kotlin.reflect.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
@@ -9,6 +10,9 @@ import kotlin.experimental.ExperimentalNativeApi
|
|||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
private const val DEPRECATED_API_MESSAGE = "This API is deprecated without replacement"
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
||||||
public class Continuation0(block: () -> Unit,
|
public class Continuation0(block: () -> Unit,
|
||||||
private val invoker: CPointer<CFunction<(COpaquePointer?) -> Unit>>,
|
private val invoker: CPointer<CFunction<(COpaquePointer?) -> Unit>>,
|
||||||
@@ -33,6 +37,7 @@ public class Continuation0(block: () -> Unit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
||||||
public class Continuation1<T1>(
|
public class Continuation1<T1>(
|
||||||
block: (p1: T1) -> Unit,
|
block: (p1: T1) -> Unit,
|
||||||
@@ -65,6 +70,7 @@ public class Continuation1<T1>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
@OptIn(FreezingIsDeprecated::class, ExperimentalNativeApi::class)
|
||||||
public class Continuation2<T1, T2>(
|
public class Continuation2<T1, T2>(
|
||||||
block: (p1: T1, p2: T2) -> Unit,
|
block: (p1: T1, p2: T2) -> Unit,
|
||||||
@@ -98,16 +104,20 @@ public class Continuation2<T1, T2>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
public fun COpaquePointer.callContinuation0() {
|
public fun COpaquePointer.callContinuation0() {
|
||||||
val single = this.asStableRef<() -> Unit>()
|
val single = this.asStableRef<() -> Unit>()
|
||||||
single.get()()
|
single.get()()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
public fun <T1> COpaquePointer.callContinuation1() {
|
public fun <T1> COpaquePointer.callContinuation1() {
|
||||||
val pair = this.asStableRef<Pair<StableRef<(T1) -> Unit>, T1>>().get()
|
val pair = this.asStableRef<Pair<StableRef<(T1) -> Unit>, T1>>().get()
|
||||||
pair.first.get()(pair.second)
|
pair.first.get()(pair.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(DEPRECATED_API_MESSAGE, level = DeprecationLevel.WARNING)
|
||||||
public fun <T1, T2> COpaquePointer.callContinuation2() {
|
public fun <T1, T2> COpaquePointer.callContinuation2() {
|
||||||
val triple = this.asStableRef<Triple<StableRef<(T1, T2) -> Unit>, T1, T2>>().get()
|
val triple = this.asStableRef<Triple<StableRef<(T1, T2) -> Unit>, T1, T2>>().get()
|
||||||
triple.first.get()(triple.second, triple.third)
|
triple.first.get()(triple.second, triple.third)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalNativeApi
|
import kotlin.experimental.ExperimentalNativeApi
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION")
|
@file:Suppress("DEPRECATION")
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalNativeApi
|
import kotlin.experimental.ExperimentalNativeApi
|
||||||
import kotlin.native.internal.Frozen
|
import kotlin.native.internal.Frozen
|
||||||
import kotlin.concurrent.AtomicReference
|
import kotlin.concurrent.AtomicReference
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
|
||||||
@FreezingIsDeprecated
|
@FreezingIsDeprecated
|
||||||
|
|
||||||
internal class FreezeAwareLazyImpl<out T>(initializer: () -> T) : Lazy<T> {
|
internal class FreezeAwareLazyImpl<out T>(initializer: () -> T) : Lazy<T> {
|
||||||
private val value_ = FreezableAtomicReference<Any?>(UNINITIALIZED)
|
private val value_ = FreezableAtomicReference<Any?>(UNINITIALIZED)
|
||||||
// This cannot be made atomic because of the legacy MM. See https://github.com/JetBrains/kotlin-native/pull/3944
|
// This cannot be made atomic because of the legacy MM. See https://github.com/JetBrains/kotlin-native/pull/3944
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
@@ -77,6 +77,7 @@ public class DetachedObjectGraph<T> internal constructor(pointer: NativePtr) {
|
|||||||
/**
|
/**
|
||||||
* Returns raw C pointer value, usable for interoperability with C scenarious.
|
* Returns raw C pointer value, usable for interoperability with C scenarious.
|
||||||
*/
|
*/
|
||||||
|
@ExperimentalForeignApi
|
||||||
public fun asCPointer(): COpaquePointer? = interpretCPointer<COpaque>(stable.value)
|
public fun asCPointer(): COpaquePointer? = interpretCPointer<COpaque>(stable.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalNativeApi
|
import kotlin.experimental.ExperimentalNativeApi
|
||||||
|
|||||||
+4
-1
@@ -1,11 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.concurrent
|
package kotlin.native.concurrent
|
||||||
|
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_WorkerBoundReference_create")
|
@GCUnsafeCall("Kotlin_WorkerBoundReference_create")
|
||||||
@ObsoleteWorkersApi
|
@ObsoleteWorkersApi
|
||||||
@@ -35,6 +37,7 @@ external private fun describeWorkerBoundReference(ref: NativePtr): String
|
|||||||
@HasFreezeHook
|
@HasFreezeHook
|
||||||
@FreezingIsDeprecated
|
@FreezingIsDeprecated
|
||||||
@ObsoleteWorkersApi
|
@ObsoleteWorkersApi
|
||||||
|
@OptIn(ExperimentalForeignApi::class)
|
||||||
public class WorkerBoundReference<out T : Any>(value: T) {
|
public class WorkerBoundReference<out T : Any>(value: T) {
|
||||||
|
|
||||||
private var ptr = NativePtr.NULL
|
private var ptr = NativePtr.NULL
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
|
|
||||||
import kotlinx.cinterop.CPointer
|
import kotlinx.cinterop.CPointer
|
||||||
import kotlinx.cinterop.NativePointed
|
import kotlinx.cinterop.NativePointed
|
||||||
import kotlinx.cinterop.NativePtr
|
import kotlinx.cinterop.NativePtr
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
|
||||||
import kotlin.native.internal.TypedIntrinsic
|
import kotlin.native.internal.TypedIntrinsic
|
||||||
import kotlin.native.internal.IntrinsicType
|
import kotlin.native.internal.IntrinsicType
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
@ExportForCompiler
|
@ExportForCompiler
|
||||||
internal class KClassImpl<T : Any>(private val typeInfo: NativePtr) : KClass<T> {
|
internal class KClassImpl<T : Any>(private val typeInfo: NativePtr) : KClass<T> {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
@file:Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
|
@file:Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
|
||||||
|
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
|
|
||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
@TypedIntrinsic(IntrinsicType.INTEROP_GET_NATIVE_NULL_PTR)
|
@TypedIntrinsic(IntrinsicType.INTEROP_GET_NATIVE_NULL_PTR)
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal external fun getNativeNullPtr(): NativePtr
|
internal external fun getNativeNullPtr(): NativePtr
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
class NativePtr @PublishedApi internal constructor(private val value: NonNullNativePtr?) {
|
class NativePtr @PublishedApi internal constructor(private val value: NonNullNativePtr?) {
|
||||||
companion object {
|
companion object {
|
||||||
// TODO: make it properly precreated, maybe use an intrinsic for that.
|
// TODO: make it properly precreated, maybe use an intrinsic for that.
|
||||||
|
|||||||
+3
-2
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalNativeApi
|
import kotlin.experimental.ExperimentalNativeApi
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
import kotlin.coroutines.intrinsics.*
|
import kotlin.coroutines.intrinsics.*
|
||||||
import kotlin.coroutines.native.internal.*
|
import kotlin.coroutines.native.internal.*
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR") // Char.toInt()
|
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR") // Char.toInt()
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
@@ -10,6 +11,7 @@ import kotlin.experimental.ExperimentalNativeApi
|
|||||||
import kotlin.internal.getProgressionLastElement
|
import kotlin.internal.getProgressionLastElement
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.native.concurrent.freeze
|
import kotlin.native.concurrent.freeze
|
||||||
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.concurrent.FreezableAtomicReference
|
import kotlin.native.concurrent.FreezableAtomicReference
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
|
|
||||||
package kotlin.native.internal
|
package kotlin.native.internal
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
@ExportForCppRuntime
|
@ExportForCppRuntime
|
||||||
internal fun DescribeObjectForDebugging(typeInfo: NativePtr, address: NativePtr): String {
|
internal fun DescribeObjectForDebugging(typeInfo: NativePtr, address: NativePtr): String {
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.ref
|
package kotlin.native.ref
|
||||||
|
|
||||||
import kotlin.experimental.ExperimentalNativeApi
|
import kotlin.experimental.ExperimentalNativeApi
|
||||||
import kotlin.native.concurrent.*
|
import kotlin.native.concurrent.*
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
import kotlinx.cinterop.NativePtr
|
import kotlinx.cinterop.NativePtr
|
||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The marker interface for objects that have a cleanup action associated with them.
|
* The marker interface for objects that have a cleanup action associated with them.
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.ref
|
package kotlin.native.ref
|
||||||
|
|
||||||
import kotlinx.cinterop.COpaquePointer
|
import kotlinx.cinterop.*
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalForeignApi::class)
|
||||||
package kotlin.native.runtime
|
package kotlin.native.runtime
|
||||||
|
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
package kotlin.native
|
package kotlin.native
|
||||||
@@ -7,8 +7,10 @@ package kotlin.native
|
|||||||
import kotlin.native.internal.GCUnsafeCall
|
import kotlin.native.internal.GCUnsafeCall
|
||||||
import kotlin.native.internal.TypedIntrinsic
|
import kotlin.native.internal.TypedIntrinsic
|
||||||
import kotlin.native.internal.IntrinsicType
|
import kotlin.native.internal.IntrinsicType
|
||||||
|
import kotlinx.cinterop.ExperimentalForeignApi
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
public final class Vector128 private constructor() {
|
public final class Vector128 private constructor() {
|
||||||
@TypedIntrinsic(IntrinsicType.EXTRACT_ELEMENT)
|
@TypedIntrinsic(IntrinsicType.EXTRACT_ELEMENT)
|
||||||
external fun getByteAt(index: Int): Byte
|
external fun getByteAt(index: Int): Byte
|
||||||
@@ -52,8 +54,10 @@ public final class Vector128 private constructor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@GCUnsafeCall("Kotlin_Vector4f_of")
|
@GCUnsafeCall("Kotlin_Vector4f_of")
|
||||||
external fun vectorOf(f0: Float, f1: Float, f2: Float, f3: Float): Vector128
|
external fun vectorOf(f0: Float, f1: Float, f2: Float, f3: Float): Vector128
|
||||||
|
|
||||||
|
@ExperimentalForeignApi
|
||||||
@GCUnsafeCall("Kotlin_Vector4i32_of")
|
@GCUnsafeCall("Kotlin_Vector4i32_of")
|
||||||
external fun vectorOf(f0: Int, f1: Int, f2: Int, f3: Int): Vector128
|
external fun vectorOf(f0: Int, f1: Int, f2: Int, f3: Int): Vector128
|
||||||
|
|||||||
Reference in New Issue
Block a user