
Roberto Bagnara bagnara@cs.unipr.it writes:
Not only I expect all allocations that may fail to be done through the custom allocation functions; I also expect GMP not to leave inconsistent objects around in case of allocation failures. And it would also be very desirable that no memory is leaked in that cases (this is harder to achieve and can be left as a desideratum).
I'm also a little confused. There are at least two ways to do it: Either have the allocation functions return NULL, and then the GMP functions allocating memory must check for that and set gmp_error to GMP_ALLOCATE. But from my reading of the source (e.g. mpz/init.c), there are no such checks. (In fact, it seems gmp_errno is only ever set by the randomness functions. And I wouldn't miss it if it was purged from the code; using global variables for error reporting is ugly).
The other alternative is to expect the allocation function to longjmp out on failure (and C++ exceptions is about the same thing, from GMP:s point of view). Then GMP has to be careful not to leak any memory when such jumps happen.
/Niels