Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGW: Add exception-handling façades to libobjc2 #280

Merged
merged 3 commits into from Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions fast_paths.m
Expand Up @@ -12,6 +12,7 @@ - (id)init;
/**
* Equivalent to [cls alloc]. If there's a fast path opt-in, then this skips the message send.
*/
OBJC_PUBLIC
id
objc_alloc(Class cls)
{
Expand All @@ -29,6 +30,7 @@ - (id)init;
/**
* Equivalent to [cls allocWithZone: null]. If there's a fast path opt-in, then this skips the message send.
*/
OBJC_PUBLIC
id
objc_allocWithZone(Class cls)
{
Expand All @@ -47,6 +49,7 @@ - (id)init;
* Equivalent to [[cls alloc] init]. If there's a fast path opt-in, then this
* skips the message send.
*/
OBJC_PUBLIC
id
objc_alloc_init(Class cls)
{
Expand Down
5 changes: 0 additions & 5 deletions objcxx_eh.h
Expand Up @@ -14,7 +14,6 @@ extern "C" {
#undef CXA_ALLOCATE_EXCEPTION_SPECIFIER
#define CXA_ALLOCATE_EXCEPTION_SPECIFIER
#endif
__attribute__((weak))
void *__cxa_allocate_exception(size_t thrown_size) CXA_ALLOCATE_EXCEPTION_SPECIFIER;

/**
Expand All @@ -23,7 +22,6 @@ void *__cxa_allocate_exception(size_t thrown_size) CXA_ALLOCATE_EXCEPTION_SPECIF
* _Unwind_Exception structure within this structure, and should be passed to
* the C++ personality function.
*/
__attribute__((weak))
struct _Unwind_Exception *objc_init_cxx_exception(id thrown_exception);
/**
* The GNU C++ exception personality function, provided by libsupc++ (GNU) or
Expand All @@ -34,21 +32,18 @@ __attribute__((weak)) DECLARE_PERSONALITY_FUNCTION(__gxx_personality_v0);
* Frees an exception object allocated by __cxa_allocate_exception(). Part of
* the Itanium C++ ABI.
*/
__attribute__((weak))
void __cxa_free_exception(void *thrown_exception);
/**
* Tests whether a C++ exception contains an Objective-C object, and returns if
* if it does. The second argument is a pointer to a boolean value indicating
* whether this is a valid object.
*/
__attribute__((weak))
void *objc_object_for_cxx_exception(void *thrown_exception, int *isValid);

/**
* Prints the type info associated with an exception. Used only when
* debugging, not compiled in the normal build.
*/
__attribute__((weak))
void print_type_info(void *thrown_exception);

/**
Expand Down
43 changes: 43 additions & 0 deletions objcxx_eh_mingw.cc
@@ -1,6 +1,7 @@
#include <atomic>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "dwarf_eh.h"
#include "objcxx_eh_private.h"
#include "objcxx_eh.h"
Expand Down Expand Up @@ -96,3 +97,45 @@ OBJC_PUBLIC extern objc_uncaught_exception_handler objc_setUncaughtExceptionHand
{
return __atomic_exchange_n(&_objc_unexpected_exception, handler, __ATOMIC_SEQ_CST);
}

extern "C" void* __cxa_begin_catch(void *object);

extern "C"
OBJC_PUBLIC
void* objc_begin_catch(void* object)
{
return __cxa_begin_catch(object);
}

extern "C" void __cxa_end_catch();

extern "C"
OBJC_PUBLIC
void objc_end_catch()
{
__cxa_end_catch();
}

extern "C" void __cxa_rethrow();

extern "C"
OBJC_PUBLIC
void objc_exception_rethrow()
{
__cxa_rethrow();
}

extern "C" EXCEPTION_DISPOSITION __gxx_personality_seh0(PEXCEPTION_RECORD ms_exc,
void *this_frame,
PCONTEXT ms_orig_context,
PDISPATCHER_CONTEXT ms_disp);

extern "C"
OBJC_PUBLIC
EXCEPTION_DISPOSITION __gnu_objc_personality_seh0(PEXCEPTION_RECORD ms_exc,
void *this_frame,
PCONTEXT ms_orig_context,
PDISPATCHER_CONTEXT ms_disp)
{
return __gxx_personality_seh0(ms_exc, this_frame, ms_orig_context, ms_disp);
}