From d9474a83195255b8428d16db3f9e3085228e582d Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 1 Feb 2019 09:06:27 +0300 Subject: [PATCH] Move compiler version to 1.3.20, simplify interop runtime. (#2608) --- .../kotlin/native/interop/indexer/Utils.kt | 1 + .../src/main/kotlin/kotlinx/cinterop/Types.kt | 2 +- .../src/main/kotlin/kotlinx/cinterop/Utils.kt | 53 +++++++++---------- .../native/interop/gen/jvm/CommandLine.kt | 2 +- gradle.properties | 4 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt index 64e175dc382..c0a24b7084b 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt @@ -93,6 +93,7 @@ internal fun parseTranslationUnit( compilerArgs: List, options: Int ): CXTranslationUnit { + memScoped { val result = clang_parseTranslationUnit( index, diff --git a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt index f8fc000eb52..f65fea9389f 100644 --- a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt +++ b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt @@ -83,7 +83,7 @@ abstract class CValues : CValuesRef() { /** * Copies the values to [placement] and returns the pointer to the copy. */ - override abstract fun getPointer(scope: AutofreeScope): CPointer + abstract override fun getPointer(scope: AutofreeScope): CPointer // TODO: optimize override fun equals(other: Any?): Boolean { diff --git a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt index 907f8a38129..264638aef3c 100644 --- a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt +++ b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt @@ -66,7 +66,7 @@ open class DeferScope { } abstract class AutofreeScope : DeferScope(), NativePlacement { - override abstract fun alloc(size: Long, align: Int): NativePointed + abstract override fun alloc(size: Long, align: Int): NativePointed } open class ArenaBase(private val parent: NativeFreeablePlacement = nativeHeap) : AutofreeScope() { @@ -359,24 +359,22 @@ fun Array?>.toCValues() = cValuesOf(*this) fun List?>.toCValues() = this.toTypedArray().toCValues() +private class CString(val bytes: ByteArray): CValues() { + override val size get() = bytes.size + 1 + + override fun getPointer(scope: AutofreeScope): CPointer { + val result = scope.allocArray(bytes.size + 1) + nativeMemUtils.putByteArray(bytes, result.pointed, bytes.size) + result[bytes.size] = 0.toByte() + return result + } +} + /** * @return the value of zero-terminated UTF-8-encoded C string constructed from given [kotlin.String]. */ val String.cstr: CValues - get() { - val bytes = encodeToUtf8(this) - - return object : CValues() { - override val size get() = bytes.size + 1 - - override fun getPointer(scope: AutofreeScope): CPointer { - val result = scope.allocArray(bytes.size + 1) - nativeMemUtils.putByteArray(bytes, result.pointed, bytes.size) - result[bytes.size] = 0.toByte() - return result - } - } - } + get() = CString(encodeToUtf8(this)) /** * Convert this list of Kotlin strings to C array of C strings, @@ -392,20 +390,21 @@ fun List.toCStringArray(autofreeScope: AutofreeScope): CPointer.toCStringArray(autofreeScope: AutofreeScope): CPointer> = autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) }) -val String.wcstr: CValues - get() { - val chars = CharArray(this.length, { i -> this.get(i)}) - return object : CValues() { - override val size get() = 2 * (chars.size + 1) - override fun getPointer(scope: AutofreeScope): CPointer { - val result = scope.allocArray(chars.size + 1) - nativeMemUtils.putCharArray(chars, result.pointed, chars.size) - result[chars.size] = 0u - return result - } - } +private class WCString(val chars: CharArray): CValues() { + override val size get() = 2 * (chars.size + 1) + + override fun getPointer(scope: AutofreeScope): CPointer { + val result = scope.allocArray(chars.size + 1) + nativeMemUtils.putCharArray(chars, result.pointed, chars.size) + // TODO: fix, after KT-29627 is fixed. + nativeMemUtils.putShort((result + chars.size)!!.pointed, 0) + return result } +} + +val String.wcstr: CValues + get() = WCString(this.toCharArray()) /** * TODO: should the name of the function reflect the encoding? diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt index d11796bea1a..c8790853235 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt @@ -84,7 +84,7 @@ const val HEADER_FILTER_ADDITIONAL_SEARCH_PREFIX = "-headerFilterAdditionalSearc fun parseCommandLine(args: Array, arguments: T): T { parseCommandLineArguments(args.asList(), arguments) - reportArgumentParseProblems(arguments.errors) + arguments.errors?.let { reportArgumentParseProblems(it) } return arguments } diff --git a/gradle.properties b/gradle.properties index 8bbe14c2e31..4b1ce11a2af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,8 +15,8 @@ # # A version of the Kotlin "toolchain" (compiler, runtime, stdlib etc) used by the build script. -buildKotlinVersion=1.3.0-rc-116 -buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_130_CompilerAllPlugins),number:1.3.0-rc-116,tag:kotlin-native,pinned:true/artifacts/content/maven +buildKotlinVersion=1.3.20 +buildKotlinCompilerRepo=https://cache-redirector.jetbrains.com/maven-central remoteRoot=konan_tests kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_dev_CompilerAllPlugins),number:1.3.30-dev-1296,pinned:true/artifacts/content/maven kotlinVersion=1.3.30-dev-1296