Compare commits
3 Commits
8d7eff2a15
...
31c624797f
| Author | SHA1 | Date | |
|---|---|---|---|
| 31c624797f | |||
| 6ecf6935d8 | |||
| d6b1d7fd46 |
@ -157,6 +157,15 @@ PUBLIC
|
|||||||
$<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>
|
$<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Fix GCC std::stacktrace link error
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
|
||||||
|
target_link_libraries(YYCCommonplace PRIVATE stdc++exp)
|
||||||
|
else ()
|
||||||
|
target_link_libraries(YYCCommonplace PRIVATE stdc++_libbacktrace)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Install binary and headers
|
# Install binary and headers
|
||||||
install(TARGETS YYCCommonplace
|
install(TARGETS YYCCommonplace
|
||||||
EXPORT YYCCommonplaceTargets
|
EXPORT YYCCommonplaceTargets
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#define REINTERPRET ::yycc::string::reinterpret
|
#define REINTERPRET ::yycc::string::reinterpret
|
||||||
#define WINFCT ::yycc::windows::winfct
|
#define WINFCT ::yycc::windows::winfct
|
||||||
#define FOPEN ::yycc::patch::fopen
|
#define FOPEN ::yycc::patch::fopen
|
||||||
|
|
||||||
using namespace std::literals::string_view_literals;
|
using namespace std::literals::string_view_literals;
|
||||||
|
|
||||||
namespace yycc::carton::ironpad {
|
namespace yycc::carton::ironpad {
|
||||||
|
|||||||
@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
namespace yycc::patch::format {
|
namespace yycc::patch::format {
|
||||||
|
|
||||||
// TODO: order all use of std::format redirect to this function.
|
|
||||||
// TODO: all use of OP::printf should also switch to this function if possible.
|
|
||||||
|
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
std::string format(std::format_string<Args...> fmt, Args&&... args) {
|
std::string format(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
return std::vformat(fmt.get(), std::make_format_args(args...));
|
return std::vformat(fmt.get(), std::make_format_args(args...));
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stacktrace>
|
||||||
|
|
||||||
#define TERMCOLOR ::yycc::carton::termcolor
|
#define TERMCOLOR ::yycc::carton::termcolor
|
||||||
|
|
||||||
@ -11,14 +12,7 @@ using namespace yycc::patch::stream;
|
|||||||
|
|
||||||
namespace yycc::rust::panic {
|
namespace yycc::rust::panic {
|
||||||
|
|
||||||
// TODO:
|
void panic(const char* file, int line, const std::u8string_view& msg) {
|
||||||
// I sadly remove the stacktrace feature for panic function.
|
|
||||||
// Because in GCC, it has link error (can be fixed by extra link option).
|
|
||||||
// In Clang, it even lack the whole header file.
|
|
||||||
// It seems that STL providers are not ready for this feature. So I decide remove it entirely.
|
|
||||||
// Once every STL probiders have ready for this, I will add it back.
|
|
||||||
|
|
||||||
void panic(const char* file, int line, const std::string_view& msg) {
|
|
||||||
// Output message in stderr.
|
// Output message in stderr.
|
||||||
auto& dst = std::cerr;
|
auto& dst = std::cerr;
|
||||||
|
|
||||||
@ -29,6 +23,9 @@ namespace yycc::rust::panic {
|
|||||||
dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl;
|
dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl;
|
||||||
// User custom message
|
// User custom message
|
||||||
dst << "note: " << msg << std::endl;
|
dst << "note: " << msg << std::endl;
|
||||||
|
// Stacktrace message if we support it.
|
||||||
|
dst << "stacktrace: " << std::endl;
|
||||||
|
dst << std::stacktrace::current() << std::endl;
|
||||||
// Restore color
|
// Restore color
|
||||||
dst << TERMCOLOR::reset();
|
dst << TERMCOLOR::reset();
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../patch/format.hpp"
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
@ -22,19 +23,15 @@
|
|||||||
*/
|
*/
|
||||||
namespace yycc::rust::panic {
|
namespace yycc::rust::panic {
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
|
||||||
* @details The macro parameter is the additional message to display.
|
|
||||||
*/
|
|
||||||
#define RS_PANIC(msg) ::yycc::rust::panic::panic(__FILE__, __LINE__, (msg))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
||||||
* @details
|
* @details
|
||||||
* The macro parameters are the message to format and its arguments, following \c std::format syntax.
|
* The macro parameters are the message to format and its arguments, following \c std::format syntax.
|
||||||
* This macro essentially calls \c std::format internally.
|
* This macro essentially calls \c std::format internally.
|
||||||
|
* However, this format function is specially modified that it can accept UTF8 format string and UTF8 string argument.
|
||||||
|
* More preciously, it is "format" in \c yycc::patch::format namespace.
|
||||||
*/
|
*/
|
||||||
#define RS_PANICF(msg, ...) RS_PANIC(std::format(msg __VA_OPT__(,) __VA_ARGS__))
|
#define RS_PANIC(msg, ...) ::yycc::rust::panic::panic(__FILE__, __LINE__, ::yycc::patch::format::format(msg __VA_OPT__(, ) __VA_ARGS__))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
||||||
@ -45,6 +42,6 @@ namespace yycc::rust::panic {
|
|||||||
* @param[in] line Line number in source file where panic occurred. Usually filled by macros.
|
* @param[in] line Line number in source file where panic occurred. Usually filled by macros.
|
||||||
* @param[in] msg Message to display during panic.
|
* @param[in] msg Message to display during panic.
|
||||||
*/
|
*/
|
||||||
[[noreturn]] void panic(const char* file, int line, const std::string_view& msg);
|
[[noreturn]] void panic(const char* file, int line, const std::u8string_view& msg);
|
||||||
|
|
||||||
} // namespace yycc::rust::panic
|
} // namespace yycc::rust::panic
|
||||||
|
|||||||
Reference in New Issue
Block a user