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:
Svyatoslav Scherbina
2022-02-03 14:04:28 +03:00
committed by Space
parent d235fc4dbe
commit 76672a4abf
4 changed files with 28 additions and 2 deletions
@@ -566,11 +566,13 @@ extern "C" id Kotlin_ObjCExport_refToLocalObjC(ObjHeader* 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);
}
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.
RETURN_RESULT_OF(Kotlin_ObjCExport_refFromObjC, obj);
}