f4e8ae5191
* @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>
44 lines
1.1 KiB
Kotlin
44 lines
1.1 KiB
Kotlin
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
|
|
|
|
package codegen.intrinsics.interop_sourceCodeStruct
|
|
|
|
import kotlinx.cinterop.*
|
|
import kotlinx.cinterop.internal.*
|
|
import kotlin.test.*
|
|
|
|
// Just making sure this doesn't get accidentally forbidden or otherwise broken.
|
|
// Used by auto-generated code, user-defined structs should be declared via
|
|
// structs in C headers or .def files instead.
|
|
|
|
@CStruct("struct { int p0; int p1; }")
|
|
class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
|
|
|
companion object : CStructVar.Type(8, 4)
|
|
|
|
var x: Int
|
|
get() = memberAt<IntVar>(0).value
|
|
set(value) {
|
|
memberAt<IntVar>(0).value = value
|
|
}
|
|
|
|
var y: Int
|
|
get() = memberAt<IntVar>(4).value
|
|
set(value) {
|
|
memberAt<IntVar>(4).value = value
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun test() = memScoped {
|
|
val s = alloc<S>()
|
|
|
|
s.x = 123
|
|
assertEquals(123, s.x)
|
|
assertEquals(123, s.ptr.reinterpret<IntVar>()[0])
|
|
|
|
s.y = 321
|
|
assertEquals(321, s.y)
|
|
assertEquals(321, s.ptr.reinterpret<IntVar>()[1])
|
|
}
|