Hide nativeMemUtils and pointerSize
This commit is contained in:
committed by
SvyatoslavScherbina
parent
388aba5040
commit
d8ed1f4414
@@ -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!
|
// 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 getByte(mem: NativePointed) = unsafe.getByte(mem.address)
|
||||||
fun putByte(mem: NativePointed, value: Byte) = unsafe.putByte(mem.address, value)
|
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()
|
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
|
import konan.internal.Intrinsic
|
||||||
|
|
||||||
inline val pointerSize: Int
|
@PublishedApi
|
||||||
|
internal inline val pointerSize: Int
|
||||||
get() = getPointerSize()
|
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.
|
// 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 getByte(mem: NativePointed): Byte
|
||||||
@Intrinsic external fun putByte(mem: NativePointed, value: Byte)
|
@Intrinsic external fun putByte(mem: NativePointed, value: Byte)
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -57,9 +57,7 @@ public fun base64Decode(encoded: String): ByteArray {
|
|||||||
val errorCode = DecodeBase64(encoded, encoded.length, result, resultSize)
|
val errorCode = DecodeBase64(encoded, encoded.length, result, resultSize)
|
||||||
if (errorCode != 0) throw Error("Non-zero exit code of DecodeBase64: ${errorCode}")
|
if (errorCode != 0) throw Error("Non-zero exit code of DecodeBase64: ${errorCode}")
|
||||||
val realSize = resultSize[0]
|
val realSize = resultSize[0]
|
||||||
val bytes = ByteArray(realSize)
|
return result.readBytes(realSize)
|
||||||
nativeMemUtils.getByteArray(result.pointed, bytes, realSize)
|
|
||||||
return bytes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ class CUrl(val url: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CPointer<ByteVar>.toKString(length: Int): String {
|
fun CPointer<ByteVar>.toKString(length: Int): String {
|
||||||
val bytes = ByteArray(length)
|
val bytes = this.readBytes(length)
|
||||||
nativeMemUtils.getByteArray(pointed, bytes, length)
|
|
||||||
return kotlin.text.fromUtf8Array(bytes, 0, bytes.size)
|
return kotlin.text.fromUtf8Array(bytes, 0, bytes.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user