Hide nativeMemUtils and pointerSize

This commit is contained in:
Svyatoslav Scherbina
2017-09-15 11:39:16 +03:00
committed by SvyatoslavScherbina
parent 388aba5040
commit d8ed1f4414
5 changed files with 18 additions and 10 deletions
@@ -34,9 +34,11 @@ private val dataModel: DataModel = when (System.getProperty("sun.arch.data.model
}
// Must be only used in interop, contains host pointer size, not target!
val pointerSize: Int = dataModel.pointerSize.toInt()
@PublishedApi
internal val pointerSize: Int = dataModel.pointerSize.toInt()
object nativeMemUtils {
@PublishedApi
internal object nativeMemUtils {
fun getByte(mem: NativePointed) = unsafe.getByte(mem.address)
fun putByte(mem: NativePointed, value: Byte) = unsafe.putByte(mem.address, value)
@@ -379,3 +379,9 @@ inline fun <R> memScoped(block: MemScope.()->R): R {
memScope.clear()
}
}
fun COpaquePointer.readBytes(count: Int): ByteArray {
val result = ByteArray(count)
nativeMemUtils.getByteArray(this.reinterpret<ByteVar>().pointed, result, count)
return result
}
@@ -2,13 +2,16 @@ package kotlinx.cinterop
import konan.internal.Intrinsic
inline val pointerSize: Int
@PublishedApi
internal inline val pointerSize: Int
get() = getPointerSize()
@Intrinsic external fun getPointerSize(): Int
@PublishedApi
@Intrinsic internal external fun getPointerSize(): Int
// TODO: do not use singleton because it leads to init-check on any access.
object nativeMemUtils {
@PublishedApi
internal object nativeMemUtils {
@Intrinsic external fun getByte(mem: NativePointed): Byte
@Intrinsic external fun putByte(mem: NativePointed, value: Byte)