fix: resolve -1 sentinel collision for NV ops (-M, -C, -A)#87
fix: resolve -1 sentinel collision for NV ops (-M, -C, -A)#87Koan-Bot wants to merge 2 commits intocpan-authors:mainfrom
Conversation
|
@Koan-Bot rr |
PR Review — fix: resolve -1 sentinel collision for NV ops (-M, -C, -A)The approach of separating the status code from the NV value via a (status, value) pair is sound and correctly addresses the -1 sentinel collision. However, there are two bugs that need fixing before merge: (1) the 🔴 Blocking1. count corrupted before croak format string (`FileCheck.xs`, L160-163)The Save the original count before the loop: else {
int orig_count = count;
while (count-- > 0) (void)POPs;
croak("Overload::FileCheck::_check returned %d values for NV OP #%d, expected 1 or 2\n", orig_count, optype);
}🟡 Important1. Missing pTHX_ and dMY_CXT in _overload_ft_ops_nv (`FileCheck.xs`, L122)The existing 2. NV ops with falsy value (0.0) fall through to CHECK_IS_FALSE (`lib/Overload/FileCheck.pm`, L486-490)When the new The new 🟢 Suggestions1. Scalar ref from _check_from_stat masks the 0.0 issue (`lib/Overload/FileCheck.pm`, L476-490)When using 2. Missing test for -M returning 0.0The test file covers the -1.0 sentinel collision and FALLBACK, but does not test the edge case where a mock returns exactly Checklist
SummaryThe approach of separating the status code from the NV value via a (status, value) pair is sound and correctly addresses the -1 sentinel collision. However, there are two bugs that need fixing before merge: (1) the Automated review by Kōand435282 |
FALLBACK_TO_REAL_OP is -1, but -1.0 is a legitimate return value for -M/-C/-A (file modified exactly 1 day in the future). The XS handler pp_overload_ft_nv checked `SvNV(status) == -1` which silently fell back to the real OP instead of returning the mocked value. Fix: replace _overload_ft_ops_sv (G_SCALAR) with _overload_ft_ops_nv (G_ARRAY) that receives a (status, value) pair. The status code signals fallback/null/success without relying on the value itself. On the Perl side, _check_from_stat wraps NV results in scalar refs so _check() can distinguish real values from FALLBACK_TO_REAL_OP. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
view items are already addressed in the current code: - **pTHX_/dMY_CXT**: Already present at lines 134-135 ✓ - **NV block ordering**: `$OP_RETURNS_NV` check (line 489) is already before `!$out` check (line 501) ✓ Only the croak bug needed fixing. Here's the summary: - **Fixed `count` corruption in croak error message** (`FileCheck.xs`, `_overload_ft_ops_nv`): Saved original `count` to `orig_count` before the `while (count-- > 0)` drain loop, so the croak message reports the actual number of values returned instead of always printing `-1`. Per reviewer's blocking comment. - **pTHX_/dMY_CXT already present**: The current code already includes `pTHX_` in the function signature and `dMY_CXT` in the body (lines 134-135), so no change needed. - **NV block ordering already correct**: The `$OP_RETURNS_NV` block (line 489) is already placed before the `if ( !$out )` check (line 501) in the current code, so NV ops returning 0.0 are correctly handled without falling through to CHECK_IS_FALSE.
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
d435282 to
42b443b
Compare
What
Fix silent fallback for -M/-C/-A when the mocked value is exactly -1.0.
Why
FALLBACK_TO_REAL_OPis -1. For NV ops, -1.0 is a valid result (filemodified exactly 1 day in the future). The XS handler
pp_overload_ft_nvchecked
SvNV(status) == -1, causing any mocked file withmtime == basetime + 86400to silently fall back to the real OP — returningundef for a nonexistent path instead of the expected -1.0.
How
_overload_ft_ops_sv()(G_SCALAR, sentinel-based) with_overload_ft_ops_nv()(G_ARRAY) that receives a(status, value)pair.The status code (-1/fallback, -2/null, 1/success) is separate from the NV.
%OP_CAN_RETURN_INTinto int-only (s) and%OP_RETURNS_NV(M, C, A).
_check()returns(CHECK_IS_TRUE, $value)for NV ops._check_from_stat()wraps NV results in scalar refs to distinguish realvalues from
FALLBACK_TO_REAL_OP.Testing
t/nv-sentinel-collision.t— 6 subtests covering -M/-C/-A withmtime/atime/ctime at basetime+86400, FALLBACK for non-mocked files,
direct mock FALLBACK, and other NV value pass-through.
make testpasses (all existing tests + new test).🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 214 insertions(+), 35 deletions(-)
Code scan: clean
Tests: passed (0 Tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline