From 3ccb4240ccacb439cec14525f933259fd2564794 Mon Sep 17 00:00:00 2001 From: theraven Date: Sun, 20 Mar 2011 21:20:42 +0000 Subject: [PATCH] Fix getting Objective-C objects out of C++ exceptions. --- eh_personality.c | 7 ++++--- objcxx_eh.cc | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/eh_personality.c b/eh_personality.c index 89b5c68..eb4a5d8 100644 --- a/eh_personality.c +++ b/eh_personality.c @@ -218,7 +218,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version, } struct objc_exception *ex = 0; - //char *cls = (char*)&exceptionClass; + char *cls = (char*)&exceptionClass; fprintf(stderr, "Class: %c%c%c%c%c%c%c%c\n", cls[7], cls[6], cls[5], cls[4], cls[3], cls[2], cls[1], cls[0]); // Check if this is a foreign exception. If it is a C++ exception, then we @@ -236,6 +236,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version, if (obj != (id)-1) { object = obj; + fprintf(stderr, "ObjC++ object exception %p\n", object); objcxxException = YES; // This is a foreign exception, buy for the purposes of exception // matching, we pretend that it isn't. @@ -328,7 +329,6 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version, } else if (foreignException || objcxxException) { - fprintf(stderr, "Doing the foreign exception thing...\n"); struct dwarf_eh_lsda lsda = parse_lsda(context, lsda_addr); action = dwarf_eh_find_callsite(context, &lsda); check_action_record(context, foreignException, &lsda, @@ -337,16 +337,17 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version, // exception, then we need to delete the exception object. if (foreignException) { + fprintf(stderr, "Doing the foreign exception thing...\n"); //[thrown_class exceptionWithForeignException: exceptionObject]; SEL box_sel = sel_registerName("exceptionWithForeignException:"); IMP boxfunction = objc_msg_lookup((id)thrown_class, box_sel); object = boxfunction((id)thrown_class, box_sel, exceptionObject); + fprintf(stderr, "Boxed as %p\n", object); } else // ObjCXX exception { _Unwind_DeleteException(exceptionObject); } - fprintf(stderr, "Boxed as %p\n", object); } else { diff --git a/objcxx_eh.cc b/objcxx_eh.cc index d354f35..4790a02 100644 --- a/objcxx_eh.cc +++ b/objcxx_eh.cc @@ -166,7 +166,7 @@ void* objc_object_for_cxx_exception(void *thrown_exception) { return (id)-1; } - return (id)(ex-1); + return *(id*)(ex+1); } void print_type_info(void *thrown_exception)