Skip to content

Commit 922c89e

Browse files
committed
Support libc++
1 parent b1296f9 commit 922c89e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

objcxx_eh.cc

+23-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ typedef struct objc_object* id;
88
#include "objc/runtime.h"
99
#include "objc/objc-arc.h"
1010

11+
#define DEBUG_EXCEPTIONS
12+
13+
#ifndef DEBUG_EXCEPTIONS
14+
#define DEBUG_LOG(...)
15+
#else
16+
#define DEBUG_LOG(str, ...) fprintf(stderr, str, ## __VA_ARGS__)
17+
#endif
18+
1119
/**
1220
* Helper function that has a custom personality function.
1321
* This calls `cxx_throw` and has a destructor that must be run. We intercept
@@ -295,10 +303,18 @@ namespace gnustep
295303
/* libc++-abi does not have __is_pointer_p and won't do the double dereference
296304
* required to get the object pointer. We need to do it ourselves if we have
297305
* caught an exception with libc++'s exception class. */
306+
#ifndef __MINGW32__
298307
if (cxx_exception_class == llvm_cxx_exception_class) {
299308
return **(id**)obj;
300309
}
301310
return *(id*)obj;
311+
#else
312+
#ifdef _LIBCPP_VERSION
313+
return **(id**)obj;
314+
#else
315+
return *(id*)obj;
316+
#endif // _LIBCPP_VERSION
317+
#endif // __MINGW32__
302318
}
303319
};
304320

@@ -355,14 +371,17 @@ bool gnustep::libobjc::__objc_id_type_info::__do_catch(const type_info *thrownTy
355371
// Id catch matches any ObjC throw
356372
if (dynamic_cast<const __objc_class_type_info*>(thrownType))
357373
{
358-
*obj = *(id*)obj;
374+
*obj = dereference_thrown_object_pointer(obj);
375+
DEBUG_LOG("gnustep::libobjc::__objc_id_type_info::__do_catch caught 0x%x\n", *obj);
359376
return true;
360377
}
361378
if (dynamic_cast<const __objc_id_type_info*>(thrownType))
362379
{
363-
*obj = *(id*)obj;
380+
*obj = dereference_thrown_object_pointer(obj);
381+
DEBUG_LOG("gnustep::libobjc::__objc_id_type_info::__do_catch caught 0x%x\n", *obj);
364382
return true;
365383
}
384+
DEBUG_LOG("gnustep::libobjc::__objc_id_type_info::__do_catch returning false\n");
366385
return false;
367386
};
368387

@@ -494,6 +513,7 @@ extern "C" void test_cxx_eh_implementation()
494513
#else
495514
static void eh_cleanup(void *exception)
496515
{
516+
DEBUG_LOG("eh_cleanup: Releasing 0x%x\n", *(id*)exception);
497517
objc_release(*(id*)exception);
498518
}
499519

@@ -504,6 +524,7 @@ void objc_exception_throw(id object)
504524
id *exc = (id *)__cxa_allocate_exception(sizeof(id));
505525
*exc = object;
506526
objc_retain(object);
527+
DEBUG_LOG("objc_exception_throw: Throwing 0x%x\n", *exc);
507528
__cxa_throw(exc, & __objc_id_type_info, eh_cleanup);
508529
}
509530
#endif

0 commit comments

Comments
 (0)