Hauke Radtki
05/21/2021, 7:24 PMHauke Radtki
05/21/2021, 7:33 PM@Test
fun suspendReturnNativeVar() {
suspend fun NativePlacement.returnStruct(): ULongVar {
val buffer = allocArray<UByteVar>(sizeOf<ULongVar>())
// Any suspending data fetch function
delay(1)
val reinterpret = buffer.reinterpret<ULongVar>()
reinterpret[0] = 0xAAAAu
return reinterpret.pointed
}
runBlocking {
memScoped {
val v = returnStruct()
assertEquals(0xAAAAu, v.value)
}
}
}
Hauke Radtki
05/21/2021, 7:35 PMkotlin.ClassCastException: kotlinx.cinterop.NativePointed cannot be cast to kotlinx.cinterop.ULongVarOf
when the coroutine returns to the calling context (when coroutine dispatches the assignment of val v
)Hauke Radtki
05/21/2021, 7:35 PMHauke Radtki
05/21/2021, 7:43 PM