diff -p -up ntl-5.5.2/include/NTL/tools.h.orig ntl-5.5.2/include/NTL/tools.h --- ntl-5.5.2/include/NTL/tools.h.orig 2009-09-01 16:20:02.000000000 -0300 +++ ntl-5.5.2/include/NTL/tools.h 2009-09-01 16:21:14.000000000 -0300 @@ -10,6 +10,7 @@ #include <cstdlib> #include <cmath> +#include <cstdio> #include <iostream> #else @@ -251,6 +252,11 @@ long IsEOFChar(long c); long CharToIntVal(long c); char IntValToChar(long a); +/* + This function is not present in vanilla NTL 5.5.2. + See tools.c for documentation. + */ +void SetErrorCallbackFunction(void (*func)(const char *s, void *context), void *context); void Error(const char *s); diff -p -up ntl-5.5.2/src/tools.c.orig ntl-5.5.2/src/tools.c --- ntl-5.5.2/src/tools.c.orig 2009-09-01 16:19:48.000000000 -0300 +++ ntl-5.5.2/src/tools.c 2009-09-01 16:27:23.000000000 -0300 @@ -17,9 +17,37 @@ NTL_START_IMPL void (*ErrorCallback)() = 0; +/*************** start of sagemath alternate error handling ***************/ +/* + The following code differs from vanilla NTL 5.5.2. + + 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; +} +/**************** end of sagemath alternate error handling ****************/ void Error(const char *s) { +/*************** start of sagemath alternate error handling ***************/ + if (ErrorCallbackFunction != NULL) + ErrorCallbackFunction(s, ErrorCallbackContext); +/**************** end of sagemath alternate error handling ****************/ + cerr << s << "\n"; _ntl_abort(); }