Add centrallix-lib Utilities#130
Conversation
Greptile SummaryThis PR adds four new utility modules to
Confidence Score: 5/5Safe to merge; all changes are additive utility code with no modifications to existing logic paths. The new modules are self-contained and only add code; no existing functionality is altered. The two findings are style-level issues (a missing do-while(0) on a debug-only macro, and duplicated cleanup in fprint_mem) that do not affect correctness. centrallix-lib/src/util.c and centrallix-lib/include/timer.h are the two files with style findings worth a second look before merge.
|
| Filename | Overview |
|---|---|
| centrallix-lib/src/util.c | Adds snprint_bytes, snprint_commas_llu, and fprint_mem utilities; logic is correct but fprint_mem duplicates fclose cleanup across two branches instead of using goto error as required by the team's style rule. |
| centrallix-lib/include/timer.h | Declares Timer struct and API; timer_benchmark macro uses bare braces instead of do-while(0), making it unsafe in unbraced if-else contexts. |
| centrallix-lib/src/timer.c | Timer implementation with correct start/stop/accumulation logic, null guards, clock_gettime error handling, and NAN sentinel for unstarted state; no issues found. |
| centrallix-lib/include/check.h | Diagnostic check macros with correct includes (errno.h, math.h, string.h) and GNU statement expressions for safe result capture; no new issues. |
| centrallix-lib/include/range.h | min/max/clamp macros guarded with #ifndef to prevent redefinition collisions; uses typeof for type-safe expansion. |
| centrallix-lib/src/check.c | Implements print_err_internal; correctly dispatches between perror, error-code, and generic stderr output paths. |
| centrallix-lib/src/range.c | Stub translation unit that only includes range.h (all logic is macro-based in the header); no issues. |
| centrallix-lib/include/util.h | Adds declarations for snprint_bytes, snprint_commas_llu, and fprint_mem with correct types; includes stdio.h for FILE*. |
| centrallix-lib/Makefile.in | Adds timer.o/lo, check.o/lo, range.o/lo to both XSTATICFILES and XDYNAMICFILES; correct and symmetric. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Caller] -->|timer_new| B[nmMalloc + timer_init]
A -->|timer_start| C{isnan start?}
C -->|yes| D[start = get_time]
C -->|no| E[noop - already running]
A -->|timer_stop| F{isnan start?}
F -->|yes| G[noop - not running]
F -->|no| H[total += get_time - start\nstart = NAN]
A -->|timer_get| I{isnan start?}
I -->|yes| J[return total]
I -->|no| K[return get_time - start + total]
A -->|timer_free| L[NULL guard → timer_de_init → nmFree]
subgraph get_time
M[clock_gettime CLOCK_MONOTONIC] -->|failure| N[return NAN]
M -->|success| O[return tv_sec + tv_nsec / 1e9]
end
D --> get_time
H --> get_time
K --> get_time
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Caller] -->|timer_new| B[nmMalloc + timer_init]
A -->|timer_start| C{isnan start?}
C -->|yes| D[start = get_time]
C -->|no| E[noop - already running]
A -->|timer_stop| F{isnan start?}
F -->|yes| G[noop - not running]
F -->|no| H[total += get_time - start\nstart = NAN]
A -->|timer_get| I{isnan start?}
I -->|yes| J[return total]
I -->|no| K[return get_time - start + total]
A -->|timer_free| L[NULL guard → timer_de_init → nmFree]
subgraph get_time
M[clock_gettime CLOCK_MONOTONIC] -->|failure| N[return NAN]
M -->|success| O[return tv_sec + tv_nsec / 1e9]
end
D --> get_time
H --> get_time
K --> get_time
Reviews (5): Last reviewed commit: "Fix incorrect type format specifier." | Re-trigger Greptile
|
This PR is ready for human review. |
This PR adds a more organized version of the utilities I created while working on #77, which have since been used in several other projects (which are now blocked by this PR).