Add support for a user supplied pointer argument to llvm_install_error_handler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78553 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-08-10 03:36:26 +00:00
parent 64a6b39417
commit ca15f3d6d6
2 changed files with 20 additions and 10 deletions

View File

@ -22,19 +22,25 @@ namespace llvm {
class Twine; class Twine;
/// An error handler callback. /// An error handler callback.
typedef void (*llvm_error_handler_t)(const std::string& reason); typedef void (*llvm_error_handler_t)(void *user_data,
const std::string& reason);
/// Installs a new error handler: this function will be called whenever a /// llvm_instal_error_handler - Installs a new error handler to be used
/// serious error is encountered by LLVM. /// whenever a serious (non-recoverable) error is encountered by LLVM.
///
/// If you are using llvm_start_multithreaded, you should register the handler /// If you are using llvm_start_multithreaded, you should register the handler
/// before doing that. /// before doing that.
/// ///
/// If no error handler is installed the default is to print the error message /// If no error handler is installed the default is to print the error message
/// to stderr, and call exit(1). /// to stderr, and call exit(1). If an error handler is installed then it is
/// If an error handler is installed then it is the handler's responsibility /// the handler's responsibility to log the message, it will no longer be
/// to log the message, it will no longer be printed to stderr. /// printed to stderr. If the error handler returns, then exit(1) will be
/// If the error handler returns, then exit(1) will be called. /// called.
void llvm_install_error_handler(llvm_error_handler_t handler); ///
/// \param user_data - An argument which will be passed to the install error
/// handler.
void llvm_install_error_handler(llvm_error_handler_t handler,
void *user_data = 0);
/// Restores default error handling behaviour. /// Restores default error handling behaviour.
/// This must not be called between llvm_start_multithreaded() and /// This must not be called between llvm_start_multithreaded() and

View File

@ -23,12 +23,16 @@ using namespace llvm;
using namespace std; using namespace std;
static llvm_error_handler_t ErrorHandler = 0; static llvm_error_handler_t ErrorHandler = 0;
static void *ErrorHandlerUserData = 0;
namespace llvm { namespace llvm {
void llvm_install_error_handler(llvm_error_handler_t handler) { void llvm_install_error_handler(llvm_error_handler_t handler,
void *user_data) {
assert(!llvm_is_multithreaded() && assert(!llvm_is_multithreaded() &&
"Cannot register error handlers after starting multithreaded mode!\n"); "Cannot register error handlers after starting multithreaded mode!\n");
assert(!ErrorHandler && "Error handler already registered!\n"); assert(!ErrorHandler && "Error handler already registered!\n");
ErrorHandler = handler; ErrorHandler = handler;
ErrorHandlerUserData = user_data;
} }
void llvm_remove_error_handler(void) { void llvm_remove_error_handler(void) {
@ -47,7 +51,7 @@ void llvm_report_error(const Twine &reason) {
if (!ErrorHandler) { if (!ErrorHandler) {
errs() << "LLVM ERROR: " << reason << "\n"; errs() << "LLVM ERROR: " << reason << "\n";
} else { } else {
ErrorHandler(reason.str()); ErrorHandler(ErrorHandlerUserData, reason.str());
} }
exit(1); exit(1);
} }