diff --git a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/ObjectiveCImpl.kt b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/ObjectiveCImpl.kt index edc97f629b1..c658e11e084 100644 --- a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/ObjectiveCImpl.kt +++ b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/ObjectiveCImpl.kt @@ -22,6 +22,7 @@ import kotlin.native.internal.ExportTypeInfo import kotlin.native.internal.ExportForCppRuntime import kotlin.native.internal.TypedIntrinsic import kotlin.native.internal.IntrinsicType +import kotlin.native.internal.FilterExceptions interface ObjCObject interface ObjCClass : ObjCObject @@ -207,6 +208,7 @@ external fun objc_autoreleasePoolPush(): NativePtr external fun objc_autoreleasePoolPop(ptr: NativePtr) @SymbolName("Kotlin_objc_allocWithZone") +@FilterExceptions private external fun objc_allocWithZone(clazz: NativePtr): NativePtr @SymbolName("Kotlin_objc_retain") diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 149120e49ba..f7ffc89b543 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -3335,6 +3335,13 @@ Task interopTest(String name, Closure configureClosure) { } } + +standaloneTest("interop_objc_allocException") { + disabled = !isAppleTarget(project) + expectedExitStatus = 0 + source = "interop/objc/allocException.kt" +} + interopTest("interop0") { disabled = (project.testTarget == 'wasm32') || // No interop for wasm yet. (project.testTarget == 'linux_mips32') || // st_uid of '/' is not equal to 0 when using qemu diff --git a/backend.native/tests/interop/objc/allocException.kt b/backend.native/tests/interop/objc/allocException.kt new file mode 100644 index 00000000000..eedb5c9d0f5 --- /dev/null +++ b/backend.native/tests/interop/objc/allocException.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +import platform.Foundation.* +import platform.objc.* +import kotlin.test.* + +import kotlinx.cinterop.* +import platform.posix.* +import kotlin.system.exitProcess + +fun exc_handler(x: Any?) : Unit { + println("Uncaught exception handler") + println(x.toString()) + exitProcess(0) +} + +fun main() { + objc_setUncaughtExceptionHandler(staticCFunction(::exc_handler)) + + println(NSJSONSerialization()) +}