Patch to allow more granular aborting.

Theo Schlossnagle jesus at
Mon Mar 14 15:38:34 CET 2011

On Mon, Mar 14, 2011 at 10:31 AM, Niels Möller <nisse at> wrote:
> Theo Schlossnagle <jesus at> writes:
>> If you know, for a fact, that all failed allocations are termination
>> worthy -- I could do this instead.
> After a look in the documentation, I see that the allocation functions
> are expected to never return NULL. That's why the default functions
> (which you patched) call abort on failure, rather than returning NULL.

So, it might be possible to accomplish my goals by replacing the
allocators.  This still leaves the FPE issue.

>> I can't do what I want from a signal handler, it isn't safe to throw
>> an exception there as we'd be in an alternate stack (most likely).
> There are things like sigsetjmp, but I'm not sure how safe that is or
> how it reallly works.
> I agree that providing using a callback function seems more robust than
> catching the signal. But then, I think it would make sense to invoke
> that callback instead of (or at least before) raising SIGFPE signal.

sigsetjmp sill not work in most situations. It _might_ be safe in the
specific case of an FPE. I agree with you that raising the signal
should be avoided and a callback provided (as the user can raise a
signal from there if they desire).

>>> 3. The final (I think) case is the mpz_t overflow conditions. Not sure
>>> how to get there without first running out of memory, though.
>> This is the case I was hitting. It was an overflow condition that
>> manifested as an OOM.
> I'm not following you here. If you run out of memory first, the overflow
> conditions (in mpz/realloc.c) will never happen. They could happen,
> e.g., if you have two operands of size close to the limit which do fit
> in memory, and try to compute their product, of a size which exceeds the
> limit.

It was aborting in realloc.

gmp version: 5.0.90
gmp: overflow in mpz type

Program received signal SIGABRT, Aborted.
0x00007fff80a40616 in __kill ()
(gdb) where
#0  0x00007fff80a40616 in __kill ()
#1  0x00007fff80ae0cca in abort ()
#2  0x0000000100f9a190 in __gmpz_realloc ()
#3  0x0000000100f97c78 in __gmpz_n_pow_ui ()

Theo Schlossnagle

More information about the gmp-devel mailing list