From 6b042a5510d6e635b0556545763c5a08b485d1a5 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 30 Aug 2017 12:19:13 +0300 Subject: [PATCH] Disable passing exceptions from Objective-C to Kotlin since they can't be correctly handled yet. --- .../native/interop/gen/SimpleBridgeGeneratorImpl.kt | 9 +++++++++ .../kotlin/native/interop/gen/jvm/StubGenerator.kt | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt index 06164e6658d..41c4cf0da0a 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.native.interop.gen import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform +import org.jetbrains.kotlin.native.interop.indexer.Language import org.jetbrains.kotlin.native.interop.indexer.NativeLibrary import org.jetbrains.kotlin.native.interop.indexer.mapFragmentIsCompilable @@ -120,6 +121,14 @@ class SimpleBridgeGeneratorImpl( nativeLines.add(" $it") } + if (libraryForCStubs.language == Language.OBJECTIVE_C) { + // Prevent Objective-C exceptions from passing to Kotlin: + nativeLines.add(1, "@try {") + nativeLines.add("} @catch (id e) { objc_terminate(); }") + // 'objc_terminate' will report the exception. + // TODO: consider implementing this in bitcode generator. + } + nativeLines.add("}") kotlinLines.add("private external fun $kotlinFunctionName($kotlinParameters): ${returnType.kotlinType}") 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 3a5a30af9b1..9a2011d39fc 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 @@ -801,7 +801,13 @@ class StubGenerator( "-I$javaHome/../include/$it" } KotlinPlatform.NATIVE -> emptyList() - } + }, + + additionalPreambleLines = configuration.library.additionalPreambleLines + + when (configuration.library.language) { + Language.C -> emptyList() + Language.OBJECTIVE_C -> listOf("void objc_terminate();") + } ) /**