-
Notifications
You must be signed in to change notification settings - Fork 41
Better error and log messages #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,25 @@ | |
|
|
||
| #include <capnp/schema.h> | ||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
| #include <exception> | ||
| #include <functional> | ||
| #include <kj/string-tree.h> | ||
| #include <mutex> | ||
| #include <string> | ||
| #include <tuple> | ||
| #include <typeinfo> | ||
| #include <type_traits> | ||
| #include <utility> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| #if __has_include(<cxxabi.h>) | ||
| #include <cxxabi.h> | ||
| #include <memory> | ||
| #endif | ||
|
|
||
| namespace mp { | ||
|
|
||
| //! Generic utility functions used by capnp code. | ||
|
|
@@ -274,6 +280,28 @@ inline char* CharCast(unsigned char* c) { return (char*)c; } | |
| inline const char* CharCast(const char* c) { return c; } | ||
| inline const char* CharCast(const unsigned char* c) { return (const char*)c; } | ||
|
|
||
| #if __has_include(<cxxabi.h>) // GCC & Clang ─ use <cxxabi.h> to demangle | ||
| inline std::string _demangle(const char* m) | ||
| { | ||
| int status = 0; | ||
| std::unique_ptr<char, void(*)(void*)> p{ | ||
| abi::__cxa_demangle(m, nullptr, nullptr, &status), std::free}; | ||
| return (status == 0 && p) ? p.get() : m; // fall back on mangled if needed | ||
| } | ||
| #else // MSVC or other ─ no demangling available | ||
| inline std::string _demangle(const char* m) { return m; } | ||
| #endif | ||
|
|
||
| template<class T> | ||
| std::string CxxTypeName(const T& /*unused*/) | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is only done in one place now, maybe wrap this in (c++20 standard)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: #218 (comment) Sure, added |
||
| #ifdef __cpp_rtti | ||
| return _demangle(typeid(std::decay_t<T>).name()); | ||
| #else | ||
| return "<type information unavailable without rtti>"; | ||
| #endif | ||
| } | ||
|
|
||
| //! Exception thrown from code executing an IPC call that is interrupted. | ||
| struct InterruptException final : std::exception { | ||
| explicit InterruptException(std::string message) : m_message(std::move(message)) {} | ||
|
|
@@ -337,6 +365,7 @@ void CancelMonitor::promiseDestroyed(CancelProbe& probe) | |
| if (m_on_cancel) m_on_cancel(); | ||
| m_probe = nullptr; | ||
| } | ||
|
|
||
| } // namespace mp | ||
|
|
||
| #endif // MP_UTIL_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
CxxTypeNamealways being evaluated now? Isn't that a bit wasteful?