Blob Blame History Raw
--- ./include/NTL/tools.h.orig	2015-01-09 06:58:19.000000000 -0700
+++ ./include/NTL/tools.h	2015-01-12 20:00:00.000000000 -0700
@@ -406,7 +406,12 @@ void swap(WrappedPtr<T,Deleter>& x, Wrap
 
 // Error Handling
 
-
+/*
+  This function is not present in vanilla NTL.
+  See tools.c for documentation.
+ */
+void SetErrorCallbackFunction(void (*func)(const char *s, void *context),
+			      void *context);
 
 class ErrorObject : public NTL_SNS runtime_error {
 public:
--- ./src/tools.c.orig	2015-01-09 06:58:19.000000000 -0700
+++ ./src/tools.c	2015-01-12 20:00:00.000000000 -0700
@@ -17,9 +17,33 @@ NTL_START_IMPL
 
 NTL_THREAD_LOCAL void (*ErrorCallback)() = 0;
 
+/*
+   The following code differs from vanilla NTL.
+
+   We add a SetErrorCallbackFunction(). This sets a global callback function
+    _function_,  which gets called with parameter _context_ and an error
+    message string whenever Error() gets called.
+
+   Note that if the custom error handler *returns*, then NTL will dump the
+   error message back to stderr and abort() as it habitually does.
+
+   -- David Harvey (2008-04-12)
+*/
+
+void (*ErrorCallbackFunction)(const char*, void*) = NULL;
+void *ErrorCallbackContext = NULL;
+
+void SetErrorCallbackFunction(void (*function)(const char*, void*), void *context)
+{
+   ErrorCallbackFunction = function;
+   ErrorCallbackContext = context;
+}
 
 void TerminalError(const char *s)
 {
+   if (ErrorCallbackFunction != NULL)
+      ErrorCallbackFunction(s, ErrorCallbackContext);
+
    cerr << s << "\n";
    _ntl_abort();
 }