Skip to content

Commit 3ab01a2

Browse files
nobuXrXr
authored andcommitted
[Backport #21625] Allow io/wait methods with IO#ungetc in text mode
1 parent c26a2b1 commit 3ab01a2

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

ext/io/wait/wait.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ io_nread(VALUE io)
8484
ioctl_arg n;
8585

8686
GetOpenFile(io, fptr);
87-
rb_io_check_readable(fptr);
87+
rb_io_check_char_readable(fptr);
8888
len = rb_io_read_pending(fptr);
8989
if (len > 0) return INT2FIX(len);
9090

@@ -143,7 +143,7 @@ io_ready_p(VALUE io)
143143
#endif
144144

145145
GetOpenFile(io, fptr);
146-
rb_io_check_readable(fptr);
146+
rb_io_check_char_readable(fptr);
147147
if (rb_io_read_pending(fptr)) return Qtrue;
148148

149149
#ifndef HAVE_RB_IO_WAIT
@@ -178,7 +178,7 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
178178
#endif
179179

180180
GetOpenFile(io, fptr);
181-
rb_io_check_readable(fptr);
181+
rb_io_check_char_readable(fptr);
182182

183183
#ifndef HAVE_RB_IO_WAIT
184184
tv = get_timeout(argc, argv, &timerec);
@@ -252,7 +252,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io)
252252
rb_io_t *fptr = NULL;
253253

254254
RB_IO_POINTER(io, fptr);
255-
rb_io_check_readable(fptr);
255+
rb_io_check_char_readable(fptr);
256256

257257
if (rb_io_read_pending(fptr)) return Qtrue;
258258

io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9785,7 +9785,7 @@ io_wait_readable(int argc, VALUE *argv, VALUE io)
97859785
rb_io_t *fptr;
97869786

97879787
RB_IO_POINTER(io, fptr);
9788-
rb_io_check_readable(fptr);
9788+
rb_io_check_char_readable(fptr);
97899789

97909790
if (rb_io_read_pending(fptr)) return Qtrue;
97919791

@@ -9832,7 +9832,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io)
98329832
rb_io_t *fptr = NULL;
98339833

98349834
RB_IO_POINTER(io, fptr);
9835-
rb_io_check_readable(fptr);
9835+
rb_io_check_char_readable(fptr);
98369836

98379837
if (rb_io_read_pending(fptr)) return Qtrue;
98389838

test/io/wait/test_io_wait_uncommon.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22
require 'test/unit'
3+
require 'io/wait'
34

45
# test uncommon device types to check portability problems
56
# We may optimize IO#wait_*able for non-Linux kernels in the future
@@ -74,4 +75,33 @@ def test_wait_readable_zero
7475
def test_wait_writable_null
7576
check_dev(IO::NULL, :wait_writable)
7677
end
78+
79+
def test_after_ungetc_ready?
80+
check_dev(IO::NULL, mode: "r") {|fp|
81+
assert_respond_to fp, :ready?
82+
fp.ungetc(?a)
83+
assert_predicate fp, :ready?
84+
}
85+
end
86+
87+
def test_after_ungetc_wait_readable
88+
check_dev(IO::NULL, mode: "r") {|fp|
89+
fp.ungetc(?a)
90+
assert_predicate fp, :wait_readable
91+
}
92+
end
93+
94+
def test_after_ungetc_in_text_ready?
95+
check_dev(IO::NULL, mode: "rt") {|fp|
96+
fp.ungetc(?a)
97+
assert_predicate fp, :ready?
98+
}
99+
end
100+
101+
def test_after_ungetc_in_text_wait_readable
102+
check_dev(IO::NULL, mode: "rt") {|fp|
103+
fp.ungetc(?a)
104+
assert_predicate fp, :wait_readable
105+
}
106+
end
77107
end

0 commit comments

Comments
 (0)