Skip to content

Commit 4baba48

Browse files
committed
Update API docs
1 parent eecd841 commit 4baba48

File tree

7 files changed

+420
-89
lines changed

7 files changed

+420
-89
lines changed

content/docs/API/_meta.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
'call_stack_management': '',
3+
'error_propagation': '',
4+
'error_types': '',
5+
'inline_logging': '',
6+
'signal_handling': '',
7+
'miscellaneous': '',
8+
};

content/docs/API/call_stack_management.mdx

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,92 +11,65 @@ Unfortunately, C doesn't provide an easy way to do this. Therefore, we will have
1111
function calls or code blocks with a macro. While this approach can be quite verbose, it
1212
is what makes our library possible.
1313

14-
<Callout type="warning">Do not use jump statements inside macro, including `break`, `continue`, `return` and `goto`.</Callout>
14+
<Callout type="warning">Do not use jump statements to jump outside macro, including `break`, `continue`, `return` and `goto`.</Callout>
1515

1616
## API
1717

1818
### `TRACE` <Badge text="Macro" />
19-
Wrapper macro for expression to automatically manage call stack frames.
19+
Wrapper macro for expression to automatically manage call stack frames without checking for errors.
2020
```c
21-
TRACE(expr)
21+
void TRACE(expr)
2222
```
2323
24+
<Callout type="info">
25+
Always use `TRY` instead of `TRACE` when error handling matters.
26+
It is easy to miss errors as `TRACE` are not checking for errors stored
27+
in context.
28+
[See `TRY`](/docs/API/error_propagation#try-)
29+
</Callout>
30+
2431
#### Parameters
2532
<ParamsTable
2633
params={[
2734
{ name: "expr", type: "N/A", desc: "The expression to be traced." },
2835
]}
2936
/>
3037
31-
#### Returns
32-
<ParamsTable
33-
params={[
34-
{ name: "success", type: "bool", desc: "Whether the expression executed without error." },
35-
]}
36-
/>
37-
3838
#### Expands to
3939
```c
40-
(ctb_push_call_stack_frame(__FILE__, __func__, __LINE__, #expr), \
41-
(expr), \
42-
ctb_pop_call_stack_frame(__FILE__, __func__, __LINE__, #expr), \
43-
!ctb_check_error_occurred())
40+
do \
41+
{ \
42+
ctb_push_call_stack_frame(__FILE__, __func__, __LINE__, #expr); \
43+
(expr); \
44+
ctb_pop_call_stack_frame(__FILE__, __func__, __LINE__, #expr); \
45+
} while (0)
4446
```
4547

4648
#### Usage
4749
```c
4850
int function_a(void)
4951
{
50-
bool success = TRACE(function_b()); // Trace a function call
52+
TRACE(function_b()); // Trace a function call
5153
}
5254

5355
int function_b(void)
5456
{
5557
int i = 0;
56-
(void) TRACE(i = 2); // Trace any expression
58+
TRACE(i = 2); // Trace any expression
5759
}
5860
```
5961
60-
### `TRACE_VOID` <Badge text="Macro" />
61-
Wrapper macro for expression to automatically manage call stack frames without checking for error.
62-
```c
63-
TRACE_VOID(expr)
64-
```
65-
66-
<Callout type="info">
67-
Do not use `TRACE_VOID` unless you trust the outer scope will take care of the
68-
error handling. It is easy to miss error states stored in hidden context.
69-
</Callout>
70-
71-
#### Parameters
72-
<ParamsTable
73-
params={[
74-
{ name: "expr", type: "N/A", desc: "The expression to be traced." },
75-
]}
76-
/>
77-
78-
#### Expands to
79-
```c
80-
do \
81-
{ \
82-
ctb_push_call_stack_frame(__FILE__, __func__, __LINE__, #expr); \
83-
(expr); \
84-
ctb_pop_call_stack_frame(__FILE__, __func__, __LINE__, #expr); \
85-
} while (0)
86-
```
87-
88-
#### Usage
89-
Same as `TRACE` but without return value.
90-
9162
### `TRACE_BLOCK` <Badge text="Macro" />
92-
Wrapper macro for a code block to automatically manage call stack frames.
63+
Wrapper macro for a code block to automatically manage call stack frames without checking for errors.
9364
```c
94-
TRACE_BLOCK(...)
65+
void TRACE_BLOCK(...)
9566
```
9667

9768
<Callout type="info">
98-
Do not use `TRACE_BLOCK` unless you trust the outer scope will take care of the
99-
error handling. It is easy to miss error states stored in hidden context.
69+
Always call `ctb_check_error` after `TRACE_BLOCK` when error handling matters.
70+
It is easy to miss errors as `TRACE_BLOCK` are not checking for errors stored
71+
in context.
72+
[See `ctb_check_error`](/docs/API/error_propagation#ctb_check_error-)
10073
</Callout>
10174

10275
#### Parameters
@@ -122,11 +95,8 @@ int function_a(void)
12295
{
12396
/* Trace a code block */
12497
TRACE_BLOCK(
125-
int i = 0;
126-
if (i == 0)
127-
{
128-
printf("%d", i);
129-
}
98+
int *ptr;
99+
printf("%d", *ptr); // Oops, segmentation fault
130100
); // <-- Don't forget the semi-colon
131101

132102
// Note: i is not accessible here

0 commit comments

Comments
 (0)