mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Converted log_failure and fatal to macros (fixes GEN_PANIC not determining correct line or file)
This commit is contained in:
parent
ed3246c6b0
commit
d2fc1d0a56
@ -4413,13 +4413,6 @@ CodeTypedef parse_typedef()
|
||||
|
||||
if ( tok.Type == TokType::BraceCurly_Close )
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
}* Something;
|
||||
|
||||
|
||||
// Its an inplace definition
|
||||
// typdef <which> <type_identifier> { ... } <identifier>;
|
||||
ok_to_parse = true;
|
||||
|
@ -3,9 +3,9 @@ using LogFailType = sw(*)(char const*, ...);
|
||||
// By default this library will either crash or exit if an error is detected while generating codes.
|
||||
// Even if set to not use fatal, fatal will still be used for memory failures as the library is unusable when they occur.
|
||||
#ifdef GEN_DONT_USE_FATAL
|
||||
constexpr LogFailType log_failure = log_fmt;
|
||||
#define log_failure log_fmt
|
||||
#else
|
||||
constexpr LogFailType log_failure = fatal;
|
||||
#define log_failure fatal
|
||||
#endif
|
||||
|
||||
enum class AccessSpec : u32
|
||||
|
@ -33,5 +33,27 @@ void assert_handler( char const* condition, char const* file, s32 line, char con
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
#if Build_Debug
|
||||
#define fatal( fmt, ... ) \
|
||||
do \
|
||||
{ \
|
||||
local_persist thread_local \
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
|
||||
\
|
||||
str_fmt(buf, GEN_PRINTF_MAXLEN, fmt, __VA_ARGS__); \
|
||||
GEN_PANIC(buf); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
|
||||
# define fatal( fmt, ... ) \
|
||||
do \
|
||||
{ \
|
||||
str_fmt_out_err_va( fmt, __VA_ARGS__ ); \
|
||||
process_exit(1); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#pragma endregion Debug
|
||||
|
||||
|
@ -541,6 +541,16 @@ sw str_fmt_file( struct FileInfo* f, char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt( char* str, sw n, char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( str, n, fmt, va );
|
||||
va_end( va );
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt_out_va( char const* fmt, va_list va )
|
||||
{
|
||||
return str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
|
||||
|
@ -9,6 +9,7 @@ struct FileInfo;
|
||||
// NOTE: A locally persisting buffer is used internally
|
||||
char* str_fmt_buf ( char const* fmt, ... );
|
||||
char* str_fmt_buf_va ( char const* fmt, va_list va );
|
||||
sw str_fmt ( char* str, sw n, char const* fmt, ... );
|
||||
sw str_fmt_va ( char* str, sw n, char const* fmt, va_list va );
|
||||
sw str_fmt_out_va ( char const* fmt, va_list va );
|
||||
sw str_fmt_out_err ( char const* fmt, ... );
|
||||
@ -32,30 +33,5 @@ sw log_fmt(char const* fmt, ...)
|
||||
return res;
|
||||
}
|
||||
|
||||
inline
|
||||
sw fatal(char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
|
||||
#if Build_Debug
|
||||
va_start(va, fmt);
|
||||
str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
assert_crash(buf);
|
||||
return -1;
|
||||
#else
|
||||
va_start(va, fmt);
|
||||
str_fmt_out_err_va( fmt, va);
|
||||
va_end(va);
|
||||
|
||||
exit(1);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user