diff options
author | Filip Pizlo <fpizlo@apple.com> | 2013-10-17 01:38:28 +0000 |
---|---|---|
committer | Filip Pizlo <fpizlo@apple.com> | 2013-10-17 01:38:28 +0000 |
commit | 0739140b05337d97c22fd17c97ac71ab5a34f5d9 (patch) | |
tree | 0ad64589658b32a17224a2cc3c04408680d4d162 /lib | |
parent | adbd3ae1dfa7530d23653b6fd910d28de8217fbd (diff) | |
download | external_llvm-0739140b05337d97c22fd17c97ac71ab5a34f5d9.zip external_llvm-0739140b05337d97c22fd17c97ac71ab5a34f5d9.tar.gz external_llvm-0739140b05337d97c22fd17c97ac71ab5a34f5d9.tar.bz2 |
Expose install_fatal_error_handler() through the C API.
I expose the API with some caveats:
- The C++ API involves a traditional void* opaque pointer for the fatal
error callback. The C API doesn’t do this. I don’t think that the void*
opaque pointer makes any sense since this is a global callback - there will
only be one of them. So if you need to pass some data to your callback,
just put it in a global variable.
- The bindings will ignore the gen_crash_diag boolean. I ignore it because
(1) I don’t know what it does, (2) it’s not documented AFAIK, and (3) I
couldn’t imagine any use for it. I made the gut call that it probably
wasn’t important enough to expose through the C API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/ErrorHandling.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp index 9425445..a0b7619 100644 --- a/lib/Support/ErrorHandling.cpp +++ b/lib/Support/ErrorHandling.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/Signals.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" +#include "llvm-c/Core.h" #include <cassert> #include <cstdlib> @@ -102,3 +103,19 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, LLVM_BUILTIN_UNREACHABLE; #endif } + +static void bindingsErrorHandler(void *user_data, const std::string& reason, + bool gen_crash_diag) { + LLVMFatalErrorHandler handler = + reinterpret_cast<LLVMFatalErrorHandler>(user_data); + handler(reason.c_str()); +} + +void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) { + install_fatal_error_handler( + bindingsErrorHandler, reinterpret_cast<void*>(Handler)); +} + +void LLVMResetFatalErrorHandler() { + remove_fatal_error_handler(); +} |