Custom error handling function
jdemeyer at cage.ugent.be
Tue Sep 19 12:21:19 UTC 2017
there are a few places in GMP where it catches some invalid operation
and it calls abort() or __gmp_invalid_operation(), which in turn raises
For interactive programs using GMP, it would be useful to have a custom
error handler instead. So, analogous to mp_set_memory_functions(), one
could have mp_set_error_functions().
My more concrete proposal would be to have 2 error functions, one to
replace abort() and one to replace __gmp_invalid_operation(), each with
a "const char* msg" argument containing an error message.
In mpz/init2.c for example, the lines
fprintf (stderr, "gmp: overflow in mpz type\n");
would be replaced by something like
GMP_ERROR("gmp: overflow in mpz type")
This should be easy to implement and it can be totally backwards
compatible. Several other math libraries like PARI/GP, NTL and GLPK
allow an analogous error handler. What do you think?
More information about the gmp-discuss