Skip to content

Commit c602309

Browse files
committed
improve optimization
1 parent 40178d2 commit c602309

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

include/cdk_error.h

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,30 @@
4343
/******************************************************************************
4444
C Development Kit: Error – a modern, fast, errno-like error mechanism.
4545
46-
Errno is awesome idea but in modern languages usually errors brings a lot more
47-
than only status code. CDK: Error aims to bring simple modern errors to C. The
48-
goal is to mimic errno but allow more fields and more advanced error features
49-
than errno allows currently, which are string messages and backtraces.
50-
51-
There are three error types by default:
52-
- Integer error
53-
- String error
54-
- Formatted string error (this one can be disabled)
55-
56-
We are using three errors for performance reasons, integer error is the fastest
57-
string error is just a bit slower and formatted string error is the slowest due
58-
to whole formatting that needs to be performed. C is often choose because of
59-
performance so we are trying to be in the C spirit ;)
60-
61-
If you do not need formatted string you can safe a few bytes by cutting
62-
formatted string buffer out during compilation. To enable that feature define
63-
CDK_ERROR_OPTIMIZE macro.
64-
65-
The second awesome feature are backtraces. Every error is capable of holding
66-
it's backtrace making debugging much much easier. Gathering a backtraces is
67-
manual which may be sometimes annoying but have also few advanteges:
68-
- it's very quick
69-
- it work on every build
70-
- it contain only functions from the lib itself, no noise
71-
72-
*****************************************************************************/
46+
The idea behind `errno` is great, but in modern languages errors usually carry
47+
more than just a status code. `cdk_error` brings that spirit to C: a simple,
48+
lightweight error API with extra context such as string messages and manual
49+
backtraces.
50+
51+
By default there are three error kinds:
52+
- Integer error
53+
- String error
54+
- Formatted string error (can be disabled)
55+
56+
Each type exists for performance reasons. Integer errors are the fastest,
57+
string errors add only a little overhead, and formatted errors are the slowest
58+
because of formatting work. Since C is often chosen for performance, you can
59+
trim down to only what you need. Defining `CDK_ERROR_OPTIMIZE` removes the
60+
formatted string buffer to save bytes.
61+
62+
Another key feature is backtraces. Every error can store its own trace, making
63+
debugging far easier. Trace collection is manual, which might feel verbose,
64+
but it has important advantages:
65+
- extremely fast
66+
- works in every build (no special compiler flags)
67+
- includes only frames from your code, no external noise
68+
69+
******************************************************************************/
7370
//////////
7471

7572
/******************************************************************************
@@ -87,6 +84,8 @@
8784
#endif
8885

8986
#ifndef CDK_ERROR_OPTIMIZE
87+
#undef CDK_ERROR_BTRACE_MAX
88+
#define CDK_ERROR_BTRACE_MAX 1
9089
#endif
9190

9291
/******************************************************************************

0 commit comments

Comments
 (0)