unavoidable abort in mpz/realloc.c

Marc Glisse marc.glisse at inria.fr
Wed Mar 16 16:00:15 CET 2011


On Wed, 16 Mar 2011, Torbjorn Granlund wrote:

> I'd like to address the main problem, that of unwinding a call chain in
> GMP without leaking memory.
>
> Do people agree that setjmp/longjmp is the only mechanism available for
> unwinding the call chain?  I am not familiar with -fexceptions.  Does
> that allow for some (portable) neater mechanism?

If C++ code calls C code that calls C++ code that throws an exception, 
compiling the C code with -fexceptions/-funwind-tables allows that 
exception to propagate properly all the way back to the original C++ code.
I think it is supported at least by gcc, Intel and clang (it is even the 
default for clang on x86_64). I believe (but may be wrong) that microsoft 
always behaves like gcc -fexceptions.

That's for the portability aspect. What to do with it is another 
question... If you provide a way to replace abort with user functions, C++ 
programs can provide C++ functions that throw. But you can still get some 
leaks. You'd have to compile gmp as a C++ program (and -fexceptions 
becomes useless), with TMP_ALLOC using destructors, to solve that. But 
then it doesn't sound so different from setjmp/longjmp (except that it is 
more efficient), and I don't think you'd be happy with an option that only 
works when gmp is compiled as C++...

I have never looked at the internals of exception handling, so I don't 
know what it allows exactly (just making sure everyone knows I am just 
ranting ;-)

Hard indeed...

-- 
Marc Glisse


More information about the gmp-bugs mailing list