Native: terminate if cinterop ObjC reference conversion throws exception
To avoid forwarding Obj-C exceptions to Kotlin or vice versa. Otherwise this might lead to a crash or other undesirable behaviour. ^KT-50648 Fixed
This commit is contained in:
committed by
Space
parent
d235fc4dbe
commit
76672a4abf
@@ -4387,6 +4387,9 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
it.defFile 'interop/objc/kt48816/objclib.def'
|
it.defFile 'interop/objc/kt48816/objclib.def'
|
||||||
it.headers "$projectDir/interop/objc/kt48816/objclib.h"
|
it.headers "$projectDir/interop/objc/kt48816/objclib.h"
|
||||||
}
|
}
|
||||||
|
createInterop("objc_kt50648") {
|
||||||
|
it.defFile 'interop/objc/kt50648/objclib.def'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createInterop("withSpaces") {
|
createInterop("withSpaces") {
|
||||||
@@ -5033,6 +5036,16 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
flags = ["-Xlazy-ir-for-caches=enable"]
|
flags = ["-Xlazy-ir-for-caches=enable"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interopTest("interop_objc_kt50648") {
|
||||||
|
source = 'interop/objc/kt50648/main.kt'
|
||||||
|
interop = "objc_kt50648"
|
||||||
|
expectedExitStatusChecker = { it != 0 }
|
||||||
|
outputChecker = {
|
||||||
|
it.contains("Converting Obj-C blocks with non-reference-typed return value to kotlin.Any is not supported (v)") &&
|
||||||
|
(it.contains("kfun:#main(){}") || project.globalTestArgs.contains('-opt')) // Stacktrace.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
standaloneTest("objc_arc_contract") {
|
standaloneTest("objc_arc_contract") {
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import objclib.*
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
getVoidBlockAsId()
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
language = Objective-C
|
||||||
|
---
|
||||||
|
id getVoidBlockAsId() {
|
||||||
|
void (^result)(void) = ^{};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -566,11 +566,13 @@ extern "C" id Kotlin_ObjCExport_refToLocalObjC(ObjHeader* obj) {
|
|||||||
return Kotlin_ObjCExport_refToObjCImpl<false>(obj);
|
return Kotlin_ObjCExport_refToObjCImpl<false>(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" ALWAYS_INLINE id Kotlin_Interop_refToObjC(ObjHeader* obj) {
|
// The function is marked with noexcept, so any exception reaching it will cause std::terminate.
|
||||||
|
extern "C" ALWAYS_INLINE id Kotlin_Interop_refToObjC(ObjHeader* obj) noexcept {
|
||||||
return Kotlin_ObjCExport_refToObjCImpl<false>(obj);
|
return Kotlin_ObjCExport_refToObjCImpl<false>(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" ALWAYS_INLINE OBJ_GETTER(Kotlin_Interop_refFromObjC, id obj) {
|
// The function is marked with noexcept, so any exception reaching it will cause std::terminate.
|
||||||
|
extern "C" ALWAYS_INLINE OBJ_GETTER(Kotlin_Interop_refFromObjC, id obj) noexcept {
|
||||||
// TODO: consider removing this function.
|
// TODO: consider removing this function.
|
||||||
RETURN_RESULT_OF(Kotlin_ObjCExport_refFromObjC, obj);
|
RETURN_RESULT_OF(Kotlin_ObjCExport_refFromObjC, obj);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user