fix(sysseek): return new file position instead of success flag#528
Merged
fix(sysseek): return new file position instead of success flag#528
Conversation
sysseek was aliased to seek, which returns 1 on success. Perl's sysseek is documented to return the new position (with "0 but true" for position 0). File::Tail relies on sysseek($fh, 0, SEEK_END) to detect new data; with the old behavior it always saw endpos=1 and its polling loop hung forever. Gave sysseek its own implementation in IOOperator (seek + tell, mapping position 0 to "0 but true") and updated OperatorHandler to dispatch "sysseek" to the new method. Verified with jcpan -t File::Tail (Files=3, Tests=15, Result: PASS). Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Summary
Fixes
jcpan -t File::Tail, which hung forever during its test suite.Root cause
sysseekwas aliased toseek, which returns1on success. Perl'ssysseekis documented to return the new file position (with the special"0 but true"dualvar for position 0).File::Tail::checkpendingusessysseek($fh, 0, SEEK_END)to detect new data at the tail of the file. With the old behaviorendposalways came back as1, soendpos - curpos == 0and the polling loop inFile::Tail::readnever made progress.Minimal repro (before fix):
Fix
sysseek(RuntimeScalar, RuntimeList)inIOOperatorthat performs the seek, then returns the new position viatell, mapping position 0 to the"0 but true"string.OperatorHandlersosysseekdispatches to the new method instead of reusingseek.(int ctx, RuntimeBase...)adapter used byMiscOpcodeHandleraccordingly.Test plan
./jperlround-trip ofsysseekwith all whence values returns correct positions (including"0 but true"for position 0).jcpan -t File::Tailnow reportsFiles=3, Tests=15, Result: PASS.make(full unit test suite) passes.Generated with Devin