Repository navigation
chore(api): take DiodeProfile by reference in set_input_gamut (#3234) - #3746
Conversation
Audit result: `profile` is required and mutated, so a nullable pointer advertised an optional argument that does not exist. Every call site already passed a real address (`©` internally, `&p` in tests) -- the `if (profile == nullptr) return;` was defensive, and silently doing nothing is a poor contract for "you gave me no profile to configure". Adds reference overloads as the preferred form. `white_xy` deliberately stays a POINTER. It is genuinely optional -- nullptr means "use the gamut's standard reference white" -- so the nullable pointer is telling the truth there. The point of this change is matching the shape to the semantics, not removing pointers on principle. Migration: the pointer overloads are kept, marked FL_DEPRECATED, forwarding to the reference forms. Sketches calling `set_input_gamut(&profile, ...)` keep compiling. The forwarders preserve the historical silent no-op on nullptr rather than dereferencing -- a sketch relying on that must not start crashing at the deprecation. Tests cover both: that the pointer and reference paths produce identical results, and that the null no-op still holds. Validation: bash test --cpp 357/357 (incl. all 730 examples linking, so the deprecation does not break example builds); bash lint green. Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe ChangesInput gamut API
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/fl/gfx/rgbw.h`:
- Around line 109-112: Replace the em dash in the deprecation comment above the
pointer overloads with ASCII punctuation such as "--" or "-"; keep the comment
text and behavior unchanged.
- Around line 106-107: Replace the decayed const float white_xy[2] parameter in
set_input_gamut’s declaration in src/fl/gfx/rgbw.h (lines 106-107) and its
implementation lambda in src/fl/gfx/rgbw.cpp.hpp (lines 246-250) with a nullable
extent-preserving representation that guarantees two floats when provided. Keep
the white override optional and update both sites consistently.
In `@tests/fl/gfx/rgbw_colorimetric.cpp`:
- Around line 419-435: Expand the assertions in the “set_input_gamut: deprecated
pointer overloads still work” test to compare both elements of all four
input_xy_r, input_xy_g, input_xy_b, and input_xy_w pairs between via_ptr and
via_ref, covering all eight mutated coordinates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 929a07b5-48cf-45c8-ad0b-d1e0ab089a7b
📒 Files selected for processing (3)
src/fl/gfx/rgbw.cpp.hppsrc/fl/gfx/rgbw.htests/fl/gfx/rgbw_colorimetric.cpp
| FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") { | ||
| // The pointer forms are kept so existing sketches calling | ||
| // set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must | ||
| // stay behaviourally identical to the reference forms. | ||
| DiodeProfile via_ptr = kRgbwDefaultProfile; | ||
| DiodeProfile via_ref = kRgbwDefaultProfile; | ||
|
|
||
| FL_DISABLE_WARNING_PUSH | ||
| FL_DISABLE_WARNING(deprecated-declarations) | ||
| set_input_gamut(&via_ptr, InputGamut::Rec2020); | ||
| FL_DISABLE_WARNING_POP | ||
| set_input_gamut(via_ref, InputGamut::Rec2020); | ||
|
|
||
| FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f); | ||
| FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f); | ||
| FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Compare all mutated coordinates in the compatibility test.
Only 3 of the 8 input_xy_* floats are checked, so a forwarding regression in any omitted coordinate can pass unnoticed. Compare both elements of all four R/G/B/W pairs.
Example additions
+ FL_CHECK_CLOSE(via_ptr.input_xy_r[1], via_ref.input_xy_r[1], 1e-9f);
+ FL_CHECK_CLOSE(via_ptr.input_xy_g[0], via_ref.input_xy_g[0], 1e-9f);
+ FL_CHECK_CLOSE(via_ptr.input_xy_b[0], via_ref.input_xy_b[0], 1e-9f);
+ FL_CHECK_CLOSE(via_ptr.input_xy_b[1], via_ref.input_xy_b[1], 1e-9f);
+ FL_CHECK_CLOSE(via_ptr.input_xy_w[1], via_ref.input_xy_w[1], 1e-9f);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") { | |
| // The pointer forms are kept so existing sketches calling | |
| // set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must | |
| // stay behaviourally identical to the reference forms. | |
| DiodeProfile via_ptr = kRgbwDefaultProfile; | |
| DiodeProfile via_ref = kRgbwDefaultProfile; | |
| FL_DISABLE_WARNING_PUSH | |
| FL_DISABLE_WARNING(deprecated-declarations) | |
| set_input_gamut(&via_ptr, InputGamut::Rec2020); | |
| FL_DISABLE_WARNING_POP | |
| set_input_gamut(via_ref, InputGamut::Rec2020); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f); | |
| } | |
| FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") { | |
| // The pointer forms are kept so existing sketches calling | |
| // set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must | |
| // stay behaviourally identical to the reference forms. | |
| DiodeProfile via_ptr = kRgbwDefaultProfile; | |
| DiodeProfile via_ref = kRgbwDefaultProfile; | |
| FL_DISABLE_WARNING_PUSH | |
| FL_DISABLE_WARNING(deprecated-declarations) | |
| set_input_gamut(&via_ptr, InputGamut::Rec2020); | |
| FL_DISABLE_WARNING_POP | |
| set_input_gamut(via_ref, InputGamut::Rec2020); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_r[1], via_ref.input_xy_r[1], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_g[0], via_ref.input_xy_g[0], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_b[0], via_ref.input_xy_b[0], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_b[1], via_ref.input_xy_b[1], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f); | |
| FL_CHECK_CLOSE(via_ptr.input_xy_w[1], via_ref.input_xy_w[1], 1e-9f); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/fl/gfx/rgbw_colorimetric.cpp` around lines 419 - 435, Expand the
assertions in the “set_input_gamut: deprecated pointer overloads still work”
test to compare both elements of all four input_xy_r, input_xy_g, input_xy_b,
and input_xy_w pairs between via_ptr and via_ref, covering all eight mutated
coordinates.
- Spell the optional white-point override `const float*` instead of `const float[2]`. The array extent decayed to a pointer anyway, so it was an unenforced promise, and ci/tools/check_array_params.py bans the spelling. Nullability is the real contract, so the pointer now says what it means. - Replace a non-ASCII em dash in the deprecation comment (7-bit ASCII rule). - Compare all eight mutated coordinates in the pointer/reference equivalence test instead of a 3-coordinate sample, and add a case covering the 3-argument forwarder so a dropped white_xy is caught. Co-Authored-By: Claude <[email protected]>
|
All three addressed in 5f6f7dd. 1. Decayed You were right that the extent was a false promise, and this repo actually has an explicit ratchet for it ( I didn't use a span/extent-preserving type, because that can't express the contract: The ratchet bans the misleading array spelling, not pointers — so I left the lambda parameters alone: 2. Em dash — fixed. Replaced with 3. Partial assertions — fixed. All eight coordinates now compared, plus a new case for the 3-argument forwarder, which had an extra argument to lose and no equivalence coverage at all. Unrelated bug found while verifying this, being fixed separately: Validated: 357/357 with all examples linking, |
Summary
Closes #3234.
Audit result:
profileis required and mutated, so the nullable pointer advertised an optional argument that doesn't exist. Every call site already passed a real address (©internally,&pthroughout the tests) — theif (profile == nullptr) return;was defensive, not a contract. And silently doing nothing is a poor answer to "you gave me no profile to configure": the caller gets no gamut applied and no signal.So
DiodeProfile*→DiodeProfile&.What deliberately did not change
white_xystays a pointer. It is genuinely optional —nullptrmeans "use the gamut's standard reference white" — so the nullable pointer is telling the truth there. The goal is matching the shape to the semantics, not removing pointers on principle.Answering the issue's questions directly:
nullptran intentional contract?DiodeProfile&?const DiodeProfile&?Migration — no sketch breaks
The pointer overloads are kept and marked
FL_DEPRECATED, forwarding to the reference forms. Existingset_input_gamut(&profile, ...)calls keep compiling and get a pointed deprecation message.The forwarders preserve the silent no-op on
nullptrrather than dereferencing. A sketch that relied on that behaviour must not start crashing at the moment we deprecate it — the deprecation is the signal, not a segfault.Testing
bash test --cpp— 357/357, including all 730 examples linking, so the new deprecation doesn't break example buildsbash lint— greenBoth use
FL_DISABLE_WARNING(deprecated-declarations)locally so exercising the deprecated path doesn't add warning noise.🤖 Generated with Claude Code
Summary by CodeRabbit