summaryrefslogtreecommitdiff
path: root/dev-libs/ntl/files/ntl-6.0.0-sage-tools.patch
blob: e79731fc2fce8265b0563db4c9699940b0bd6651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--- src.orig/src/tools.c	2012-08-06 11:54:53.652334400 +0200
+++ src/src/tools.c	2012-08-06 11:59:18.183993600 +0200
@@ -18,8 +18,35 @@
 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 Error(const char *s)
 {
+   if (ErrorCallbackFunction != NULL)
+      ErrorCallbackFunction(s, ErrorCallbackContext);
+
    cerr << s << "\n";
    _ntl_abort();
 }
--- src.orig/include/NTL/tools.h	2012-08-06 11:54:52.830333000 +0200
+++ src/include/NTL/tools.h	2012-08-06 11:59:18.143993600 +0200
@@ -10,6 +10,7 @@
 
 #include <cstdlib>
 #include <cmath>
+#include <cstdio>
 #include <iostream>
 
 #else
@@ -252,6 +253,12 @@
 char IntValToChar(long a);
 
 
+/*
+  This function is not present in vanilla NTL.
+  See tools.c for documentation.
+ */
+void SetErrorCallbackFunction(void (*func)(const char *s, void *context), void *context);
+
 
 void Error(const char *s);