Nikos Mavrogiannopoulos nmav at
Tue Jun 22 18:30:38 CEST 2010

 Currently there is a fork of the GMP at libgcrypt (crypto library)[0],
and the main if not only reason is that the API for GMP does not allow
detection of out of memory situations, except for a callback. For
example in libgcrypt if I want to do multiplication I do:

gcry_mpi_t w = gcry_mpi_new(gcry_mpi_get_nbits(a)+gcry_mpi_get_nbits(b));
if (w==NULL) return -ENOMEM;
gcry_mpi_mul (w, a, b); /* always succeeds */

whilst in gmp:

mpz_init (w);
mpz_mul (w, a, b);

In the first case the application can return an error on the
out-of-memory condition whilst in the gmp case, the application cannot
control out of memory errors, except crashing or transfering control to
a callback that is not always useful.

My question is. Do you plan in GMP to support a "safe" API such as
Having something like this will really help applications that are build
on the assumption that recovery from out-of-memory situations is
possible, to benefit from using GMP.


[0]. The API of libgcrypt's gmp are the gcry_mpi_* functions.

More information about the gmp-devel mailing list