From 7bd78e5b4660d3c8c885fe45e484f0aea532381c Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 25 Dec 2017 09:12:40 +0000 Subject: [PATCH] Fix a bug in ObjC++ EH. Throwing an Objective-C exception through a C++ catch block was broken. This was because the C++ code inserts a cleanup handler to make sure that it invokes `__cxa_end_catch`. Unwinding through this catchup transformed the Objective-C exception into a C++ one. This case should have been handled, except for two bugs: 1. A typo (`#ifdef` instead of `#ifndef`) meant that we were not extracting the Objective-C exception from the C++ object. 2. We were skipping everything except catchalls after the search phase, because we lose some information in the transformation. Fixes #49 --- eh_personality.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eh_personality.c b/eh_personality.c index 31aecc16..90afbbb3 100644 --- a/eh_personality.c +++ b/eh_personality.c @@ -330,7 +330,7 @@ static inline _Unwind_Reason_Code internal_objc_personality(int version, // The object to return void *object = NULL; -#ifdef NO_OBJCXX +#ifndef NO_OBJCXX if (exceptionClass == cxx_exception_class) { int objcxx; @@ -421,7 +421,7 @@ static inline _Unwind_Reason_Code internal_objc_personality(int version, // If this is not a cleanup, ignore it and keep unwinding. //if (check_action_record(context, foreignException, &lsda, //action.action_record, thrown_class, &selector) != handler_cleanup) - if (handler != handler_cleanup) + if ((handler != handler_cleanup) && !objcxxException) { DEBUG_LOG("Ignoring handler! %d\n",handler); return continueUnwinding(exceptionObject, context);