Skip to content

Commit e47a7c3

Browse files
authored
Merge pull request #79 from touchlab/psh/address-warnings
Address the various build warnings across the app after updating to 1.7.20 beta
2 parents 4af76e2 + 2f03f73 commit e47a7c3

File tree

11 files changed

+35
-26
lines changed

11 files changed

+35
-26
lines changed

gradle.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
kotlin.code.style=official
22

33
GROUP=co.touchlab
4-
VERSION_NAME=1.2.1
5-
KOTLIN_VERSION=1.6.20
4+
5+
VERSION_NAME=1.2.0
6+
KOTLIN_VERSION=1.7.20-Beta
67

78
kotlin.native.ignoreDisabledTargets=true
89

@@ -23,7 +24,5 @@ POM_DEVELOPER_NAME=Kevin Galligan
2324
POM_DEVELOPER_ORG=Kevin Galligan
2425
POM_DEVELOPER_URL=https://touchlab.co/
2526

26-
kotlin.mpp.enableGranularSourceSetsMetadata=true
27-
kotlin.native.enableDependencyPropagation=false
2827
kotlin.mpp.enableCInteropCommonization=true
2928
kotlin.mpp.commonizerLogLevel=info

sqliter-driver/src/appleMain/kotlin/co/touchlab/sqliter/DatabaseFileContext.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package co.touchlab.sqliter
1818

1919
import co.touchlab.sqliter.internal.File
2020
import co.touchlab.sqliter.internal.FileFilter
21+
import kotlinx.cinterop.UnsafeNumber
2122
import platform.Foundation.NSApplicationSupportDirectory
2223
import platform.Foundation.NSFileManager
2324
import platform.Foundation.NSSearchPathForDirectoriesInDomains
@@ -34,6 +35,7 @@ actual object DatabaseFileContext{
3435

3536
internal fun databaseDirPath():String = iosDirPath("databases")
3637

38+
@OptIn(UnsafeNumber::class)
3739
internal fun iosDirPath(folder:String):String{
3840
val paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
3941
val documentsDirectory = paths[0] as String;

sqliter-driver/src/linuxX64Main/kotlin/co/touchlab/sqliter/DatabaseFileContext.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ actual object DatabaseFileContext {
4646
if (dir != null) {
4747
val prefix = file.getName() + "-mj"
4848
val files = dir.listFiles(object : FileFilter {
49-
override fun accept(candidate: File): Boolean {
50-
return candidate.getName().startsWith(prefix)
49+
override fun accept(pathname: File): Boolean {
50+
return pathname.getName().startsWith(prefix)
5151
}
5252
})
5353
if (files != null) {

sqliter-driver/src/linuxX64Main/kotlin/co/touchlab/sqliter/internal/File.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ internal actual class File(dirPath: String? = null, name: String) {
330330
}
331331
val result = ArrayList<String>(filenames.size)
332332
for (filename in filenames) {
333-
if (filter!!.accept(this, filename)) {
333+
if (filter.accept(this, filename)) {
334334
result.add(filename)
335335
}
336336
}
@@ -389,7 +389,7 @@ internal actual class File(dirPath: String? = null, name: String) {
389389
}
390390
val result = ArrayList<File>(files.size)
391391
for (file in files) {
392-
if (filter!!.accept(file)) {
392+
if (filter.accept(file)) {
393393
result.add(file)
394394
}
395395
}
@@ -407,10 +407,8 @@ internal actual class File(dirPath: String? = null, name: String) {
407407
return null
408408
}
409409
val count = filenames.size
410-
val result = arrayOfNulls<File>(count)
411410

412-
val files = Array<File>(count, { i -> File(this, filenames[i]) })
413-
return files
411+
return Array(count) { i -> File(this, filenames[i]) }
414412
}
415413

416414
/**
@@ -454,6 +452,7 @@ internal actual class File(dirPath: String? = null, name: String) {
454452
return mkdirs(false)
455453
}
456454

455+
@Suppress("UNUSED_PARAMETER")
457456
private fun mkdirs(resultIfExists: Boolean): Boolean {
458457
/* If the terminal directory already exists, answer false */
459458
if (exists()) {

sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/DatabaseFileContext.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ actual object DatabaseFileContext {
2828
if (dir != null) {
2929
val prefix = file.getName() + "-mj"
3030
val files = dir.listFiles(object: FileFilter {
31-
override fun accept(candidate: File):Boolean {
32-
return candidate.getName().startsWith(prefix)
31+
override fun accept(pathname: File):Boolean {
32+
return pathname.getName().startsWith(prefix)
3333
}
3434
})
3535
if (files != null) {

sqliter-driver/src/mingwMain/kotlin/co/touchlab/sqliter/internal/Utils.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package co.touchlab.sqliter.internal
22

33
import kotlinx.cinterop.allocArray
44
import kotlinx.cinterop.memScoped
5+
import kotlinx.cinterop.sizeOf
56
import kotlinx.cinterop.toKString
67
import platform.windows.GetEnvironmentVariableW
78
import platform.windows.WCHARVar
@@ -14,9 +15,9 @@ internal class Utils {
1415
return getEnvironmentVariable("USERPROFILE")
1516
}
1617

17-
fun getEnvironmentVariable(variable: String): String {
18+
private fun getEnvironmentVariable(variable: String): String {
1819
return memScoped {
19-
val size = 1024 * WCHARVar.size
20+
val size = 1024 * sizeOf<WCHARVar>()
2021
val pointer = allocArray<WCHARVar>(size)
2122
GetEnvironmentVariableW(variable, pointer, size.toUInt())
2223
pointer.toKString()

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/concurrency/SingleThreadDatabaseConnection.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
package co.touchlab.sqliter.concurrency
1818

1919
import co.touchlab.sqliter.DatabaseConnection
20-
import kotlin.native.concurrent.ensureNeverFrozen
20+
import co.touchlab.sqliter.util.ensureNeverFrozenIfStrictMM
2121

2222
internal class SingleThreadDatabaseConnection(delegateConnection: DatabaseConnection):DatabaseConnection by delegateConnection
2323
{
2424
init {
25-
if (Platform.memoryModel == MemoryModel.STRICT)
26-
ensureNeverFrozen()
25+
ensureNeverFrozenIfStrictMM()
2726
}
2827
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package co.touchlab.sqliter.util
22

3+
import kotlin.native.concurrent.ensureNeverFrozen
34
import kotlin.native.concurrent.freeze
45

6+
@OptIn(FreezingIsDeprecated::class)
57
internal inline fun <T> T.maybeFreeze(): T = if (Platform.memoryModel == MemoryModel.STRICT) {
68
this.freeze()
79
} else {
810
this
11+
}
12+
13+
@OptIn(FreezingIsDeprecated::class)
14+
internal inline fun <T> T.ensureNeverFrozenIfStrictMM() {
15+
if (Platform.memoryModel == MemoryModel.STRICT)
16+
this?.ensureNeverFrozen()
917
}

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeDatabaseConnectionTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package co.touchlab.sqliter
1818

19+
import co.touchlab.sqliter.util.maybeFreeze
1920
import platform.posix.usleep
2021
import kotlin.native.concurrent.*
2122
import kotlin.system.getTimeMillis
@@ -77,7 +78,7 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
7778
val workers = Array(10) { Worker.start() }
7879
val futures = mutableListOf<Future<Unit>>()
7980
workers.forEach {
80-
futures.add(it.execute(TransferMode.SAFE, { ManagerOps(manager, biginsert, bigselect).freeze() }) {
81+
futures.add(it.execute(TransferMode.SAFE, { ManagerOps(manager, biginsert, bigselect).maybeFreeze() }) {
8182
val conn = it.manager.surpriseMeConnection()
8283
try {
8384
for (i in 0 until 10) {
@@ -402,7 +403,7 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
402403

403404
val workers = (0 until 20).map { Worker.start(errorReporting = true, name = "Test Worker $it") }
404405
val futures = workers.map { worker ->
405-
worker.execute(TransferMode.SAFE, { config2.freeze() }) {
406+
worker.execute(TransferMode.SAFE, { config2.maybeFreeze() }) {
406407
val managerInner = createDatabaseManager(it)
407408
val conn = managerInner.createMultiThreadedConnection()
408409
conn.close()
@@ -419,7 +420,7 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
419420
private fun threadWait(time: Int, manager: DatabaseManager, block: (DatabaseConnection) -> Unit): Boolean {
420421
return manager.withConnection {
421422
val worker = Worker.start()
422-
val future = worker.execute(TransferMode.SAFE, { Pair(manager, block).freeze() }) {
423+
val future = worker.execute(TransferMode.SAFE, { Pair(manager, block).maybeFreeze() }) {
423424
try {
424425
usleep(500_000u)
425426
it.first.withConnection(it.second)

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/TestSupport.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package co.touchlab.sqliter
1818

19+
import co.touchlab.sqliter.util.maybeFreeze
1920
import kotlin.native.concurrent.Future
2021
import kotlin.native.concurrent.TransferMode
2122
import kotlin.native.concurrent.Worker
22-
import kotlin.native.concurrent.freeze
2323
import kotlin.system.getTimeMillis
2424

2525
class MPWorker(){
2626
val worker = Worker.start()
2727
fun <T> runBackground(backJob: () -> T): MPFuture<T> {
28-
return MPFuture(worker.execute(TransferMode.SAFE, {backJob.freeze()}){
28+
return MPFuture(worker.execute(TransferMode.SAFE, {backJob.maybeFreeze()}){
2929
it()
3030
})
3131
}
@@ -61,7 +61,7 @@ class ThreadOps<C>(val producer:()->C){
6161
tests.shuffle()
6262
}
6363

64-
exes.freeze()
64+
exes.maybeFreeze()
6565

6666
val start = currentTimeMillis()
6767

0 commit comments

Comments
 (0)