|
10 | 10 | //===----------------------------------------------------------------------===//
|
11 | 11 |
|
12 | 12 | #include <exception>
|
13 |
| -#include <memory> |
14 |
| -#include <stdlib.h> |
15 | 13 | #include "abort_message.h"
|
16 | 14 | #include "cxxabi.h"
|
17 | 15 | #include "cxa_handlers.h"
|
|
23 | 21 |
|
24 | 22 | static constinit const char* cause = "uncaught";
|
25 | 23 |
|
26 |
| -#ifndef _LIBCXXABI_NO_EXCEPTIONS |
27 |
| -// Demangle the given string, or return the string as-is in case of an error. |
28 |
| -static std::unique_ptr<char const, void (*)(char const*)> demangle(char const* str) |
29 |
| -{ |
30 |
| -#if !defined(LIBCXXABI_NON_DEMANGLING_TERMINATE) |
31 |
| - if (const char* result = __cxxabiv1::__cxa_demangle(str, nullptr, nullptr, nullptr)) |
32 |
| - return {result, [](char const* p) { std::free(const_cast<char*>(p)); }}; |
33 |
| -#endif |
34 |
| - return {str, [](char const*) { /* nothing to free */ }}; |
35 |
| -} |
36 |
| - |
| 24 | +# ifndef _LIBCXXABI_NO_EXCEPTIONS |
37 | 25 | __attribute__((noreturn))
|
38 | 26 | static void demangling_terminate_handler()
|
39 | 27 | {
|
@@ -61,20 +49,30 @@ static void demangling_terminate_handler()
|
61 | 49 | exception_header + 1;
|
62 | 50 | const __shim_type_info* thrown_type =
|
63 | 51 | static_cast<const __shim_type_info*>(exception_header->exceptionType);
|
64 |
| - auto name = demangle(thrown_type->name()); |
| 52 | + |
| 53 | + auto name = [str = thrown_type->name()] { |
| 54 | +# ifndef LIBCXXABI_NON_DEMANGLING_TERMINATE |
| 55 | + if (const char* result = __cxxabiv1::__cxa_demangle(str, nullptr, nullptr, nullptr)) |
| 56 | + // We're about to abort(), this memory can never be freed; so it's fine |
| 57 | + // to just return a raw pointer |
| 58 | + return result; |
| 59 | +# endif |
| 60 | + return str; |
| 61 | + }(); |
| 62 | + |
65 | 63 | // If the uncaught exception can be caught with std::exception&
|
66 | 64 | const __shim_type_info* catch_type =
|
67 | 65 | static_cast<const __shim_type_info*>(&typeid(std::exception));
|
68 | 66 | if (catch_type->can_catch(thrown_type, thrown_object))
|
69 | 67 | {
|
70 | 68 | // Include the what() message from the exception
|
71 | 69 | const std::exception* e = static_cast<const std::exception*>(thrown_object);
|
72 |
| - abort_message("terminating due to %s exception of type %s: %s", cause, name.get(), e->what()); |
| 70 | + abort_message("terminating due to %s exception of type %s: %s", cause, name, e->what()); |
73 | 71 | }
|
74 | 72 | else
|
75 | 73 | {
|
76 | 74 | // Else just note that we're terminating due to an exception
|
77 |
| - abort_message("terminating due to %s exception of type %s", cause, name.get()); |
| 75 | + abort_message("terminating due to %s exception of type %s", cause, name); |
78 | 76 | }
|
79 | 77 | }
|
80 | 78 | #else // !_LIBCXXABI_NO_EXCEPTIONS
|
|
0 commit comments