mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
unsafeptr: specialised exceptions
This commit is contained in:
@@ -7,13 +7,15 @@ import java.io.IOException
|
|||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
class DanglingPointerException(msg: String) : NullPointerException(msg)
|
||||||
|
class AddressOverflowException(msg: String) : IndexOutOfBoundsException(msg)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Further read:
|
* Further read:
|
||||||
* - http://www.docjar.com/docs/api/sun/misc/Unsafe.html
|
* - http://www.docjar.com/docs/api/sun/misc/Unsafe.html
|
||||||
*
|
*
|
||||||
* Created by minjaesong on 2019-06-21.
|
* Created by minjaesong on 2019-06-21.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal object UnsafeHelper {
|
internal object UnsafeHelper {
|
||||||
var unsafeAllocatedSize = 0L
|
var unsafeAllocatedSize = 0L
|
||||||
internal set
|
internal set
|
||||||
@@ -110,8 +112,8 @@ internal class UnsafePtr(pointer: Long, allocSize: Long) {
|
|||||||
// You may break the glass and use this tool when some fucking incomprehensible bugs ("vittujen vitun bugit")
|
// You may break the glass and use this tool when some fucking incomprehensible bugs ("vittujen vitun bugit")
|
||||||
// appear (e.g. getting garbage values when it fucking shouldn't)
|
// appear (e.g. getting garbage values when it fucking shouldn't)
|
||||||
|
|
||||||
assert(!destroyed) { throw NullPointerException("The pointer is already destroyed ($this)") }
|
assert(!destroyed) { throw DanglingPointerException("The pointer is already destroyed ($this)") }
|
||||||
assert(index in 0 until size) { throw IndexOutOfBoundsException("Index: $index; alloc size: $size") }
|
assert(index in 0 until size) { throw AddressOverflowException("Index: $index; alloc size: $size") }
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(index: Long): Byte {
|
operator fun get(index: Long): Byte {
|
||||||
|
|||||||
Reference in New Issue
Block a user