#1212: .eof returns false if last read call read the last byte of the file, but
not beyond
----------------------+-----------------------------------------------------
Reporter: jonathan | Owner:
Type: RFC | Status: new
Priority: normal | Milestone:
Component: core | Version:
Severity: medium | Keywords:
Lang: | Patch:
Platform: |
----------------------+-----------------------------------------------------
Comment(by doughera):
Replying to [comment:7 cotto]:
> The original report from jnthn is confusing. I can see it being a
potential issue that fh.eof() returns *false* when there are 0 bytes left
in a file but a read hasn't returned fewer bytes than requested.
This is the documented and expected behavior of the C-level stdio function
feof(3). It's intended as an after-the-fact error status check after
you've hit the end of the file. (It is occasionally useful in
distinguishing among various error conditions that may cause an fread(3)
to return less than the asked-for number of bytes).
Perl 5 does implement the ungetc look-ahead trick in some circumstances,
but {{{ perldoc -f eof }}} also contains this hint:
Practical hint: you almost never need to use "eof" in Perl,
because the input operators typically return "undef" when they
run out of data, or if there was an error.
> Given that, I'd like to avoid trying to secretly read and unread an
extra character if we can make fh.eof do so reliably and portably. If
that's not an option, we should document the surprising behavior and give
HLLs the tools they need to do whatever makes sense for their users.
This ticket appears to request a predictive fh.eof() function that asks
what would happen if you tried to read another character, without actually
reading another character. I don't know how you could implement that
reliably and portably for all different types of inputs. I suppose one
could do it only on file handles that also advertise the .ungetc method,
but then the .eof function becomes even more magically erratic in its
actual behavior.
I think parrot should simply provide the fh.eof function that answers the
question of whether the previous read ran off the end of the file. The
HLL writer (or the end user) who has more context about the particular
input source in question may be able to provide something more predictive.
--
Ticket URL: <https://trac.parrot.org/parrot/ticket/1212#comment:8>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets