summaryrefslogtreecommitdiff
path: root/errno.c
diff options
context:
space:
mode:
authorNiels M?ller <nisse@lysator.liu.se>2016-01-27 20:57:29 +0100
committerNiels M?ller <nisse@lysator.liu.se>2016-01-27 20:57:29 +0100
commit6cb528f425b8605f129717cf527b3bdcdd1733ad (patch)
tree36c3fb72a3c8622ace065cf72d456b6233ff2853 /errno.c
parent7f7ac50b91edb114efae90c02c2d767d0174c44a (diff)
downloadgmp-6cb528f425b8605f129717cf527b3bdcdd1733ad.tar.gz
When available, use SIGFPE rather than abort for gmp exceptions.
Diffstat (limited to 'errno.c')
-rw-r--r--errno.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/errno.c b/errno.c
index d3c02ef4b..c82e8277b 100644
--- a/errno.c
+++ b/errno.c
@@ -33,24 +33,27 @@ GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
#include <stdlib.h>
+
+#include <signal.h>
+
#include "gmp.h"
#include "gmp-impl.h"
int gmp_errno = 0;
-/* The deliberate divide by zero triggers an exception on most systems. On
- those where it doesn't, for example power and powerpc, use abort instead.
-
- Enhancement: Perhaps raise(SIGFPE) (or the same with kill()) would be
- better than abort. Perhaps it'd be possible to get the BSD style
- FPE_INTDIV_TRAP parameter in there too. */
-
+/* Use SIGFPE on systems which have it. Otherwise, deliberate divide
+ by zero, which triggers an exception on most systems. On those
+ where it doesn't, for example power and powerpc, use abort instead. */
void
__gmp_exception (int error_bit)
{
gmp_errno |= error_bit;
+#ifdef SIGFPE
+ raise (SIGFPE);
+#else
__gmp_junk = 10 / __gmp_0;
+#endif
abort ();
}