This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Implementing Exception Propagation (N2179)
- From: Sebastian Redl <sebastian dot redl at getdesigned dot at>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 22 May 2008 20:35:38 +0200
- Subject: Re: Implementing Exception Propagation (N2179)
- References: <482F4610.3020008@getdesigned.at>
I've had even more thoughts about this. It occurred to me that I could
avoid the whole mess with the copying of the exception object by
splitting the exception object and the exception header apart. Every
exception object is reference-counted. The exception header contains a
pointer to the exception object.
This complicates allocation a bit. But it makes throwing the exception
much easier. Instead of having to look up and pass a copy constructor,
all the code needs to do is dereference the pointer it gets from
__cxa_allocate_exception (because that function now returns the pointer
to the exception header, which has the pointer to the exception object
as its first field).
Now multiple exception headers can refer to the same exception object.
Thus, no copying needed.
The idea can be taken a bit further. For example, there is some
information in the header that really doesn't need to be duplicated,
namely the exceptionType and exceptionDestructor fields. This could be
transferred to the object allocation.
Once these two fields are in the object allocation, exception_ptr would
no longer need to keep the whole header around. It could instead refer
directly to the object allocation, and rethrow_exception would just
create a new header for the new unwinding.
All this shouldn't be too hard to implement, although it will still
break the ABI quite thoroughly. Which reminds me: does breaking the ABI
this way mean that the __cxxabiv1 namespace should be renamed to __cxxabiv2?
Also, how far do you think I should go with the transfer? Should I keep
just the exception object and reference count separate? Or should I
transfer as much as possible over and have the exception_ptr point to
that instead? I personally feel more like doing the latter.
Oh, and on a slightly related side note, I've implemented
nested_exception. It depends on exception_ptr, of course, but is
otherwise quite trivial. I've got some minor code organization questions
about it, but that can wait.
Sebastian