Issue #22230 has been updated by matz (Yukihiro Matsumoto). Please leave this implementation defined. Other implementations should be free to behave differently. [#note-1](https://bugs.ruby-lang.org/issues/22230#note-1) makes the case well. The `IOError` is a consequence of CRuby having a character buffer and avoiding the reverse conversion back to bytes, not a decision about what the language promises. An implementation that converts back in `getc` and keeps no character buffer at all would have no reason to raise here, and I do not want to force it to emulate a buffer it does not have. CRuby is not even consistent with itself: after `ungetc`, byte reads work when no converter is in play and fail when one is. That is not a rule to hold every implementation to. Matz. ---------------------------------------- Misc #22230: Should Ruby specs define byte oriented read behavior when the character buffer is not empty? https://bugs.ruby-lang.org/issues/22230#change-118424 * Author: javanthropus (Jeremy Bopp) * Status: Open ---------------------------------------- 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 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? -- https://bugs.ruby-lang.org/