Skip to content

Commit e95a128

Browse files
authored
Merge pull request #66 from touchlab/kpg/memory_model_changes
Kpg/memory model changes
2 parents 58167e8 + 919e565 commit e95a128

File tree

23 files changed

+145
-90
lines changed

23 files changed

+145
-90
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
build:
1313
strategy:
1414
matrix:
15-
os: [ macOS-latest, windows-latest, ubuntu-18.04 ]
15+
os: [ macOS-latest, ubuntu-18.04 ]
16+
# os: [ macOS-latest, windows-latest, ubuntu-18.04 ]
1617
runs-on: ${{matrix.os}}
1718
steps:
1819
- name: Checkout the repo
@@ -47,5 +48,7 @@ jobs:
4748
- name: Build
4849
run: ./gradlew build --no-daemon --stacktrace
4950

51+
- name: Build New Memory Model
52+
run: ./gradlew build --no-daemon --stacktrace -Pkotlin.native.binary.memoryModel=experimental
5053
env:
5154
GRADLE_OPTS: -Dorg.gradle.configureondemand=true -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m"

gradle.properties

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

33
GROUP=co.touchlab
4-
VERSION_NAME=1.0.10
5-
KOTLIN_VERSION=1.5.30
4+
VERSION_NAME=1.0.11
5+
KOTLIN_VERSION=1.6.20-RC2
66

77
kotlin.native.ignoreDisabledTargets=true
88

sqliter-driver/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ if(!HostManager.hostIsLinux) {
115115
tasks.findByName("publishLinuxX64PublicationToMavenRepository")?.enabled = false
116116
}
117117

118+
if(!HostManager.hostIsMingw) {
119+
tasks.findByName("mingwX64Test")?.enabled = false
120+
tasks.findByName("linkDebugTestMingwX64")?.enabled = false
121+
tasks.findByName("publishMingwX64PublicationToMavenRepository")?.enabled = false
122+
}
123+
118124
apply(from = "../gradle/gradle-mvn-mpp-push.gradle")
119125

120126
tasks.register("publishMac"){

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ actual object DatabaseFileContext{
6363
{
6464
val prefix = file.getName() + "-mj"
6565
val files = dir.listFiles(object: FileFilter {
66-
override fun accept(candidate: File):Boolean {
67-
return candidate.getName().startsWith(prefix)
66+
override fun accept(pathname: File):Boolean {
67+
return pathname.getName().startsWith(prefix)
6868
}
6969
})
7070
if (files != null)

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

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,15 @@ internal actual class File(dirPath:String?=null, name:String){
4444
* This field is initialized from the system property "file.separator".
4545
* Later changes to that property will have no effect on this field or this class.
4646
*/
47-
var separatorChar: Char = '/'
47+
val separatorChar: Char = '/'
4848

4949
/**
5050
* The system-dependent string used to separate components in filenames ('/').
5151
* See [.separatorChar].
5252
*/
53-
var separator: String = "/"
53+
val separator: String = "/"
5454

55-
/**
56-
* The system-dependent character used to separate components in search paths (':').
57-
* This is used to split such things as the PATH environment variable and classpath
58-
* system properties into lists of directories to be searched.
59-
*
60-
*
61-
* This field is initialized from the system property "path.separator".
62-
* Later changes to that property will have no effect on this field or this class.
63-
*/
64-
var pathSeparatorChar: Char = ':'
65-
66-
/**
67-
* The system-dependent string used to separate components in search paths (":").
68-
* See [.pathSeparatorChar].
69-
*/
70-
var pathSeparator: String = ":"
71-
72-
private var caseSensitive: Boolean = true
73-
74-
// separatorChar = System.getProperty("file.separator", "/").charAt(0);
75-
// pathSeparatorChar = System.getProperty("path.separator", ":").charAt(0);
76-
// separator = String.valueOf(separatorChar);
77-
// pathSeparator = String.valueOf(pathSeparatorChar);
78-
// caseSensitive = isCaseSensitiveImpl();
55+
private val caseSensitive: Boolean = true
7956
}
8057

8158
/**
@@ -272,9 +249,7 @@ internal actual class File(dirPath:String?=null, name:String){
272249
* @return the number of bytes in this file.
273250
*/
274251
fun length(): Long{
275-
val attrMap = defaultFileManager().attributesOfItemAtPath(path, null)
276-
if(attrMap == null)
277-
return 0
252+
val attrMap = defaultFileManager().attributesOfItemAtPath(path, null) ?: return 0
278253
return attrMap[NSFileSize] as Long
279254
}
280255

@@ -289,20 +264,13 @@ internal actual class File(dirPath:String?=null, name:String){
289264
*
290265
* @return an array of strings with file names or `null`.
291266
*/
292-
fun list(): Array<String>? {
267+
private fun list(): Array<String> {
293268
return listImpl(path)
294269
}
295270

296-
private fun listImpl(path: String): Array<String>?{
271+
private fun listImpl(path: String): Array<String> {
297272
val pathList = defaultFileManager().contentsOfDirectoryAtPath(path, null) as List<*>
298-
if(pathList == null)
299-
{
300-
return null
301-
}
302-
else {
303-
val pathArray = Array<String>(pathList.size, { i -> pathList[i] as String })
304-
return pathArray
305-
}
273+
return Array(pathList.size) { i -> pathList[i] as String }
306274
}
307275

308276
/**
@@ -322,12 +290,12 @@ internal actual class File(dirPath:String?=null, name:String){
322290
*/
323291
fun list(filter: FilenameFilter?): Array<String>? {
324292
val filenames = list()
325-
if (filter == null || filenames == null) {
293+
if (filter == null) {
326294
return filenames
327295
}
328296
val result = ArrayList<String>(filenames.size)
329297
for (filename in filenames) {
330-
if (filter!!.accept(this, filename)) {
298+
if (filter.accept(this, filename)) {
331299
result.add(filename)
332300
}
333301
}
@@ -386,7 +354,7 @@ internal actual class File(dirPath:String?=null, name:String){
386354
}
387355
val result = ArrayList<File>(files.size)
388356
for (file in files) {
389-
if (filter!!.accept(file)) {
357+
if (filter.accept(file)) {
390358
result.add(file)
391359
}
392360
}
@@ -404,10 +372,8 @@ internal actual class File(dirPath:String?=null, name:String){
404372
return null
405373
}
406374
val count = filenames.size
407-
val result = arrayOfNulls<File>(count)
408375

409-
val files = Array<File>(count, {i -> File(this, filenames[i])})
410-
return files
376+
return Array(count) { i -> File(this, filenames[i]) }
411377
}
412378

413379
/**
@@ -448,10 +414,6 @@ internal actual class File(dirPath:String?=null, name:String){
448414
* `false` on failure or if the directory already existed.
449415
*/
450416
fun mkdirs(): Boolean {
451-
return mkdirs(false)
452-
}
453-
454-
private fun mkdirs(resultIfExists: Boolean): Boolean {
455417
/* If the terminal directory already exists, answer false */
456418
if (exists()) {
457419
return false
@@ -470,11 +432,9 @@ internal actual class File(dirPath:String?=null, name:String){
470432
return defaultFileManager().createFileAtPath(path, null, null)
471433
}
472434

473-
private fun getFileType(path:String):NSFileAttributeType?{
474-
val attrMap = defaultFileManager().attributesOfItemAtPath(path, null)
475-
if(attrMap == null)
476-
return null
477-
return attrMap[NSFileType] as NSFileAttributeType?
435+
private fun getFileType(path:String):NSFileAttributeType{
436+
val attrMap = defaultFileManager().attributesOfItemAtPath(path, null) ?: return null
437+
return attrMap[NSFileType] as NSFileAttributeType
478438
}
479439

480440
fun isDirectory(): Boolean{

sqliter-driver/src/linuxX64Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package co.touchlab.sqliter.concurrency
22

3+
import co.touchlab.sqliter.util.maybeFreeze
34
import kotlinx.cinterop.Arena
45
import kotlinx.cinterop.alloc
56
import kotlinx.cinterop.ptr
67
import platform.posix.*
7-
import kotlin.native.concurrent.freeze
88

99
/**
1010
* A simple lock.
@@ -19,7 +19,7 @@ actual class Lock actual constructor() {
1919
pthread_mutexattr_init(attr.ptr)
2020
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt())
2121
pthread_mutex_init(mutex.ptr, attr.ptr)
22-
freeze()
22+
maybeFreeze()
2323
}
2424

2525
actual fun lock() {

sqliter-driver/src/mingwX64Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package co.touchlab.sqliter.concurrency
22

3+
import co.touchlab.sqliter.util.maybeFreeze
34
import kotlinx.cinterop.Arena
45
import kotlinx.cinterop.alloc
56
import kotlinx.cinterop.ptr
@@ -14,7 +15,6 @@ import platform.posix.pthread_mutexattr_destroy
1415
import platform.posix.pthread_mutexattr_init
1516
import platform.posix.pthread_mutexattr_settype
1617
import platform.posix.pthread_mutexattr_tVar
17-
import kotlin.native.concurrent.freeze
1818

1919
/**
2020
* A simple lock.
@@ -29,7 +29,7 @@ actual class Lock actual constructor() {
2929
pthread_mutexattr_init(attr.ptr)
3030
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt())
3131
pthread_mutex_init(mutex.ptr, attr.ptr)
32-
freeze()
32+
maybeFreeze()
3333
}
3434

3535
actual fun lock() {

sqliter-driver/src/mingwX86Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package co.touchlab.sqliter.concurrency
22

3+
import co.touchlab.sqliter.util.maybeFreeze
34
import kotlinx.cinterop.Arena
45
import kotlinx.cinterop.alloc
56
import kotlinx.cinterop.ptr
@@ -14,7 +15,6 @@ import platform.posix.pthread_mutexattr_destroy
1415
import platform.posix.pthread_mutexattr_init
1516
import platform.posix.pthread_mutexattr_settype
1617
import platform.posix.pthread_mutexattr_tVar
17-
import kotlin.native.concurrent.freeze
1818

1919
/**
2020
* A simple lock.
@@ -29,7 +29,7 @@ actual class Lock actual constructor() {
2929
pthread_mutexattr_init(attr.ptr)
3030
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt())
3131
pthread_mutex_init(mutex.ptr, attr.ptr)
32-
freeze()
32+
maybeFreeze()
3333
}
3434

3535
actual fun lock() {

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/DatabaseConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum class JournalMode {
8989

9090
companion object {
9191
fun forString(s: String) =
92-
if (s.toUpperCase().equals(WAL.name)) {
92+
if (s.uppercase() == WAL.name) {
9393
WAL
9494
} else {
9595
DELETE

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/DatabaseConnection.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package co.touchlab.sqliter
1818

1919
interface DatabaseConnection {
20+
fun rawExecSql(sql: String)
2021
fun createStatement(sql: String): Statement
2122
fun beginTransaction()
2223
fun setTransactionSuccessful()
@@ -98,7 +99,7 @@ val DatabaseConnection.journalMode: JournalMode
9899

99100
fun DatabaseConnection.updateJournalMode(value: JournalMode): JournalMode {
100101
return if (journalMode != value) {
101-
JournalMode.forString(stringForQuery("PRAGMA journal_mode=${value.name}").toUpperCase())
102+
JournalMode.forString(stringForQuery("PRAGMA journal_mode=${value.name}").uppercase())
102103
} else {
103104
value
104105
}

0 commit comments

Comments
 (0)