Skip to content

Commit

Permalink
Memory release fix, Kotlin upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Oct 28, 2023
1 parent a5a532b commit ef3d00a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 275 deletions.
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
GROUP=co.touchlab

VERSION_NAME=1.2.3
KOTLIN_VERSION=1.8.10
KOTLIN_VERSION=1.9.20-RC2

kotlin.native.ignoreDisabledTargets=true

Expand All @@ -26,3 +26,6 @@ POM_DEVELOPER_URL=https://touchlab.co/

kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.commonizerLogLevel=info
kotlin.mpp.applyDefaultHierarchyTemplate=false
kotlin.native.cacheKind.macosArm64=none
kotlin.native.cacheKind.iosSimulatorArm64=none
1 change: 0 additions & 1 deletion gradle/gradle-mvn-mpp-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ publishing {
}

tasks.register('publishWindows') {
dependsOn 'publishMingwX86PublicationToMavenRepository'
dependsOn 'publishMingwX64PublicationToMavenRepository'
}

Expand Down
21 changes: 10 additions & 11 deletions sqliter-driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ fun configInterop(target: org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTar
HostManager.hostIsMingw -> listOf("-linker-options", "-lsqlite3 -Lc:\\msys64\\mingw64\\lib")
else -> listOf("-linker-options", "-lsqlite3")
}
kotlinNativeCompilation.kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlin.experimental.ExperimentalNativeApi",
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
"-opt-in=kotlinx.cinterop.BetaInteropApi",
"-Xexpect-actual-classes",
)
}
}

kotlin {
val knTargets = listOf(
macosX64(),
iosX64(),
iosArm64(),
iosArm32(),
macosX64(),
iosX64(),
iosArm64(),
watchosArm32(),
watchosArm64(),
watchosX86(),
watchosX64(),
tvosArm64(),
tvosX64(),
Expand All @@ -47,8 +51,7 @@ kotlin {
tvosSimulatorArm64(),
watchosDeviceArm64(),
mingwX64(),
mingwX86(),
linuxX64()
linuxX64(),
)

knTargets
Expand Down Expand Up @@ -87,10 +90,6 @@ kotlin {
dependsOn(mingwMain)
}

val mingwX86Main = sourceSets.maybeCreate("mingwX86Main").apply {
dependsOn(mingwMain)
}

knTargets.forEach { target ->
when {
target.name.startsWith("mingw") -> {
Expand Down
197 changes: 0 additions & 197 deletions sqliter-driver/buildold.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package co.touchlab.sqliter.interop

import kotlinx.cinterop.*
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.autoreleasepool
import platform.Foundation.NSString
import platform.Foundation.create

actual inline fun bytesToString(bv:CPointer<ByteVar>):String = NSString.create(uTF8String = bv).toString()
actual inline fun bytesToString(bv: CPointer<ByteVar>): String = autoreleasepool {
NSString.create(uTF8String = bv).toString()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import platform.posix.usleep

expect inline fun bytesToString(bv:CPointer<ByteVar>):String

private const val EMPTY_STRING = ""

internal class ActualSqliteStatement(private val db: SqliteDatabase, private val stmtPointer: SqliteStatementPointer) :
SqliteStatement {

Expand All @@ -21,7 +23,7 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val

override fun columnGetString(columnIndex: Int): String =
sqlite3_column_text(stmtPointer, columnIndex)?.reinterpret<ByteVar>()?.let { bytesToString(it) }
?: ""
?: EMPTY_STRING

override fun columnGetBlob(columnIndex: Int): ByteArray {
val blobSize = sqlite3_column_bytes(stmtPointer, columnIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package co.touchlab.sqliter.interop
import cnames.structs.sqlite3_stmt
import kotlinx.cinterop.CPointer

typealias SqliteDatabasePointer = CPointer<co.touchlab.sqliter.sqlite3.sqlite3>
typealias SqliteDatabasePointer = CPointer<cnames.structs.sqlite3>
typealias SqliteStatementPointer = CPointer<sqlite3_stmt>
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import co.touchlab.sqliter.concurrency.withLock
import co.touchlab.sqliter.interop.SqliteDatabase
import co.touchlab.sqliter.interop.SqliteDatabasePointer
import co.touchlab.sqliter.util.maybeFreeze
import kotlin.native.concurrent.AtomicInt
import kotlin.native.concurrent.AtomicReference
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.AtomicReference

class NativeDatabaseConnection internal constructor(
val dbManager: NativeDatabaseManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import co.touchlab.sqliter.concurrency.withLock
import co.touchlab.sqliter.interop.OpenFlags
import co.touchlab.sqliter.interop.dbOpen
import co.touchlab.sqliter.util.maybeFreeze
import kotlin.native.concurrent.AtomicInt
import kotlin.concurrent.AtomicInt

class NativeDatabaseManager(private val path:String,
override val configuration: DatabaseConfiguration
Expand Down Expand Up @@ -108,3 +108,7 @@ class NativeDatabaseManager(private val path:String,
configuration.lifecycleConfig.onCloseConnection(connection)
}
}

fun AtomicInt.increment() {
incrementAndGet()
}
Loading

0 comments on commit ef3d00a

Please sign in to comment.