Encapsulate fsBytesUsed/fsBytesTotal with read-only accessors - #5789
Conversation
fsBytesUsed/fsBytesTotal were WLED_GLOBAL, written and read by file.cpp (via updateFSInfo()), and read-only from json.cpp (status report in serializeInfo()). Since json.cpp never writes them, moved them to file-local static in file.cpp and exposed two by-value getters, getFsBytesUsed()/getFsBytesTotal(), instead of a mutable reference. This is a real, compiler-enforced improvement, not just relabeling: because the getters return by value, an accidental write from json.cpp (or any other file) is now a build error instead of a silent bug - unlike the write-needed Tier-2 cases (loadLedmap, dnsServer) that were deliberately left as plain globals since no accessor shape actually restricts those. No behavior change - purely a storage/access-pattern change. Verified: - esp32dev builds and links cleanly via `pio run -e esp32dev`. - usermods env (builds all 59 usermods) builds and links cleanly via `pio run -e usermods`. - Repo-wide grep confirms no remaining raw references to either identifier outside file.cpp. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 12 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Part of an ongoing pass on
WLED_GLOBALdeclarations (see #5777-#5788, #5774/#12 for earlier ones).fsBytesUsed/fsBytesTotalare written and read byfile.cpp(viaupdateFSInfo()), and read-only fromjson.cpp(status report inserializeInfo()).Since
json.cppnever writes them, moved both to file-localstaticinfile.cppand exposed two by-value getters —getFsBytesUsed()/getFsBytesTotal()— instead of a mutable reference.This is deliberately narrower in scope than earlier Tier-2 work: only applied where the external file (
json.cpp) is genuinely read-only. Because the getters return by value, an accidental write fromjson.cpp(or any other file) is now a build error instead of a silent bug — a real, compiler-enforced improvement, not just a rename. Other Tier-2 candidates where the external file legitimately needs to write (e.g.loadLedmap,dnsServer) are being left as plain globals, since no accessor shape actually restricts a write in C++ without a real module/friend boundary — wrapping those would just relabel the same coupling.No behavior change — purely a storage/access-pattern change.
Test plan
esp32dev: builds and links cleanly viapio run -e esp32dev.usermodsenv (builds all 59 usermods): builds and links cleanly viapio run -e usermods.file.cpp.🤖 Generated with Claude Code