Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
api-level: 36
target: google_apis
arch: x86_64
script: ./gradlew connectedCheck
script: ./gradlew androidConnectedCheck
- name: Upload test results
uses: actions/upload-artifact@v4
if: failure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ internal fun Collection.createIndexImpl(name: String, config: IndexConfiguration
is ValueIndexConfiguration -> CBLCollection_CreateValueIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
is FullTextIndexConfiguration -> CBLCollection_CreateFullTextIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
is ArrayIndexConfiguration -> CBLCollection_CreateArrayIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
is VectorIndexConfiguration -> CBLCollection_CreateVectorIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package kotbase

import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.convert
import kotlinx.cinterop.cstr
import libcblite.*
import platform.posix.strdup
import platform.posix.strlen

public actual class VectorIndexConfiguration
Expand Down Expand Up @@ -103,21 +104,20 @@ public actual constructor(
return this
}

internal val actual: CValue<CBLVectorIndexConfiguration>
get() {
val exp = expression
return cValue {
centroids = this@VectorIndexConfiguration.centroids.convert()
dimensions = this@VectorIndexConfiguration.dimensions.convert()
encoding = this@VectorIndexConfiguration.encoding.actual
expression.buf = strdup(exp)
expression.size = strlen(exp)
expressionLanguage = kCBLN1QLLanguage
isLazy = this@VectorIndexConfiguration.isLazy
maxTrainingSize = this@VectorIndexConfiguration.maxTrainingSize.convert()
metric = this@VectorIndexConfiguration.metric.actual
minTrainingSize = this@VectorIndexConfiguration.minTrainingSize.convert()
numProbes = this@VectorIndexConfiguration.numProbes.convert()
}
internal fun actual(scope: AutofreeScope): CValue<CBLVectorIndexConfiguration> {
val exp = expression
return cValue {
centroids = this@VectorIndexConfiguration.centroids.convert()
dimensions = this@VectorIndexConfiguration.dimensions.convert()
encoding = this@VectorIndexConfiguration.encoding.actual
expression.buf = exp.cstr.getPointer(scope)
expression.size = strlen(exp)
expressionLanguage = kCBLN1QLLanguage
isLazy = this@VectorIndexConfiguration.isLazy
maxTrainingSize = this@VectorIndexConfiguration.maxTrainingSize.convert()
metric = this@VectorIndexConfiguration.metric.actual
minTrainingSize = this@VectorIndexConfiguration.minTrainingSize.convert()
numProbes = this@VectorIndexConfiguration.numProbes.convert()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class KermitCouchbaseLiteLogSinkTest : BaseTest() {
}

private fun allowLogsToWrite() = runBlocking {
delay(50)
delay(100)
}

private fun Array<out LogDomain>.toTags() = ifEmpty { LogDomain.ALL.toTypedArray() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class KermitCouchbaseLiteLoggerTest : BaseTest(useLegacyLogging = true) {
}

private fun allowLogsToWrite() = runBlocking {
delay(50)
delay(100)
}

private fun Set<LogDomain>.toTags() = map { "CBL-${it.name}" }.toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ internal fun Collection.createIndexImpl(name: String, config: IndexConfiguration
is ValueIndexConfiguration -> CBLCollection_CreateValueIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
is FullTextIndexConfiguration -> CBLCollection_CreateFullTextIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
is ArrayIndexConfiguration -> CBLCollection_CreateArrayIndex(
actual,
name.toFLString(this),
config.actual,
config.actual(this),
error
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package kotbase

import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.cstr
import libcblite.CBLArrayIndexConfiguration
import libcblite.kCBLN1QLLanguage
import platform.posix.strdup
import platform.posix.strlen

public actual class ArrayIndexConfiguration
Expand All @@ -41,16 +42,15 @@ public actual constructor(
}
}

internal val actual: CValue<CBLArrayIndexConfiguration>
get() {
val exp = expressions.joinToString(separator = ",")
val path = path
return cValue {
expressionLanguage = kCBLN1QLLanguage
expressions.buf = strdup(exp)
expressions.size = strlen(exp)
this.path.buf = strdup(path)
this.path.size = strlen(path)
}
internal fun actual(scope: AutofreeScope): CValue<CBLArrayIndexConfiguration> {
val exp = expressions.joinToString(separator = ",")
val path = path
return cValue {
expressionLanguage = kCBLN1QLLanguage
expressions.buf = exp.cstr.getPointer(scope)
expressions.size = strlen(exp)
this.path.buf = path.cstr.getPointer(scope)
this.path.size = strlen(path)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ internal constructor(
is ValueIndex -> CBLCollection_CreateValueIndex(
actual,
name.toFLString(this),
index.actual,
index.actual(this),
error
)
is FullTextIndex -> CBLCollection_CreateFullTextIndex(
actual,
name.toFLString(this),
index.actual,
index.actual(this),
error
)
else -> error("Unhandled Index type ${index::class}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,13 @@ internal constructor(
is ValueIndex -> CBLDatabase_CreateValueIndex(
actual,
name.toFLString(this),
index.actual,
index.actual(this),
error
)
is FullTextIndex -> CBLDatabase_CreateFullTextIndex(
actual,
name.toFLString(this),
index.actual,
index.actual(this),
error
)
else -> error("Unhandled Index type ${index::class}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.io.files.SystemPathSeparator
import libcblite.CBLDatabaseConfiguration
import libcblite.CBLDatabaseConfiguration_Default
import platform.posix.free
import platform.posix.memset
import platform.posix.strdup
import platform.posix.strlen
import kotlin.experimental.ExperimentalNativeApi
Expand All @@ -33,7 +34,10 @@ public actual constructor(config: DatabaseConfiguration?) {

private val memory = object {
val arena = Arena()
val actual = arena.alloc<CBLDatabaseConfiguration>().ptr
val actual = arena.alloc<CBLDatabaseConfiguration>().ptr.also {
// zero out struct to ensure free() isn't called on a garbage pointer
memset(it, 0, sizeOf<CBLDatabaseConfiguration>().convert())
}
}

@OptIn(ExperimentalNativeApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public actual class FileLogger internal constructor() : Logger {
if (value != null) {
SystemFileSystem.createDirectories(Path(value.directory), false)
}
val actual = value?.getActual(level) ?: LogFileConfiguration.getNullActual()
wrapCBLError { error ->
CBLLog_SetFileConfig(actual, error)
memScoped {
val actual = value?.getActual(level, this) ?: LogFileConfiguration.getNullActual()
wrapCBLError { error ->
CBLLog_SetFileConfig(actual, error)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
package kotbase

import kotbase.internal.JsonUtils
import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.cstr
import libcblite.CBLFullTextIndexConfiguration
import libcblite.kCBLJSONLanguage
import platform.posix.strdup
import platform.posix.strlen

public actual class FullTextIndex
Expand Down Expand Up @@ -50,17 +51,16 @@ internal constructor(private val items: List<FullTextIndexItem>) : Index() {
return JsonUtils.toJson(data)
}

internal val actual: CValue<CBLFullTextIndexConfiguration>
get() {
val json = getJson()
val lang = language
return cValue {
expressionLanguage = kCBLJSONLanguage
expressions.buf = strdup(json)
expressions.size = strlen(json)
language.buf = lang?.let { strdup(it) }
language.size = lang?.let { strlen(it) } ?: 0U
ignoreAccents = isIgnoringAccents
}
internal fun actual(scope: AutofreeScope): CValue<CBLFullTextIndexConfiguration> {
val json = getJson()
val lang = language
return cValue {
expressionLanguage = kCBLJSONLanguage
expressions.buf = json.cstr.getPointer(scope)
expressions.size = strlen(json)
language.buf = lang?.cstr?.getPointer(scope)
language.size = lang?.let { strlen(it) } ?: 0U
ignoreAccents = isIgnoringAccents
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package kotbase

import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.cstr
import libcblite.CBLFullTextIndexConfiguration
import libcblite.kCBLN1QLLanguage
import platform.posix.strdup
import platform.posix.strlen

public actual class FullTextIndexConfiguration
Expand Down Expand Up @@ -65,22 +66,21 @@ public actual constructor(

public actual var where: String? = where

internal val actual: CValue<CBLFullTextIndexConfiguration>
get() {
val exp = expressions.joinToString(separator = ",")
val lang = language
val whr = where
return cValue {
expressionLanguage = kCBLN1QLLanguage
expressions.buf = strdup(exp)
expressions.size = strlen(exp)
language.buf = lang?.let { strdup(it) }
language.size = lang?.let { strlen(it) } ?: 0U
where.buf = whr?.let { strdup(it) }
where.size = whr?.let { strlen(it) } ?: 0U
ignoreAccents = isIgnoringAccents
}
internal fun actual(scope: AutofreeScope): CValue<CBLFullTextIndexConfiguration> {
val exp = expressions.joinToString(separator = ",")
val lang = language
val whr = where
return cValue {
expressionLanguage = kCBLN1QLLanguage
expressions.buf = exp.cstr.getPointer(scope)
expressions.size = strlen(exp)
language.buf = lang?.cstr?.getPointer(scope)
language.size = lang?.let { strlen(it) } ?: 0U
where.buf = whr?.cstr?.getPointer(scope)
where.size = whr?.let { strlen(it) } ?: 0U
ignoreAccents = isIgnoringAccents
}
}

internal actual companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package kotbase

import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.convert
import kotlinx.cinterop.cstr
import libcblite.CBLLogFileConfiguration
import platform.posix.strdup
import platform.posix.strlen

public actual class LogFileConfiguration
Expand Down Expand Up @@ -84,11 +85,11 @@ public actual constructor(public actual val directory: String) {

override fun hashCode(): Int = directory.hashCode()

internal fun getActual(level: LogLevel): CValue<CBLLogFileConfiguration> {
internal fun getActual(level: LogLevel, scope: AutofreeScope): CValue<CBLLogFileConfiguration> {
readonly = true
return cValue {
with(directory) {
buf = strdup(this@LogFileConfiguration.directory)
buf = this@LogFileConfiguration.directory.cstr.getPointer(scope)
size = strlen(this@LogFileConfiguration.directory)
}
this.level = level.actual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
package kotbase

import kotbase.internal.JsonUtils
import kotlinx.cinterop.AutofreeScope
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.cstr
import libcblite.CBLValueIndexConfiguration
import libcblite.kCBLJSONLanguage
import platform.posix.strdup
import platform.posix.strlen

public actual class ValueIndex
Expand All @@ -35,13 +36,12 @@ internal constructor(private val items: List<ValueIndexItem>) : Index() {
return JsonUtils.toJson(data)
}

internal val actual: CValue<CBLValueIndexConfiguration>
get() {
val json = getJson()
return cValue {
expressionLanguage = kCBLJSONLanguage
expressions.buf = strdup(json)
expressions.size = strlen(json)
}
internal fun actual(scope: AutofreeScope): CValue<CBLValueIndexConfiguration> {
val json = getJson()
return cValue {
expressionLanguage = kCBLJSONLanguage
expressions.buf = json.cstr.getPointer(scope)
expressions.size = strlen(json)
}
}
}
Loading