Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
cxxaux.cc
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#include "cxxaux.hh"
3#include "logging.hh"
4#include <cxxabi.h> // abi::__cxa_demangle
5#include <unistd.h>
6#include <fcntl.h>
7#include <cstring>
8
9#ifdef ASE_WITH_CPPTRACE
10#include <cpptrace/from_current.hpp>
11#endif
12
13namespace Ase {
14
15VirtualBase::~VirtualBase() noexcept
16{}
17
22const char*
23cxx_demangle (const std::type_info &typeinfo) noexcept
24{
25 static auto &m2d = *new std::unordered_map<const char*, const char*>();
26 static std::mutex mtx;
27 const char *mangled_identifier = typeinfo.name();
28 { std::lock_guard<std::mutex> locker (mtx);
29 auto it = m2d.find (mangled_identifier);
30 if (it != m2d.end())
31 return it->second;
32 }
33 int status = 0;
34 char *malloced_result = abi::__cxa_demangle (mangled_identifier, NULL, NULL, &status);
35 if (malloced_result && !status) {
36 std::lock_guard<std::mutex> locker (mtx);
37 auto it = m2d.find (mangled_identifier);
38 if (it != m2d.end()) {
39 free (malloced_result);
40 return it->second;
41 }
42 m2d[mangled_identifier] = malloced_result;
43 return malloced_result;
44 }
45 return mangled_identifier;
46}
47
49cxx_demangle (const char *mangled_identifier) noexcept
50{
51 int status = 0;
52 char *malloced_result = abi::__cxa_demangle (mangled_identifier, NULL, NULL, &status);
53 std::string result;
54 if (malloced_result && !status) {
55 result = malloced_result;
56 free (malloced_result);
57 }
58 return result.empty() ? mangled_identifier : result;
59}
60
61void
62perror_die (const std::string &msg) noexcept
63{
64 std::string message = msg;
65 if (errno)
66 message += std::string (": ") + strerror (errno);
67 assertion_failed (message.c_str(), nullptr, 0, nullptr);
68 for (;;)
69 abort();
70}
71
73void
74assertion_fatal (const char *msg, const char *file, int line, const char *func) noexcept
75{
76 logging_abort (ASSERTION, msg ? msg : "", file, line, func);
77}
78
80void
81assertion_failed (const char *msg, const char *file, int line, const char *func) noexcept
82{
83 return logging (ASSERTION, msg ? msg : "", file, line, func);
84}
85
86void
88{
89#ifdef ASE_WITH_CPPTRACE
90 cpptrace::rethrow (exception);
91#endif
92 std::rethrow_exception (exception);
93}
94
95} // Ase
abort
T c_str(T... args)
T empty(T... args)
errno
free
The Anklang C++ API namespace.
Definition api.hh:9
void assertion_failed(const char *msg, const char *file, int line, const char *func) noexcept
Print instructive message, handle "breakpoint", "backtrace" and "fatal-warnings" in $ASE_DEBUG.
Definition cxxaux.cc:81
const char * cxx_demangle(const std::type_info &typeinfo) noexcept
Demangle a std::typeinfo.name() string into a proper C++ type name.
Definition cxxaux.cc:23
void assertion_fatal(const char *msg, const char *file, int line, const char *func) noexcept
Print a debug message via assertion_failed() and abort the program.
Definition cxxaux.cc:74
void perror_die(const std::string &msg) noexcept
Issue a warning about an assertion error.
Definition cxxaux.cc:62
void ase_rethrow(std::exception_ptr exception)
Helper to trace rethrown exceptions.
Definition cxxaux.cc:87
T rethrow_exception(T... args)
strerror