Bug #21625
closedAllow IO#wait_readable together with IO#ungetc even in text mode
Description
Background¶
IO#wait_readable calles rb_io_check_byte_readable() in that C implementation, so that is treated as binary reading class operation.
open(IO::NULL, "rt") { |f| f.ungetc(?a); f.wait_readable }
# => in 'IO#wait_readable': byte oriented read for character buffered IO (IOError)
This is inconsistent with the behavior of IO#select.
open(IO::NULL, "rt") { |f| f.ungetc(?a); IO.select([f]) }
# => [[#<File:NUL (closed)>], [], []]
Proposal¶
Change IO#wait_readable into character reading class function.
This allows mixing usage of IO#wait_readable and IO#ungetc.
This change avoids the IOError that previously occurred, but in that case,
an exception is thrown when the binary read method is subsequently called.
Overall behavior remains unchanged, but exceptions will occur at more desirable locations.
If the method being called next is a character method, no exception will be thrown.
But that is the desired behavior.
related methods¶
IO#io_wait_priority may apply similar changes for consistency.
IO#ready? seems to have the same issue. This is in the io-wait default gem.
IO#wait already respects the character read buffer.
        
           Updated by nobu (Nobuyoshi Nakada) 3 days ago
          Updated by nobu (Nobuyoshi Nakada) 3 days ago
          
          
        
        
      
      - Subject changed from Allow IO#wait_readable together with IO#ungetc to Allow IO#wait_readable together with IO#ungetc even in text mode
- Backport set to 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED
- Tracker changed from Feature to Bug
        
           Updated by nobu (Nobuyoshi Nakada) 2 days ago
          Updated by nobu (Nobuyoshi Nakada) 2 days ago
          
          
        
        
      
      
    
        
           Updated by nobu (Nobuyoshi Nakada) 2 days ago
          Updated by nobu (Nobuyoshi Nakada) 2 days ago
          
          
        
        
      
      - Status changed from Open to Closed
Applied in changeset git|12350eb9e0d3317da57b5a37c0c2810946b48850.
[Bug #21625] Allow io/wait methods with IO#ungetc in text mode