martmists
12/15/2021, 10:05 AMWhen calling variadic C functions spread operator is supported only for *arrayOf(...)
How can I avoid this? Can I write a wrapper function in the .def or something? I already tried *arrayOf(*x.map { ... }.toTypedArray())
but that was also invalid?Rob Elliot
12/15/2021, 10:23 AMplatform.posix.*
functions for launching a process...martmists
12/15/2021, 10:30 AMRob Elliot
12/15/2021, 10:33 AMCValuesRef<CPointerVar<ByteVar>>
, which I created as so:
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.CPointerVar
import kotlinx.cinterop.CValuesRef
import kotlinx.cinterop.cstr
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toCValues
memScoped {
val args: CValuesRef<CPointerVar<ByteVar>> = listOf("a", "b", "c")
.map { it.cstr.ptr }
.toCValues().ptr
// call c function here
}
Rob Elliot
12/15/2021, 10:36 AMmemscoped
block terminates... since we're passing a pointer to the actual strings / array, I guess the c function had better have finished using them (i.e. it had better be single threaded) or they will be gone.
In my case I'm forking a process... I presume that the strings will be copied into the new process's memory space, otherwise nothing would work?!Rob Elliot
12/15/2021, 10:44 AMCValues
as well to signal it had ended...Rob Elliot
12/15/2021, 10:49 AMkotlinx.cinterop.toCStringArray
might save me a lot of that!martmists
12/15/2021, 10:56 AMjimn
12/18/2021, 1:51 PMjimn
12/18/2021, 1:55 PMmartmists
12/18/2021, 4:49 PMint *PyArg_ParseTupleAndKeywords*(PyObject *_args_, PyObject *_kw_, _const_ char *_format_, char *_keywords_[], ...)
jimn
12/19/2021, 12:53 PMjimn
12/19/2021, 12:56 PM*listOf(outerArgs).toTypedArray<out Any?>()
is as good a shot as any, plus or minus StableRef.create()