diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f7481c..c5534a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ if(ENABLE_SANITIZERS) endif() # --- Definitions --- -target_compile_definitions(c_traceback PRIVATE VERSION_INFO="${PROJECT_VERSION}") +target_compile_definitions(c_traceback PRIVATE CTB_VERSION="${PROJECT_VERSION}") # --- Installation --- if(PROJECT_IS_TOP_LEVEL) diff --git a/examples/example.c b/examples/example.c index bd32e94..bbef4c4 100644 --- a/examples/example.c +++ b/examples/example.c @@ -10,6 +10,9 @@ static void division_vec(double *vec, double denominator); int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + double *vec = malloc(N * sizeof(double)); if (!vec) { diff --git a/examples/example_logging.c b/examples/example_logging.c index 47d00a1..2f18355 100644 --- a/examples/example_logging.c +++ b/examples/example_logging.c @@ -20,6 +20,9 @@ void log_message_level2(int i); int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + log_error(1); log_warning(3); log_message(5); diff --git a/examples/example_multi_error.c b/examples/example_multi_error.c index 80cb98e..67106a0 100644 --- a/examples/example_multi_error.c +++ b/examples/example_multi_error.c @@ -30,6 +30,9 @@ void do_something_risky() int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + TRACE(open_file(FILE_PATH1)); TRACE(open_file(FILE_PATH2)); diff --git a/examples/example_open_file.c b/examples/example_open_file.c index dbe2c44..e68c52b 100644 --- a/examples/example_open_file.c +++ b/examples/example_open_file.c @@ -18,6 +18,9 @@ void open_file(const char *file_name) int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + TRY_GOTO(open_file(FILE_PATH), error); /* Do something */ diff --git a/examples/example_print_compilation_info.c b/examples/example_print_compilation_info.c index 305b45d..2cdda98 100644 --- a/examples/example_print_compilation_info.c +++ b/examples/example_print_compilation_info.c @@ -4,6 +4,9 @@ int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + ctb_print_compilation_info(); return 0; diff --git a/examples/example_recursion.c b/examples/example_recursion.c index 24f4ffe..1b184ad 100644 --- a/examples/example_recursion.c +++ b/examples/example_recursion.c @@ -17,6 +17,9 @@ void recursion(int count) int main(void) { + ctb_clear_context(); + ctb_install_signal_handler(); + TRY_GOTO(recursion(0), error); printf("This shouldn't be printed if there is error"); diff --git a/examples/example_seg_fault.c b/examples/example_seg_fault.c index 999a573..6ab1090 100644 --- a/examples/example_seg_fault.c +++ b/examples/example_seg_fault.c @@ -11,6 +11,7 @@ void some_function(void) int main(void) { + ctb_clear_context(); ctb_install_signal_handler(); THROW(CTB_BUFFER_ERROR, "Hello! This is a test error before segfault."); diff --git a/examples/example_tut04.c b/examples/example_tut04.c index cad4578..266897f 100644 --- a/examples/example_tut04.c +++ b/examples/example_tut04.c @@ -13,6 +13,7 @@ void divide_vec(double *arr, const size_t n, const double denominator); int main(void) { + ctb_clear_context(); ctb_install_signal_handler(); const size_t n = 1000; // Vector size diff --git a/include/c_traceback/error.h b/include/c_traceback/error.h index 78e3982..7d5725c 100644 --- a/include/c_traceback/error.h +++ b/include/c_traceback/error.h @@ -89,4 +89,9 @@ bool ctb_check_error(void); */ void ctb_clear_error(void); +/** + * \brief Clear the C Traceback context (including errors and call stack). + */ +void ctb_clear_context(void); + #endif // C_TRACEBACK_ERROR_H diff --git a/src/error.c b/src/error.c index cebe8a5..546f291 100644 --- a/src/error.c +++ b/src/error.c @@ -116,3 +116,10 @@ void ctb_clear_error(void) { get_context()->num_errors = 0; } + +void ctb_clear_context(void) +{ + CTB_Context *context = get_context(); + context->num_errors = 0; + context->call_depth = 0; +}