Anklang-0.3.0.dev595+g65331842 anklang-0.3.0.dev595+g65331842
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
9namespace Ase {
10
11VirtualBase::~VirtualBase() noexcept
12{}
13
18const char*
19cxx_demangle (const std::type_info &typeinfo) noexcept
20{
21 static auto &m2d = *new std::unordered_map<const char*, const char*>();
22 static std::mutex mtx;
23 const char *mangled_identifier = typeinfo.name();
24 { std::lock_guard<std::mutex> locker (mtx);
25 auto it = m2d.find (mangled_identifier);
26 if (it != m2d.end())
27 return it->second;
28 }
29 int status = 0;
30 char *malloced_result = abi::__cxa_demangle (mangled_identifier, NULL, NULL, &status);
31 if (malloced_result && !status) {
32 std::lock_guard<std::mutex> locker (mtx);
33 auto it = m2d.find (mangled_identifier);
34 if (it != m2d.end()) {
35 free (malloced_result);
36 return it->second;
37 }
38 m2d[mangled_identifier] = malloced_result;
39 return malloced_result;
40 }
41 return mangled_identifier;
42}
43
45cxx_demangle (const char *mangled_identifier) noexcept
46{
47 int status = 0;
48 char *malloced_result = abi::__cxa_demangle (mangled_identifier, NULL, NULL, &status);
49 std::string result;
50 if (malloced_result && !status) {
51 result = malloced_result;
52 free (malloced_result);
53 }
54 return result.empty() ? mangled_identifier : result;
55}
56
57void
58perror_die (const std::string &msg) noexcept
59{
60 std::string message = msg;
61 if (errno)
62 message += std::string (": ") + strerror (errno);
63 assertion_failed (message.c_str(), nullptr, 0, nullptr);
64 for (;;)
65 abort();
66}
67
69void
70assertion_fatal (const char *msg, const char *file, int line, const char *func) noexcept
71{
72 logging_abort (ASSERTION, msg ? msg : "", file, line, func);
73}
74
76void
77assertion_failed (const char *msg, const char *file, int line, const char *func) noexcept
78{
79 return logging (ASSERTION, msg ? msg : "", file, line, func);
80}
81
82} // 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:77
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:19
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:70
void perror_die(const std::string &msg) noexcept
Issue a warning about an assertion error.
Definition cxxaux.cc:58
strerror