Implement explicit and implicit object pinning for interop

This allows passing Kotlin primitive arrays directly to native
This commit is contained in:
Svyatoslav Scherbina
2017-09-19 10:08:07 +03:00
committed by SvyatoslavScherbina
parent fd35ccbf2e
commit a6ca64871f
4 changed files with 102 additions and 19 deletions
+11 -19
View File
@@ -1,27 +1,19 @@
import kotlinx.cinterop.*
fun main(args: Array<String>) {
memScoped {
val count = 5
val values = intArrayOf(14, 12, 9, 13, 8)
val count = values.size
val values = allocArray<IntVar>(count)
values[0] = 14
values[1] = 12
values[2] = 9
values[3] = 13
values[4] = 8
cstdlib.qsort(values.refTo(0), count.toLong(), IntVar.size, staticCFunction { a, b ->
val aValue = a!!.reinterpret<IntVar>()[0]
val bValue = b!!.reinterpret<IntVar>()[0]
cstdlib.qsort(values, count.toLong(), IntVar.size, staticCFunction { a, b ->
val aValue = a!!.reinterpret<IntVar>()[0]
val bValue = b!!.reinterpret<IntVar>()[0]
(aValue - bValue)
})
(aValue - bValue)
})
for (i in 0 .. count - 1) {
print(values[i])
print(" ")
}
println()
for (i in 0..count - 1) {
print(values[i])
print(" ")
}
println()
}