fix: handle open(<&) dup mode on mocked filehandles - #424
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
open() with dup modes (<&, >&, <&=, >&=) on a mocked filehandle fell through to CORE::open, which failed with "Bad file descriptor" because mocked handles have synthetic filenos. Detect dup modes in __open and, when the source handle belongs to a mocked file, create a new tied handle that shares the same mock data. The duplicate inherits the source handle's access mode (r/w/a) and seek position, while maintaining an independent position pointer afterward — matching Perl's buffered-IO dup semantics. Non-mocked handles still fall through to CORE::open as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
open(my $dup, "<&", $fh)now works when$fhis a mocked filehandle.Why
Previously, dup modes (
<&,>&,<&=,>&=) fell through toCORE::open, whichfailed with "Bad file descriptor" because mocked handles have synthetic filenos
that don't correspond to real kernel file descriptors. Any code that dups a mocked
handle (common in IO redirection tests, logging, etc.) would crash.
How
Added early detection of dup modes in
__open. When the source handle belongs toa mocked file (found via
_fh_to_file), a new tiedFileHandleis created sharingthe same mock data. The duplicate inherits the source's access mode (r/w/a) and
current seek position. Non-mocked handles still fall through to
CORE::open.Testing
New
t/dup_handle.twith 6 subtests covering:<&) with position inheritance>&) with shared mock data+<source) with mode inheritance<&=)Full suite: 1592 tests pass (only pre-existing
fh-ref-leak.tfailure, unrelated).Quality Report
Changes: 2 files changed, 144 insertions(+)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan