Skip to content

Commit d493048

Browse files
committed
Add ctb_clear_context
1 parent f661188 commit d493048

10 files changed

Lines changed: 32 additions & 0 deletions

File tree

examples/example.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ static void division_vec(double *vec, double denominator);
1010

1111
int main(void)
1212
{
13+
ctb_clear_context();
14+
ctb_install_signal_handler();
15+
1316
double *vec = malloc(N * sizeof(double));
1417
if (!vec)
1518
{

examples/example_logging.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ void log_message_level2(int i);
2020

2121
int main(void)
2222
{
23+
ctb_clear_context();
24+
ctb_install_signal_handler();
25+
2326
log_error(1);
2427
log_warning(3);
2528
log_message(5);

examples/example_multi_error.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void do_something_risky()
3030

3131
int main(void)
3232
{
33+
ctb_clear_context();
34+
ctb_install_signal_handler();
35+
3336
TRACE(open_file(FILE_PATH1));
3437
TRACE(open_file(FILE_PATH2));
3538

examples/example_open_file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ void open_file(const char *file_name)
1818

1919
int main(void)
2020
{
21+
ctb_clear_context();
22+
ctb_install_signal_handler();
23+
2124
TRY_GOTO(open_file(FILE_PATH), error);
2225
/* Do something */
2326

examples/example_print_compilation_info.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
int main(void)
66
{
7+
ctb_clear_context();
8+
ctb_install_signal_handler();
9+
710
ctb_print_compilation_info();
811

912
return 0;

examples/example_recursion.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ void recursion(int count)
1717

1818
int main(void)
1919
{
20+
ctb_clear_context();
21+
ctb_install_signal_handler();
22+
2023
TRY_GOTO(recursion(0), error);
2124
printf("This shouldn't be printed if there is error");
2225

examples/example_seg_fault.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void some_function(void)
1111

1212
int main(void)
1313
{
14+
ctb_clear_context();
1415
ctb_install_signal_handler();
1516
THROW(CTB_BUFFER_ERROR, "Hello! This is a test error before segfault.");
1617

examples/example_tut04.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void divide_vec(double *arr, const size_t n, const double denominator);
1313

1414
int main(void)
1515
{
16+
ctb_clear_context();
1617
ctb_install_signal_handler();
1718

1819
const size_t n = 1000; // Vector size

include/c_traceback/error.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ bool ctb_check_error(void);
8989
*/
9090
void ctb_clear_error(void);
9191

92+
/**
93+
* \brief Clear the C Traceback context (including errors and call stack).
94+
*/
95+
void ctb_clear_context(void);
96+
9297
#endif // C_TRACEBACK_ERROR_H

src/error.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,10 @@ void ctb_clear_error(void)
116116
{
117117
get_context()->num_errors = 0;
118118
}
119+
120+
void ctb_clear_context(void)
121+
{
122+
CTB_Context *context = get_context();
123+
context->num_errors = 0;
124+
context->call_depth = 0;
125+
}

0 commit comments

Comments
 (0)