From 757c306341bede234f191e0341eaad442ff77e0e Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 27 Mar 2017 20:04:51 +0300 Subject: [PATCH] Support enum arguments and return values in interop variadic functions --- .../Runtime/src/native/kotlin/kotlinx/cinterop/Varargs.kt | 2 ++ .../kotlin/native/interop/gen/jvm/StubGenerator.kt | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/Varargs.kt b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/Varargs.kt index e63c79732bf..002a8b6c1f9 100644 --- a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/Varargs.kt +++ b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/Varargs.kt @@ -64,6 +64,8 @@ private tailrec fun convertArgument( FFI_TYPE_KIND_FLOAT } + is CEnum -> convertArgument(argument.value, isVariadic, location, additionalPlacement) + else -> throw Error("unsupported argument: $argument") } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt index 44e7ab9763e..f37c8e081d8 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt @@ -695,11 +695,8 @@ class StubGenerator( } private fun FunctionDecl.generateAsFfiVarargs(): Boolean = (platform == KotlinPlatform.NATIVE && this.isVararg && - // Neither takes nor returns structs by value or enum-typed values: - (this.parameters.map { it.type } + this.returnType).all { - val type = it.unwrapTypedefs() - type !is RecordType && type !is EnumType - }) + // Neither takes nor returns structs by value: + !this.returnsRecord() && this.parameters.all { it.type.unwrapTypedefs() !is RecordType }) /** * Constructs [InValueBinding] for return value of Kotlin binding for given C function. @@ -873,6 +870,7 @@ class StubGenerator( 8 -> "FFI_TYPE_KIND_DOUBLE" else -> TODO(unwrappedType.toString()) } + is EnumType -> getFfiTypeKind(unwrappedType.def.baseType) else -> TODO(unwrappedType.toString()) } }