[KT-32929] Filter exceptions from objc alloc (#3318)
Issue: SIGSEGV in Throwable.printStackTrace when terminating after ObjC alloc exception Root-cause: Corrupted kotlin.Throwable has been sent as ReportUnhandledException() parameter Fix: Use @FilterException which terminates correctly with objc_terminate
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -3335,6 +3335,13 @@ Task interopTest(String name, Closure<KonanInteropTest> 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
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
Reference in New Issue
Block a user