Interop: add minor improvements
This commit is contained in:
@@ -195,4 +195,8 @@ class Arena : Placement, Closeable {
|
||||
|
||||
override fun close() = clear()
|
||||
|
||||
}
|
||||
|
||||
fun <T : NativeRef> Placement.alloc(type: NativeRef.TypeWithSize<T>): T {
|
||||
return type.byPtr(this.alloc(type.size))
|
||||
}
|
||||
@@ -19,14 +19,16 @@ fun free(ptr: NativePtr?) {
|
||||
|
||||
fun free(ref: NativeRef?) = free(ref.getNativePtr())
|
||||
|
||||
fun <T : NativeRef> mallocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?): NativeArray<RefBox<T>> {
|
||||
val res = malloc(array[elements.size](elemType.ref))
|
||||
fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?): NativeArray<RefBox<T>> {
|
||||
val res = this.alloc(array[elements.size](elemType.ref))
|
||||
elements.forEachIndexed { i, element ->
|
||||
res[i].value = element
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fun <T : NativeRef> mallocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?) = heap.allocNativeArrayOf(elemType, *elements)
|
||||
|
||||
fun CString.Companion.fromString(str: String?): CString? {
|
||||
if (str == null) {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user