backend.native: use common/hash to compute hashes for RTTI

This commit is contained in:
Svyatoslav Scherbina
2016-10-19 11:31:42 +03:00
parent 9f5f2eecfc
commit 61e1d91c03
6 changed files with 104 additions and 44 deletions
@@ -2,15 +2,6 @@ package kotlin_native.interop
fun <T : NativeRef> malloc(type: NativeRef.TypeWithSize<T>) = type.byPtr(bridge.malloc(type.size))
inline fun <T : NativeRef, R> malloc(type: NativeRef.TypeWithSize<T>, action: (T) -> R): R {
val ref = malloc(type)
try {
return action(ref)
} finally {
free(ref)
}
}
fun free(ptr: NativePtr?) {
if (ptr != null) {
bridge.free(ptr)
@@ -29,6 +20,14 @@ fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, va
fun <T : NativeRef> mallocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?) = heap.allocNativeArrayOf(elemType, *elements)
fun Placement.allocNativeArrayOf(elements: ByteArray): NativeArray<Int8Box> {
val res = this.alloc(array[elements.size](Int8Box))
elements.forEachIndexed { i, element ->
res[i].value = element
}
return res
}
fun CString.Companion.fromString(str: String?): CString? {
if (str == null) {
return null