backend: support native interop value types
also improve reliability of `==` lowering
This commit is contained in:
committed by
SvyatoslavScherbina
parent
1bafee0ac3
commit
7f90ce3d8a
@@ -0,0 +1,53 @@
|
||||
package konan.internal
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
class NativePtrBox(val value: NativePtr) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is NativePtrBox) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.value == other.value
|
||||
}
|
||||
|
||||
override fun hashCode() = value.hashCode()
|
||||
|
||||
override fun toString() = value.toString()
|
||||
}
|
||||
|
||||
fun boxNativePtr(value: NativePtr) = NativePtrBox(value)
|
||||
|
||||
class NativePointedBox(val value: NativePointed) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is NativePointedBox) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.value == other.value
|
||||
}
|
||||
|
||||
override fun hashCode() = value.hashCode()
|
||||
|
||||
override fun toString() = value.toString()
|
||||
}
|
||||
|
||||
fun boxNativePointed(value: NativePointed?) = if (value != null) NativePointedBox(value) else null
|
||||
fun unboxNativePointed(box: NativePointedBox?) = box?.value
|
||||
|
||||
class CPointerBox(val value: CPointer<*>) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is CPointerBox) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.value == other.value
|
||||
}
|
||||
|
||||
override fun hashCode() = value.hashCode()
|
||||
|
||||
override fun toString() = value.toString()
|
||||
}
|
||||
|
||||
fun boxCPointer(value: CPointer<*>?) = if (value != null) CPointerBox(value) else null
|
||||
fun unboxCPointer(box: CPointerBox?) = box?.value
|
||||
@@ -1,5 +1,9 @@
|
||||
package konan.internal
|
||||
|
||||
import kotlinx.cinterop.CPointer
|
||||
import kotlinx.cinterop.NativePointed
|
||||
import kotlinx.cinterop.NativePtr
|
||||
|
||||
@Intrinsic external fun areEqualByValue(first: Boolean, second: Boolean): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: Char, second: Char): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: Byte, second: Byte): Boolean
|
||||
@@ -9,9 +13,9 @@ package konan.internal
|
||||
@Intrinsic external fun areEqualByValue(first: Float, second: Float): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: Double, second: Double): Boolean
|
||||
|
||||
// For comparing with `null`:
|
||||
@Intrinsic external fun areEqualByValue(first: Nothing?, second: Any?): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: Any?, second: Nothing?): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: NativePtr, second: NativePtr): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: NativePointed?, second: NativePointed?): Boolean
|
||||
@Intrinsic external fun areEqualByValue(first: CPointer<*>?, second: CPointer<*>?): Boolean
|
||||
|
||||
inline fun areEqual(first: Any?, second: Any?): Boolean {
|
||||
return if (first == null) second == null else first.equals(second)
|
||||
|
||||
Reference in New Issue
Block a user