Misc #22230
openShould Ruby specs define byte oriented read behavior when the character buffer is not empty?
Description
In https://github.com/ruby/spec/pull/1384, there was a discussion regarding whether or not raising an IOError when performing a byte oriented read operation while the character buffer is nonempty should be part of the Ruby spec. @Eregon (Benoit Daloze) asked me to remove the new tests I was requesting to add and also remove existing tests that would define this behavior since it was unclear if the behavior in CRuby was an intentional design decision or a consequence of its specific implementation.
I intend to remove the tests in the above MR via a single commit that is easy to revert pending the outcome of this ticket as requested.
In all cases I tested, CRuby raises IOError for all byte oriented read operations whenever the character buffer is nonempty. IO.getc is used in all these cases to ensure that the character buffer has data in it, but it was argued that other implementations could instead make getc reverse the encoding conversion (if one is in play) and put the bytes into the byte buffer instead, eliminating the character buffer entirely. If that conversion would fail, getc could raise a conversion error of some kind and leave the buffer unchanged. It's unclear to me though if there are other ways that content could be left in the character buffer during normal read operations which would be harder to avoid while preserving performance and semantics.
CRuby's implementation appears to be consistent, so I don't think these tests are attempting to enforce buggy behavior. Should this behavior be codified as part of the spec, or should other implementations be free to behave differently?