26#if __cplusplus < 201103L && !defined(va_copy)
27# define va_copy(...) __va_copy(__VA_ARGS__)
46#if __cplusplus < 201103L
48#elif __cplusplus == 201103L
50#elif __cplusplus == 201402L
52#elif __cplusplus == 201703L
54#elif __cplusplus == 202002L
56#elif __cplusplus == 202302L
61#if !ZTH_HAVE_EXCEPTIONS
70#ifdef ZTH_OS_BAREMETAL
77 " newlib" _NEWLIB_VERSION
90# ifdef __ARM_ARCH_PROFILE
91# if __ARM_ARCH_PROFILE == 'A'
93# elif __ARM_ARCH_PROFILE == 'R'
95# elif __ARM_ARCH_PROFILE == 'M'
97# elif __ARM_ARCH_PROFILE == 'S'
105#ifdef ZTH_ARM_USE_PSP
108#if defined(_DEBUG) && (!defined(ZTH_CONFIG_DEBUG) || ZTH_CONFIG_DEBUG)
117#ifdef ZTH_CONTEXT_UCONTEXT
120#ifdef ZTH_CONTEXT_SIGALTSTACK
123#ifdef ZTH_CONTEXT_SJLJ
126#ifdef ZTH_CONTEXT_WINFIBER
132#ifdef ZTH_ENABLE_ASAN
135#ifdef ZTH_ENABLE_LSAN
138#ifdef ZTH_ENABLE_UBSAN
149void abort(
char const* fmt, ...) noexcept
161void abortv(
char const* fmt, va_list args)
noexcept
163 static bool recurse =
false;
174 (void)fflush(
nullptr);
178#ifndef ZTH_OS_BAREMETAL
179static void log_init()
181# ifdef ZTH_OS_WINDOWS
187 (void)setvbuf(stdout,
nullptr, _IOLBF, 4096);
188 (void)setvbuf(stderr,
nullptr, _IOLBF, 4096);
189# ifdef ZTH_OS_WINDOWS
202 static int support = 0;
213 AttachConsole(ATTACH_PARENT_PROCESS);
216 if(!GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode))
218 if(!SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode | 0x0004))
222 if(GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), &mode))
223 SetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), mode | 0x0004);
243 static bool do_color =
246 if(do_color && color > 0)
247 zth::log(
"\x1b[%d%sm", (color % 8) + 30, color >= 8 ?
";1" :
"");
251 if(do_color && color > 0)
258#if __cplusplus >= 201703L
264# if defined(__cpp_lib_string_resize_and_overwrite) \
265 && __cpp_lib_string_resize_and_overwrite >= 202110L
267 res.resize_and_overwrite(
268 res.capacity(), [](
char* ,
size_t size) ->
size_t { return size; });
271 res.resize(res.capacity());
275 va_copy(args2, args);
277 int c = vsnprintf(res.data(), res.size(), fmt, args2);
280 if(
unlikely((
size_t)c >= res.size())) {
282# if defined(__cpp_lib_string_resize_and_overwrite) \
283 && __cpp_lib_string_resize_and_overwrite >= 202110L
284 res.resize_and_overwrite(
285 (
size_t)c + 1U, [](
char* ,
size_t size) ->
size_t {
return size; });
287 res.resize((
size_t)c + 1U);
291 c = vsnprintf(res.data(), res.size(), fmt, args);
295 res.resize(c > 0 ? (
size_t)c : 0);
300string formatv(
char const* fmt, va_list args)
302 int const maxstack = (int)
sizeof(
void*) * 8;
305 char* hbuf =
nullptr;
306 size_t hbuf_size = 0;
310 va_copy(args2, args);
312 int c = vsnprintf(sbuf, maxstack, fmt, args2);
316 hbuf_size = (size_t)c + 1U;
317 hbuf = allocate_noexcept<char>(hbuf_size);
323 int c2 = vsprintf(hbuf, fmt, args);
330 string res(buf, (
size_t)(c < 0 ? 0 : c));
331 deallocate(hbuf, hbuf_size);
350#ifdef ZTH_OS_BAREMETAL
351__attribute__((weak))
int asprintf(
char** strp,
const char* fmt, ...)
355 int res = vasprintf(strp, fmt, args);
360__attribute__((weak))
int vasprintf(
char** strp,
const char* fmt, va_list ap)
364 int len = vsnprintf(
nullptr, 0, fmt, ap_dup);
367 if(strp && (*strp =
static_cast<char*
>(malloc(len + 1))))
368 vsnprintf(*strp, len + 1, fmt, ap);
void zth_abort(char const *fmt,...)
Aborts the process after printing the given printf() formatted message.
#define zth_config(name)
Checks if the given zth::Config field is enabled.
void log_colorv(int color, char const *fmt, va_list args)
Logs a given printf()-like formatted string using an ANSI color code.
void abort(char const *fmt,...) noexcept
Aborts the process after printing the given printf() formatted message.
impl::PickBacktrace ::type Backtrace
Save a backtrace.
#define ZTH_VERSION
Zth version as string literal.
char const * banner() noexcept
Returns a banner line with version and configuration information.
void log(char const *fmt,...)
Logs a given printf()-like formatted string.
void logv(char const *fmt, va_list arg)
Logs a given printf()-like formatted string.
void abortv(char const *fmt, va_list args) noexcept
Aborts the process after printing the given printf() formatted message.
bool log_supports_ansi_colors() noexcept
Returns if the system supports ANSI colors.
string formatv(char const *fmt, va_list args)
Format like vsprintf(), but save the result in an zth::string.
static bool const EnableColorLog
Enable colored output.
#define zth_assert(expr)
assert(), but better integrated in Zth.
#define likely(expr)
Marks the given expression to likely be evaluated to true.
#define ZTH_STRINGIFY(x)
Converts the argument to a string literal.
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.
void zth_terminate()
Terminate immediately.