Skip to content

Commit 801e356

Browse files
committed
Add changes made thus far
1 parent d839e97 commit 801e356

File tree

11 files changed

+26
-14
lines changed

11 files changed

+26
-14
lines changed

packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/MemAllocator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ interface MemAllocator {
6565
/**
6666
* Instantiates a [RealmValue] representing a `realm_value_t` of type `RLM_TYPE_DECIMAL128`.
6767
*/
68-
fun decimal128Transport(value: ULongArray?): RealmValue
68+
fun decimal128Transport(value: Decimal128?): RealmValue
6969

7070
/**
7171
* Instantiates a [RealmValue] representing a `realm_value_t` of type `RLM_TYPE_OBJECT_ID` from

packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmValueAllocator.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ object JvmMemAllocator : MemAllocator {
5151
override fun doubleTransport(value: Double?): RealmValue =
5252
createTransport(value, realm_value_type_e.RLM_TYPE_DOUBLE) { dnum = value!! }
5353

54-
@ExperimentalUnsignedTypes
55-
override fun decimal128Transport(value: ULongArray?): RealmValue =
54+
override fun decimal128Transport(value: Decimal128?): RealmValue =
5655
createTransport(value, realm_value_type_e.RLM_TYPE_DECIMAL128) {
5756
decimal128 = realm_decimal128_t().apply {
58-
w = value!!.toLongArray()
57+
w = longArrayOf(value!!.low.toLong(), value.high.toLong())
5958
}
60-
}
59+
}
6160

6261
override fun objectIdTransport(value: ByteArray?): RealmValue =
6362
createTransport(value, realm_value_type_e.RLM_TYPE_OBJECT_ID) {

packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmValue.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.realm.kotlin.internal.interop
1818

1919
import kotlinx.cinterop.addressOf
20+
import kotlinx.cinterop.get
2021
import kotlinx.cinterop.memScoped
2122
import kotlinx.cinterop.usePinned
2223
import org.mongodb.kbson.Decimal128

packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmValueAllocator.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ class NativeMemAllocator : MemTrackingAllocator {
6868
createTransport(value, realm_value_type.RLM_TYPE_DOUBLE) { dnum = value!! }
6969

7070
@OptIn(ExperimentalUnsignedTypes::class)
71-
override fun decimal128Transport(value: ULongArray?): RealmValue =
71+
override fun decimal128Transport(value: Decimal128?): RealmValue =
7272
createTransport(value, realm_value_type.RLM_TYPE_DECIMAL128) {
7373
decimal128.apply {
74-
value!!.usePinned {
75-
val dest = w.getPointer(scope)
76-
val source = it.addressOf(0)
77-
memcpy(dest, source, 2.toULong())
74+
val valueArray = ULongArray(2) {
75+
if (it == 0) value!!.low else value!!.high
76+
}
77+
(0 until 2).map {
78+
w[it] = valueArray[it]
7879
}
7980
}
8081
}

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/Converters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ internal object Decimal128Converter : PassThroughPublicConverter<Decimal128>() {
164164
if (realmValue.isNull()) null else realmValueToDecimal128(realmValue)
165165

166166
override inline fun MemTrackingAllocator.toRealmValue(value: Decimal128?): RealmValue =
167-
TODO("BsonDecimal128 doesn't expose 'high' and 'low' so we can't create transport objects towards the C-API yet.")
167+
decimal128Transport(value)
168168
}
169169

170170
// Converter for Core INT storage type (i.e. Byte, Short, Int and Char public types )

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmObjectHelper.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ internal object RealmObjectHelper {
196196
is Timestamp -> setValueTransportByKey(obj, key, timestampTransport(value))
197197
is Float -> setValueTransportByKey(obj, key, floatTransport(value))
198198
is Double -> setValueTransportByKey(obj, key, doubleTransport(value))
199-
is Decimal128 -> setValueTransportByKey(obj, key, decimal128Transport(ULongArray(2) {
200-
i -> if (i == 0) value.low else value.high
201-
}))
199+
is Decimal128 -> setValueTransportByKey(obj, key, decimal128Transport(value))
202200
is BsonObjectId -> setValueTransportByKey(
203201
obj,
204202
key,

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/query/ObjectQuery.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ internal class ObjectQuery<E : BaseRealmObject> constructor(
176176

177177
private fun parseQuery(): RealmQueryPointer = tryCatchCoreException {
178178
inputScope {
179+
// val args1 = convertToQueryArgs(args)
179180
RealmInterop.realm_query_parse(
180181
realmReference.dbPointer,
181182
classKey,

packages/test-base/src/androidAndroidTest/kotlin/io/realm/kotlin/test/shared/ImportTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import io.realm.kotlin.types.RealmInstant
3030
import io.realm.kotlin.types.RealmObject
3131
import io.realm.kotlin.types.RealmUUID
3232
import org.mongodb.kbson.BsonObjectId
33+
import org.mongodb.kbson.Decimal128
3334
import kotlin.test.AfterTest
3435
import kotlin.test.BeforeTest
3536
import kotlin.test.Test
@@ -83,6 +84,7 @@ class ImportTests {
8384
Boolean::class -> assertEquals(true, managed.booleanField)
8485
Float::class -> assertEquals(3.14f, managed.floatField)
8586
Double::class -> assertEquals(1.19840122, managed.doubleField)
87+
Decimal128::class -> assertEquals(Decimal128("1.8446744073709551618E-6157"), managed.decimal128Field)
8688
RealmInstant::class -> assertEquals(RealmInstant.from(100, 1000), managed.timestampField)
8789
ObjectId::class -> assertEquals(ObjectId.from("507f1f77bcf86cd799439011"), managed.objectIdField)
8890
BsonObjectId::class -> assertEquals(BsonObjectId("507f1f77bcf86cd799439011"), managed.bsonObjectIdField)

packages/test-base/src/androidAndroidTest/kotlin/io/realm/kotlin/test/shared/MutableRealmTests.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import io.realm.kotlin.test.platform.PlatformUtils
3636
import io.realm.kotlin.types.RealmInstant
3737
import kotlinx.coroutines.delay
3838
import kotlinx.coroutines.runBlocking
39+
import org.mongodb.kbson.Decimal128
3940
import kotlin.test.AfterTest
4041
import kotlin.test.BeforeTest
4142
import kotlin.test.Test
@@ -177,6 +178,7 @@ class MutableRealmTests {
177178
booleanField = false
178179
floatField = 42.42f
179180
doubleField = 42.42
181+
decimal128Field = Decimal128("1.8446744073709551618E-6157")
180182
timestampField = RealmInstant.from(42, 42)
181183

182184
nullableStringField = "UPDATED"
@@ -188,6 +190,7 @@ class MutableRealmTests {
188190
nullableBooleanField = false
189191
nullableFloatField = 42.42f
190192
nullableDoubleField = 42.42
193+
nullableDecimal128Field = Decimal128("1.8446744073709551618E-6157")
191194
nullableTimestampField = RealmInstant.from(42, 42)
192195
nullableObject = this
193196

@@ -228,6 +231,7 @@ class MutableRealmTests {
228231
assertEquals(false, booleanField)
229232
assertEquals(42.42f, floatField)
230233
assertEquals(42.42, doubleField)
234+
assertEquals(Decimal128("1.8446744073709551618E-6157"), decimal128Field)
231235
assertEquals(RealmInstant.from(42, 42), timestampField)
232236

233237
assertEquals("UPDATED", nullableStringField)
@@ -239,6 +243,7 @@ class MutableRealmTests {
239243
assertEquals(false, nullableBooleanField)
240244
assertEquals(42.42f, nullableFloatField)
241245
assertEquals(42.42, nullableDoubleField)
246+
assertEquals(Decimal128("1.8446744073709551618E-6157"), nullableDecimal128Field)
242247
assertEquals(RealmInstant.from(42, 42), nullableTimestampField)
243248
assertEquals(primaryKey, nullableObject!!.primaryKey)
244249

packages/test-base/src/commonMain/kotlin/io/realm/kotlin/entities/Nullability.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import io.realm.kotlin.types.RealmInstant
2222
import io.realm.kotlin.types.RealmObject
2323
import io.realm.kotlin.types.RealmUUID
2424
import org.mongodb.kbson.BsonObjectId
25+
import org.mongodb.kbson.Decimal128
2526

2627
class Nullability : RealmObject {
2728
var stringNullable: String? = null
@@ -36,6 +37,7 @@ class Nullability : RealmObject {
3637

3738
var floatNullable: Float? = null
3839
var doubleField: Double? = null
40+
var decimal128Field: Decimal128? = null
3941
var timestampField: RealmInstant? = null
4042
var objectIdField: ObjectId? = null
4143
var bsonObjectIdField: BsonObjectId? = null

0 commit comments

Comments
 (0)