Niels Möller nisse at lysator.liu.se
Sat Mar 8 08:57:19 UTC 2014

"David M. Warme" <David at Warme.net> writes:

> Your example safe_mpz_mul() is definitely NOT what I want to do:

The example was intended to illustrate the needed steps. You can wrap
something a lot more complicated than a single mpz_mul in the same way.

> The problem is that GMP does not presently seem able to divulge to my
> application all of its pending TMP_DECL, TMP_MARK, and TMP_FREE
> context blocks.

If you follow the organization I laid out, with the code block
"protected" by the setjmp modifying only variables allocated within
that block, then the cleanup code can consider *all* allocations after
the setjmp as temporaries that should be deallocated. (Some blocks
may have been explicitly deallocated prior to the failure, those most
not be deallocated again, of course).

In effect, you switch to a completely new allocation arena on setjmp;
any dealloc or realloc on blocks belonging to the previous arena are an

I haven't thought about the other gc issues you describe, but as far as I
understand, the above should be reasonably straightforward, solve the
main problem you describe, and not require any changes to gmp.


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list