This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCHv2] do not throw in std::make_exception_ptr
On Fri, Aug 05, 2016 at 07:56:02AM +0200, Daniel Krügler wrote:
> 2016-08-05 6:49 GMT+02:00 Gleb Natapov <gleb@scylladb.com>:
> > Instead of throwing an exception allocate its memory and initialize it
> > explicitly. Makes std::make_exception_ptr more efficient since no stack
> > unwinding is needed.
>
> [..]
>
> > +#ifndef _CXXABI_INIT_EXCEPTION_H
> > +#define _CXXABI_INIT_EXCEPTION_H 1
> > +
> > +#pragma GCC system_header
> > +
> > +#pragma GCC visibility push(default)
> > +
> > +#include <stddef.h>
> > +#include <bits/c++config.h>
> > +
> > +#ifndef _GLIBCXX_CDTOR_CALLABI
> > +#define _GLIBCXX_CDTOR_CALLABI
> > +#define _GLIBCXX_HAVE_CDTOR_CALLABI 0
> > +#else
> > +#define _GLIBCXX_HAVE_CDTOR_CALLABI 1
> > +#endif
>
> > /// Obtain an exception_ptr pointing to a copy of the supplied object.
> > template<typename _Ex>
> > @@ -173,7 +184,16 @@ namespace std
> > #if __cpp_exceptions
> > try
> > {
> > - throw __ex;
> > +#if __cpp_rtti && !_GLIBCXX_HAVE_CDTOR_CALLABI
> > + void *__e = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ex));
> > + (void)__cxxabiv1::__cxa_init_primary_exception(__e,
> > + const_cast<std::type_info*>(&typeid(__ex)),
> > + __exception_ptr::__dest_thunk<_Ex>);
> > + new (__e) _Ex(__ex);
> > + return exception_ptr(__e);
> > +#else
> > + throw __ex;
> > +#endif
>
> Please take this question was a grain of salt: Is it really correct
> that the more efficient approach is used, when
>
> !_GLIBCXX_HAVE_CDTOR_CALLABI
>
> instead of
>
> _GLIBCXX_HAVE_CDTOR_CALLABI
>
> ?
>
> To me _GLIBCXX_HAVE_CDTOR_CALLABI sounds like a feature but with that
> logic it sounds more like it would be constraint, is that correct?
>
_GLIBCXX_HAVE_CDTOR_CALLABI means that a platform has special calling
convention for class members. It is not a feature just a platform quirk.
On such platform __dest_thunk will not work.
--
Gleb.