Interop: support allocating zero bytes
This commit is contained in:
committed by
SvyatoslavScherbina
parent
0e43e0d0d8
commit
8dc42bbe35
@@ -51,7 +51,10 @@ object nativeMemUtils {
|
|||||||
internal class NativeAllocated(override val rawPtr: NativePtr) : NativePointed
|
internal class NativeAllocated(override val rawPtr: NativePtr) : NativePointed
|
||||||
|
|
||||||
fun alloc(size: Long, align: Int): NativePointed {
|
fun alloc(size: Long, align: Int): NativePointed {
|
||||||
val address = unsafe.allocateMemory(size)
|
val address = unsafe.allocateMemory(
|
||||||
|
if (size == 0L) 1L else size // It is a hack: `sun.misc.Unsafe` can't allocate zero bytes
|
||||||
|
)
|
||||||
|
|
||||||
if (address % align != 0L) TODO(align.toString())
|
if (address % align != 0L) TODO(align.toString())
|
||||||
return interpretPointed<NativeAllocated>(address)
|
return interpretPointed<NativeAllocated>(address)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user