Pull request: Raise SIGFPE instead of abort in __gmp_exception`
yyc1992 at gmail.com
Thu Jan 7 14:01:06 UTC 2016
On Sat, Jan 2, 2016 at 4:57 PM, Yichao Yu <yyc1992 at gmail.com> wrote:
> This implements the `Enhancement` for `__gmp_exception`. I'm not sure
> how to attach additional information on the signal so I leave that
> enhancement there.
> We (julia) catches the SIGFPE generated by GMP and raise our own
> error. Given the comment in this file, I think this is a reasonable
> thing to do.
> I'm pretty sure gmail will destroy the formatting of the patch so I
> attached a link to a gist of the patch too.
> Hopefully this is the right place to suggest patches.
> Happy new year.
Another julia developer Jameson (c.c.'d) pointed out that this may
raise an signal on the process instead of the thread on Mac and the
portable way to do this is `pthread_kill(pthread_self(), SIGFPE)`.
Since this add another (small) link dependency and this shouldn't be a
problem on x86, I'm not sure what's the preferred way to do this.
> Yichao Yu
> # HG changeset patch
> # User Yichao Yu <yyc1992 at gmail.com>
> # Date 1451770649 18000
> # Sat Jan 02 16:37:29 2016 -0500
> # Node ID 73752db1e2f346a6ee321116ebf2dd88361788a6
> # Parent 60c77e71e1d3322567642dbd1919aa8b7531a822
> Raise SIGFPE instead of abort in __gmp_exception on platforms that
> doesn't do that automatically for integer zero division.
> diff -r 60c77e71e1d3 -r 73752db1e2f3 errno.c
> --- a/errno.c Fri Jan 01 21:41:57 2016 +0100
> +++ b/errno.c Sat Jan 02 16:37:29 2016 -0500
> @@ -33,6 +33,7 @@
> see https://www.gnu.org/licenses/. */
> #include <stdlib.h>
> +#include <signal.h>
> #include "gmp.h"
> #include "gmp-impl.h"
> @@ -40,10 +41,9 @@
> /* 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.
> + those where it doesn't, for example power and powerpc, raise SIGFPE 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
> + Enhancement: Perhaps it'd be possible to get the BSD style
> FPE_INTDIV_TRAP parameter in there too. */
> @@ -51,7 +51,7 @@
> gmp_errno |= error_bit;
> __gmp_junk = 10 / __gmp_0;
> - abort ();
> + raise (SIGFPE);
More information about the gmp-devel