Skip to content

Add centrallix-lib Utilities - #130

Open
Lightning11wins wants to merge 54 commits into
masterfrom
add-utils
Open

Lightning11wins wants to merge 54 commits into
masterfrom
add-utils

Conversation

@Lightning11wins

Copy link
Copy Markdown
Contributor

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).

@Lightning11wins Lightning11wins self-assigned this Jun 26, 2026
@Lightning11wins Lightning11wins added ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer. labels Jun 26, 2026
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds timer.c/h, check.c/h, range.c/h, and new utilities in util.c/h as formally organised centrallix-lib components, integrates them into the build system (Makefile.in, configure.ac), refactors mtsession.c to use mssError_internal with macro wrappers for __FILE__/__LINE__ injection, and adds three new strtcatf/strtcatf_va test cases.

  • New utilities: timerInit/Start/Stop/Get/Free with NaN-sentinel guards for unstarted timers and clock-failure robustness; check/checkPos/checkDouble/checkPtr macros for diagnostics-on-failure; min/max/clamp/roundTo with #ifndef collision guards; snprintBytes, snprintCommasLlu, and fprintMem for memory reporting.
  • mtsession refactor: mssError is now a macro wrapping mssError_internal, which injects source location at the call site; the previously flagged xaAddItem leak on error is fixed.
  • Build system: -lm detection added to configure.ac for pow/round/isnan/NAN in the new modules.

Confidence Score: 4/5

  • The new utility modules are well-structured and the previously flagged issues (NaN poisoning, xaAddItem leak, wrong accumulation operator) are all fixed. One new function (fprintMem) uses direct returns in place of the project's required goto error pattern.
  • fprintMem is a nontrivial new function that opens a file handle and exits through four separate return sites instead of a single goto error / cleanup label. The team has enforced this requirement strictly on previous findings in this same PR. Everything else — timer NaN guards, check macros, range helpers, mtsession refactor — looks correct.
  • centrallix-lib/src/util.c — the new fprintMem function needs its error exits converted to goto error.

Important Files Changed

Filename Overview
centrallix-lib/src/util.c Adds snprintBytes, snprintCommasLlu, and fprintMem utilities. fprintMem uses direct returns instead of goto error, violating the required project convention for nontrivial functions.
centrallix-lib/include/timer.h Defines Timer struct and declares the timer API. The timerBenchmark debug macro uses a bare block that can cause compile errors with trailing else clauses.
centrallix-lib/src/timer.c Full timer implementation with correct NaN guards for unstarted timers, accumulating stop, and clock failure handling. Previous review issues (NaN poisoning, missing null guard) are all addressed.
centrallix-lib/include/check.h Error-checking macros for int, positive-int, double, and pointer results. Includes math.h and string.h for isnan/strrchr. printFail is wrapped in do-while(0). GCC statement expressions are used intentionally throughout.
centrallix-lib/src/mtsession.c Refactors mssError into mssError_internal with macro wrappers, adds mssUserError, and integrates strtcpy/check utilities. The previously flagged xaAddItem leak on insertion failure has been fixed.
centrallix-lib/tests/test_strtcpy_11.c Table-driven test for strtcatf() covering return values, *pos tracking, null-termination, and guard-byte integrity across normal, exact-fit, truncating, and degenerate cases.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([timerNew]) --> B[nmMalloc + timerInit\nstart=NAN, total=0]
    B --> C([timerStart])
    C --> D{isnan start?}
    D -- Yes: not running --> E[start = getTime]
    D -- No: already running --> F[noop return]
    E --> G([timerStop])
    G --> H{isnan start?}
    H -- Yes: not started --> I[noop return]
    H -- No: running --> J[stop_time = getTime]
    J --> K{isnan stop_time?}
    K -- Yes: clock failed --> L[keep running, return]
    K -- No --> M[total += stop_time - start\nstart = NAN]
    M --> N([timerGet])
    N --> O{isnan start?}
    O -- stopped --> P[return total]
    O -- running --> Q[current = getTime - start\nreturn total + current]
    P --> R([timerFree / timerReset])
    Q --> R
    R --> S[nmFree or re-init]
Loading

Reviews (13): Last reviewed commit: "Rename checkNeg() to checkPos()." | Re-trigger Greptile

Comment thread centrallix-lib/include/check.h
Comment thread centrallix-lib/include/check.h
Comment thread centrallix-lib/src/timer.c
Comment thread centrallix-lib/src/timer.c Outdated
Comment thread centrallix-lib/src/timer.c
Comment thread centrallix-lib/src/util.c Outdated
Comment thread centrallix-lib/include/range.h
Comment thread centrallix-lib/src/timer.c Outdated
Comment thread centrallix-lib/include/check.h
Comment thread centrallix-lib/src/util.c Outdated
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

This PR is ready for human review.

This was referenced Jul 28, 2026
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

This PR is definitely too large to be considered trivial!

@Lightning11wins Lightning11wins added the testing Includes testing, either new tests or updates to existing tests. label Aug 24, 2026
Comment thread centrallix-lib/src/timer.c
Comment thread centrallix-lib/include/check.h Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread centrallix-lib/src/timer.c Outdated
This was referenced Sep 4, 2026
Comment thread centrallix-lib/include/mtsession.h Outdated
Comment thread centrallix-lib/src/mtsession.c Outdated
@Lightning11wins Lightning11wins mentioned this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request AI review for PRs. size: medium Might be hard to review, usually less than ~5000 lines. testing Includes testing, either new tests or updates to existing tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants