backend/tests: add interop3 (uses callback)
This commit is contained in:
committed by
SvyatoslavScherbina
parent
9e716291c1
commit
a85d30215d
@@ -1359,6 +1359,12 @@ task interop2(type: RunInteropKonanTest) {
|
|||||||
interop = 'cstdio'
|
interop = 'cstdio'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task interop3(type: RunInteropKonanTest) {
|
||||||
|
goldValue = "8 9 12 13 14 \n"
|
||||||
|
source = "interop/basics/3.kt"
|
||||||
|
interop = 'cstdlib'
|
||||||
|
}
|
||||||
|
|
||||||
task interop_echo_server(type: RunInteropKonanTest) {
|
task interop_echo_server(type: RunInteropKonanTest) {
|
||||||
if (isLinux()) {
|
if (isLinux()) {
|
||||||
disabled = true
|
disabled = true
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
memScoped {
|
||||||
|
val count = 5
|
||||||
|
|
||||||
|
val values = allocArray<CInt32Var>(count)
|
||||||
|
values[0].value = 14
|
||||||
|
values[1].value = 12
|
||||||
|
values[2].value = 9
|
||||||
|
values[3].value = 13
|
||||||
|
values[4].value = 8
|
||||||
|
|
||||||
|
cstdlib.qsort(values[0].ptr, count.toLong(), CInt32Var.size, staticCFunction(::comparator))
|
||||||
|
|
||||||
|
for (i in 0 .. count - 1) {
|
||||||
|
print(values[i].value)
|
||||||
|
print(" ")
|
||||||
|
}
|
||||||
|
println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun comparator(a: COpaquePointer?, b: COpaquePointer?): Int {
|
||||||
|
val aValue = a!!.reinterpret<CInt32Var>().pointed.value
|
||||||
|
val bValue = b!!.reinterpret<CInt32Var>().pointed.value
|
||||||
|
|
||||||
|
return (aValue - bValue)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user