abort on error - is this being addressed?

Torbjorn Granlund tg at gmplib.org
Thu Aug 26 16:15:13 CEST 2010

The allocation functions can be customised, see the GMP manual.  Any
fancy behaviour can be impelemeted by the user, including ordering more
swap disks, reclaming memory by GC or compaction, or killing of other

Running out of memory is a condition which is difficult to handle.
Assume we have this sequence of GMP calls,

  mpz_add (...)
  mpz_mul (...)
  mpz_add (...)

and the mpz_mul cannot store its result due to memory shortage.  What
should GMP do?  Store it anyway...?  Store some other value that fits in

GMP calls abort which on Unix systems means a SIGABRT is sent to the
process.  This can be caught using the standard POSIX signal mechanism.
If we had designed GMP to use return codes, we could have used that,
resulting in ugly user programs:

  if (mpz_add (...) == ERROR)
  if (mpz_mul (...) == ERROR)
  if (mpz_add (...) == ERROR)

I think this would be much worse than using signals.


More information about the gmp-discuss mailing list