r4zzz4k
09/20/2018, 1:18 PMoutput.pointed.value = input, for structures I was going to copy bytes and needed size of generic CVariable).
The stuff that breaks:
import kotlinx.cinterop.*
inline fun <reified T : CVariable> sizeOf(value: T) = sizeOf<T>()
fun process(value: Any) {
when (value) {
is Int -> 4
is CVariable -> sizeOf(value)
}
}
fun main() = Unit
The error:
error: compilation failed: native variable class deserialized class CVariable must have the companion object
* Source files: sample.kt
* Compiler version info: Konan: 0.9.1 / Kotlin: 1.3.0
* Output kind: PROGRAM
exception: java.lang.IllegalStateException: native variable class deserialized class CVariable must have the companion objectsvyatoslav.scherbina
09/20/2018, 1:26 PMCVariable class doesn’t have any particular size.svyatoslav.scherbina
09/20/2018, 1:27 PMCValue<*> for structs?r4zzz4k
09/20/2018, 2:45 PMType is present, but is not a companion in these abstract classes. Of course it's logical.
Regarding CValue<T> -- I've forgot about it as I only saw it in function signatures and not entirely understood the idea behind it.
Right now I'm preparing List of `GValue: CStructVar`s, allocated within memScoped block, and in the other place getting them from list and trying to convert the list into void*. Should I use CValue<GValue> in the first place instead?svyatoslav.scherbina
09/20/2018, 2:51 PMShould I useYes, I suppose so. This may seem a bit inconvenient, butin the first place instead?CValue<GValue>
CValue<GValue> corresponds to the value of the structure (which doesn’t depend on any native memory and remains valid after leaving memScoped {}), while GValue is much like a pointer.
For example, CValue<IntVar> is mostly equivalent to Int.r4zzz4k
09/20/2018, 2:52 PMprocess above I should be able to check is CValue<*> and will have .size handy. Cool, thanks, will try!