[llvm-commits] [llvm] r78553 - in /llvm/trunk: include/llvm/Support/ErrorHandling.h lib/Support/ErrorHandling.cpp

Daniel Dunbar daniel at zuster.org
Sun Aug 9 20:36:26 PDT 2009


Author: ddunbar
Date: Sun Aug  9 22:36:26 2009
New Revision: 78553

URL: http://llvm.org/viewvc/llvm-project?rev=78553&view=rev
Log:
Add support for a user supplied pointer argument to llvm_install_error_handler.

Modified:
    llvm/trunk/include/llvm/Support/ErrorHandling.h
    llvm/trunk/lib/Support/ErrorHandling.cpp

Modified: llvm/trunk/include/llvm/Support/ErrorHandling.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorHandling.h?rev=78553&r1=78552&r2=78553&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/ErrorHandling.h (original)
+++ llvm/trunk/include/llvm/Support/ErrorHandling.h Sun Aug  9 22:36:26 2009
@@ -22,19 +22,25 @@
   class Twine;
 
   /// 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
-  /// serious error is encountered by LLVM.
+  /// llvm_instal_error_handler - Installs a new error handler to be used
+  /// whenever a serious (non-recoverable) error is encountered by LLVM.
+  ///
   /// If you are using llvm_start_multithreaded, you should register the handler
   /// before doing that.
   ///
   /// If no error handler is installed the default is to print the error message
-  /// to stderr, and call exit(1).
-  /// If an error handler is installed then it is the handler's responsibility
-  /// to log the message, it will no longer be printed to stderr.
-  /// If the error handler returns, then exit(1) will be called.
-  void llvm_install_error_handler(llvm_error_handler_t handler);
+  /// to stderr, and call exit(1).  If an error handler is installed then it is
+  /// the handler's responsibility to log the message, it will no longer be
+  /// printed to stderr.  If the error handler returns, then exit(1) will be
+  /// called.
+  ///
+  /// \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.
   /// This must not be called between llvm_start_multithreaded() and

Modified: llvm/trunk/lib/Support/ErrorHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=78553&r1=78552&r2=78553&view=diff

==============================================================================
--- llvm/trunk/lib/Support/ErrorHandling.cpp (original)
+++ llvm/trunk/lib/Support/ErrorHandling.cpp Sun Aug  9 22:36:26 2009
@@ -23,12 +23,16 @@
 using namespace std;
 
 static llvm_error_handler_t ErrorHandler = 0;
+static void *ErrorHandlerUserData = 0;
+
 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() &&
          "Cannot register error handlers after starting multithreaded mode!\n");
   assert(!ErrorHandler && "Error handler already registered!\n");
   ErrorHandler = handler;
+  ErrorHandlerUserData = user_data;
 }
 
 void llvm_remove_error_handler(void) {
@@ -47,7 +51,7 @@
   if (!ErrorHandler) {
     errs() << "LLVM ERROR: " << reason << "\n";
   } else {
-    ErrorHandler(reason.str());
+    ErrorHandler(ErrorHandlerUserData, reason.str());
   }
   exit(1);
 }





More information about the llvm-commits mailing list