Vlad Balan
03/11/2020, 7:28 AMtypedef struct {
uint8_t a;
} testStructDto;
is translated in Kotlin as follows:
@kotlinx.cinterop.internal.CStruct public final class testStructDto public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
public companion object : kotlinx.cinterop.CStructVar.Type {
}
public final var a: liboverlay.uint8_t /* = kotlin.UByte */ /* compiled code */
}
My Kotlin native function:
@ExperimentalUnsignedTypes
override fun init(): CPointer<testStructDto> {
val dtoVar = nativeHeap.alloc<testStructDto>()
dtoVar.a = 0xa5.toUByte()
return dtoVar.ptr
}
I can use it in Kotlin like this:
@Test
fun `initialize`() {
val context = controller.init()
assertEquals(0xa5.toUByte(), context.pointed.a)
}
But when I try to use it in C like this:
libtest_ExportedSymbols *libPtr = libtest_symbols()
libtest_kref_MyObjectFactory kFactory = libPtr->kotlin.root.MyObjectFactory._instance();
libtest_kref_MyObject kObject = libPtr->kotlin.MyObjectFactory.create(kFactory);
testStructDto *dto = (testStructDto *) libPtr->kotlin.root.MyObject.init(kObject);
I always get
dto->a = 32
I get the value 32
even if I assign something else than 0xa5
.
Does anybody know what I am doing wrong?
Thanks in advance!
Slack Conversation