Move compiler version to 1.3.20, simplify interop runtime. (#2608)

This commit is contained in:
Nikolay Igotti
2019-02-01 09:06:27 +03:00
committed by GitHub
parent a35a06f9f8
commit d9474a8319
5 changed files with 31 additions and 31 deletions
@@ -93,6 +93,7 @@ internal fun parseTranslationUnit(
compilerArgs: List<String>,
options: Int
): CXTranslationUnit {
memScoped {
val result = clang_parseTranslationUnit(
index,
@@ -83,7 +83,7 @@ abstract class CValues<T : CVariable> : CValuesRef<T>() {
/**
* Copies the values to [placement] and returns the pointer to the copy.
*/
override abstract fun getPointer(scope: AutofreeScope): CPointer<T>
abstract override fun getPointer(scope: AutofreeScope): CPointer<T>
// TODO: optimize
override fun equals(other: Any?): Boolean {
@@ -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 <T : CPointed> Array<CPointer<T>?>.toCValues() = cValuesOf(*this)
fun <T : CPointed> List<CPointer<T>?>.toCValues() = this.toTypedArray().toCValues()
private class CString(val bytes: ByteArray): CValues<ByteVar>() {
override val size get() = bytes.size + 1
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
val result = scope.allocArray<ByteVar>(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<ByteVar>
get() {
val bytes = encodeToUtf8(this)
return object : CValues<ByteVar>() {
override val size get() = bytes.size + 1
override fun getPointer(scope: AutofreeScope): CPointer<ByteVar> {
val result = scope.allocArray<ByteVar>(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<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointer
fun Array<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>> =
autofreeScope.allocArrayOf(this.map { it.cstr.getPointer(autofreeScope) })
val String.wcstr: CValues<UShortVar>
get() {
val chars = CharArray(this.length, { i -> this.get(i)})
return object : CValues<UShortVar>() {
override val size get() = 2 * (chars.size + 1)
override fun getPointer(scope: AutofreeScope): CPointer<UShortVar> {
val result = scope.allocArray<UShortVar>(chars.size + 1)
nativeMemUtils.putCharArray(chars, result.pointed, chars.size)
result[chars.size] = 0u
return result
}
}
private class WCString(val chars: CharArray): CValues<UShortVar>() {
override val size get() = 2 * (chars.size + 1)
override fun getPointer(scope: AutofreeScope): CPointer<UShortVar> {
val result = scope.allocArray<UShortVar>(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<UShortVar>
get() = WCString(this.toCharArray())
/**
* TODO: should the name of the function reflect the encoding?
@@ -84,7 +84,7 @@ const val HEADER_FILTER_ADDITIONAL_SEARCH_PREFIX = "-headerFilterAdditionalSearc
fun <T: CommonToolArguments> parseCommandLine(args: Array<String>, arguments: T): T {
parseCommandLineArguments(args.asList(), arguments)
reportArgumentParseProblems(arguments.errors)
arguments.errors?.let { reportArgumentParseProblems(it) }
return arguments
}
+2 -2
View File
@@ -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