Skip to content

fix: PRINT/PRINTF return false when weakened data ref is gone#283

Merged
toddr merged 2 commits intocpanel:masterfrom
atoomic:koan.atoomic/fix-print-printf-weakref-return
Mar 20, 2026
Merged

fix: PRINT/PRINTF return false when weakened data ref is gone#283
toddr merged 2 commits intocpanel:masterfrom
atoomic:koan.atoomic/fix-print-printf-weakref-return

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 3, 2026

What

PRINT and PRINTF now check _write_bytes() return value instead of unconditionally returning 1.

Why

When a mock is destroyed while a filehandle is still open, the weakened data ref becomes undef. _write_bytes() correctly returns 0 with $! = EBADF in this case, but PRINT/PRINTF ignored the failure and returned 1 (success). WRITE already handled this correctly — this aligns PRINT/PRINTF with the same pattern.

How

  • Check _write_bytes() return; only call _update_write_times() when bytes were written
  • Return $bytes ? 1 : 0 to match PRINT/PRINTF's boolean contract (vs WRITE's byte-count contract)
  • Added tests for both print and printf after mock destruction, verifying false return and EBADF errno

Testing

  • Updated t/filehandle_weakref.t: existing print subtest now asserts return value and errno; new printf subtest added

🤖 Generated with Claude Code

@toddr
Copy link
Member

toddr commented Mar 19, 2026

@Koan-Bot rebase

@toddr toddr marked this pull request as ready for review March 19, 2026 05:34
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-print-printf-weakref-return branch from 8f731bc to 4e1d20b Compare March 19, 2026 15:23
Koan-Bot added a commit to atoomic/Test-MockFile that referenced this pull request Mar 19, 2026
@Koan-Bot
Copy link
Contributor Author

Rebase: fix: PRINT/PRINTF return false when weakened data ref is gone

Branch koan.atoomic/fix-print-printf-weakref-return rebased onto master and force-pushed.

Diff: 2 files changed, 29 insertions(+), 12 deletions(-)

Review feedback was analyzed and applied.

Actions

  • Rebased koan.atoomic/fix-print-printf-weakref-return onto upstream/master
  • Force-pushed koan.atoomic/fix-print-printf-weakref-return to origin
  • CI failed (attempt 1)
  • Applied CI fix (attempt 1)
  • Pushed CI fix (attempt 1)
  • CI passed after fix attempt 1

CI

CI failed initially, fixed on attempt 1.


Automated by Kōan

@toddr
Copy link
Member

toddr commented Mar 20, 2026

@Koan-Bot rebase

Koan-Bot added a commit to atoomic/Test-MockFile that referenced this pull request Mar 20, 2026
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-print-printf-weakref-return branch from a20121f to 299fd5b Compare March 20, 2026 20:36
@Koan-Bot
Copy link
Contributor Author

Rebase: fix: PRINT/PRINTF return false when weakened data ref is gone

Branch koan.atoomic/fix-print-printf-weakref-return rebased onto master and force-pushed.

Diff: 2 files changed, 37 insertions(+), 10 deletions(-)

Review feedback was analyzed and applied.

Actions

  • Rebased koan.atoomic/fix-print-printf-weakref-return onto upstream/master
  • Force-pushed koan.atoomic/fix-print-printf-weakref-return to origin
  • CI passed

CI

CI passed.


Automated by Kōan

@toddr
Copy link
Member

toddr commented Mar 20, 2026

@Koan-Bot rebase

Koan-Bot and others added 2 commits March 20, 2026 16:12
PRINT and PRINTF always returned 1 (success) even when _write_bytes()
failed because the mock was destroyed and the weakened data ref became
undef. WRITE already handled this correctly by checking the return
value. Apply the same pattern to PRINT and PRINTF for consistency.

Also skips _update_write_times() when no bytes were written, matching
WRITE's existing behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-print-printf-weakref-return branch from 299fd5b to 6bc2967 Compare March 20, 2026 22:14
@Koan-Bot
Copy link
Contributor Author

Rebase: fix: PRINT/PRINTF return false when weakened data ref is gone

Branch koan.atoomic/fix-print-printf-weakref-return rebased onto master and force-pushed.

Diff: 2 files changed, 37 insertions(+), 10 deletions(-)

Review feedback was analyzed and applied.

Actions

  • Rebased koan.atoomic/fix-print-printf-weakref-return onto upstream/master
  • Force-pushed koan.atoomic/fix-print-printf-weakref-return to origin
  • CI passed

CI

CI passed.


Automated by Kōan

@toddr toddr merged commit 5305a82 into cpanel:master Mar 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants