This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCHv2] do not throw in std::make_exception_ptr
- From: Daniel Krügler <daniel dot kruegler at gmail dot com>
- To: Gleb Natapov <gleb at scylladb dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 5 Aug 2016 07:56:02 +0200
- Subject: Re: [PATCHv2] do not throw in std::make_exception_ptr
- Authentication-results: sourceware.org; auth=none
- References: <20160805044923.GX17903@scylladb.com>
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?
Thanks,
- Daniel