mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-30 14:30:53 -07:00 
			
		
		
		
	Converted log_failure and fatal to macros (fixes GEN_PANIC not determining correct line or file)
This commit is contained in:
		| @@ -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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user