diff --git a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt index ecb5aa053bc..d6b06f3c1f2 100644 --- a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt +++ b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt @@ -361,6 +361,20 @@ val String.cstr: CValues } } +/** + * Convert this list of Kotlin strings to C array of C strings, + * allocating memory for the array and C strings with given [AutofreeScope]. + */ +fun List.toCStringArray(autofreeScope: AutofreeScope): CPointer> = + autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) }) + +/** + * Convert this array of Kotlin strings to C array of C strings, + * allocating memory for the array and C strings with given [AutofreeScope]. + */ +fun Array.toCStringArray(autofreeScope: AutofreeScope): CPointer> = + autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) }) + val String.wcstr: CValues get() { val chars = CharArray(this.length, { i -> this.get(i)})