_mp_alloc vs ALLOC

Niels Möller nisse at lysator.liu.se
Mon Jun 4 21:32:49 CEST 2012


Torbjorn Granlund <tg at gmplib.org> writes:

> I know of only two C mechanims, either signals+handlers or setjmp+
> longjmp.

I'm not entirely sure what type of errors you are considering handling
here? Memory allocation failures? Divide-by-zero? Something else?

It's possible to make errno-style handling thread safe by using some of
the available mechanisms for putting errno into thread local storage
(pointer to current exception handler would likewise also have to live
in thread-local storage). But it's not particularly pretty.

Returning a success/failure from each call, and manually propagating the
error up the call tree (and doing any needed cleanup un the way) seems
to be the sanest way to do error handling in C. Even if it's a lot of
clutter.

If you do something like exceptions with setjmp/longjmp, I think you'd
also need something like unwind-protect to ensure that you cleanup
temporary allocations and the like, and that appears a bit brittle to me
(but I'm not sure I'd trust the automatic stack unwinding with C++
exceptions either...).

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list