Patch to allow more granular aborting.

Theo Schlossnagle jesus at
Tue Mar 15 12:31:49 CET 2011

On Tuesday, March 15, 2011, Torbjorn Granlund <tg at> wrote:
> Theo Schlossnagle <jesus at> writes:
>   I'm confused now.  In a previous mail, you suggested I use the builtin
>   libgmp mechanism to replace the allocators.  It appears libgmp indeed
>   has replaceable allocators, but then when it goes to allocate they are
>   not used. I results in I me being unable to wrap realloc and throw and
>   exception on NULL return.
> GMP only allocates (reallocates) things when memory (more memory) is
> needed, as Niels pointed out.
> If you want allocation (reallocation) using the replaceable allocators
> to take place also when memory is not needed, then you probably need to
> maintain your custom GMP version.
> Your statement that "when [GMP] goes to allocate [the custom allocators]
> are not used" is simply a misunderstanding of GMP source code.

I call mpz_n_pow_ui. Libgmp performs an allocation directly using
mpz_realloc instead of the reallocation function I set. Therefore I
cannot change the way in which libgmp handles OOM. This is my problem.
It appears that the mpz_n_pow_ui is not the only function that behaves
this way. There is a problem.

Handling these conditions from a signal handler is not portably safe.
I proposed a solution to the problem. An explanation that I simply
don't understand the source code is not helpful. Please instead
propose a solution that allows me to use the stock version of libgmp.
This problem is not unique to me. It is a problem for anyone
attempting to use libgmp in a long running process that takes user
input. (lua embed, for example)



Theo Schlossnagle

More information about the gmp-devel mailing list