Interop: support allocating zero bytes

This commit is contained in:
Svyatoslav Scherbina
2016-11-30 13:14:47 +07:00
committed by SvyatoslavScherbina
parent 0e43e0d0d8
commit 8dc42bbe35
@@ -51,7 +51,10 @@ object nativeMemUtils {
internal class NativeAllocated(override val rawPtr: NativePtr) : 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())
return interpretPointed<NativeAllocated>(address)
}