[Bug:trunk] readpartial after ungetc fails with text mode

e$B1sF#$G$9!#e(B

e$B0J2<$N$h$&$K$9$k$H!“e(B"a” e$B$,=PNO$5$l$k$3$H$r4|BT$9$k$N$G$9$,!"e(B
EOFError e$B$K$J$j$^$9!#e(B

$ echo -n a > foo.txt && ./ruby -e ’
open(“foo.txt”, “r+t”) do |f|
f.ungetc(f.getc)
p f.readpartial(2)
end

-e:4:in readpartial': end of file reached (EOFError) from -e:4:inblock in ’
from -e:2:in open' from -e:2:in

mingw32 e$B$G$Ne(B rubyspec e$B$,$3$N$;$$$G8G$^$k$h$&$G$9e(B (mingw32
[email protected]$He(B “r+” [email protected]$1$GLdBj$K$J$ke(B) e$B!#e(B

e$B$3$&$$$&E?Kv$_$?$$$G$9!#e(B

  1. text mode [email protected]$He(B ungetc e$B$,e(B rbuf e$B$G$J$/e(B cbuf
    e$B$K5-O?$9$ke(B
  2. readpartial e$B$Oe(B rbuf e$B$7$+8+$J$$e(B

readpartial e$B$,e(B cbuf e$B$b8+$k$Y$-$J$s$G$9$+$M!#e(B

e$B$3$l$Oe(B akr [email protected]@%$5$s$NC4Ev$G$$$$$G$7$g$&$+!#e(B

2010e$BG/e(B2e$B7ne(B26e$BF|e(B19:34 Yusuke ENDOH [email protected]:

  1. text mode [email protected]$He(B ungetc e$B$,e(B rbuf e$B$G$J$/e(B cbuf e$B$K5-O?$9$ke(B
  2. readpartial e$B$Oe(B rbuf e$B$7$+8+$J$$e(B

readpartial e$B$,e(B cbuf e$B$b8+$k$Y$-$J$s$G$9$+$M!#e(B

e$B$$$$$(!#e(B

cbuf e$B$OJ8;z%3!<%IJQ49:Q$$N%G!<%?$rCy$a$F$*$/>l=j$G$"$j!"e(B
readpartial e$B$OJQ49A0$N%P%$%HNs$rFI$
=P$9%a%=%C%I$J$N$G!"e(B
cbuf e$B$rFI$^[email protected]$7$$F0:n$G$9!#e(B

cbuf e$B$,6u$G$J$1$l$PNc30$K$9$k$H$$$&A*Br;h$O$"$j$($^$9!#e(B

2010e$BG/e(B2e$B7ne(B26e$BF|e(B20:19 Yusuke ENDOH [email protected]:

e$B$$$$$(!#e(B
e$B%P%C%U%!%j%s%0$7$F$$$k$H$+%f!<%6$,5$$K$7$J$/$F$b$$$$$h$&$K$J$i$J$$e(B
e$B$b$N$+$J$"!#e(B

e$B$3$NLdBj$,I=LL2=$9$k$N$Oe(Bungetc()[email protected]$1$J$N$G!"%P%C%U%!$,#2$D$"$k$H$$$&<BAu$r=q$/I,MW$O$J$/$Fe(B
ungetc()e$B$N%a%=%C%[email protected]@$K%P%$%J%jFI$9~$$HAH$_9g$o$;[email protected]$h!#$He(B
e$BDI5-$9$l$P:Q$`OC$G$O$J$$$+$J$!e(B

e$B8=<[email protected]$3&$G!"$=$&$$$&MWK>$O$3$J$5$=$&[email protected]$7!#e(B

e$B1sF#$G$9!#e(B

2010e$BG/e(B2e$B7ne(B26e$BF|e(B19:42 Tanaka A. [email protected]:

readpartial e$B$OJQ49A0$N%P%$%HNs$rFI$_=P$9%a%=%C%I$J$N$G!"e(B
cbuf e$B$rFI$^[email protected]$7$$F0:n$G$9!#e(B

e$B$&$&!"e(B1.9 e$B$Ne(B IO e$B$OK\Ev$KFq$7$$$G$9$M!#e(B

IO#readpartial e$B$He(B ungetc e$B$Ne(B rdoc e$B$r$Q$C$H8+$F$be(B
“buffer” e$B$N<oN`$,e(B
e$BJ#?t$"$k$H$OFI$_<h$l$J$+$C$?$N$G$9$,!"$I$3$+$K=q$$$F$"$k$3$H$G$9$+!)e(B
e$B%P%C%U%!%j%s%0$7$F$$$k$H$+%f!<%6$,5$$K$7$J$/$F$b$$$$$h$&$K$J$i$J$$e(B
e$B$b$N$+$J$"!#e(B

e$B$H$j$"$($:!"e(BRubySpec e$BB&$Ge(B pipe e$B$re(B binmode
e$B$K$7$F$7$N$.$^$9!#e(B

2010e$BG/e(B2e$B7ne(B26e$BF|e(B22:06 KOSAKI Motohiro
[email protected]:

e$B$3$NLdBj$,I=LL2=$9$k$N$Oe(Bungetc()[email protected]$1$J$N$G!"%P%C%U%!$,#2$D$"$k$H$$$&<BAu$r=q$/I,MW$O$J$/$Fe(B
ungetc()e$B$N%a%=%C%[email protected]@$K%P%$%J%jFI$9~$$HAH$_9g$o$;[email protected]$h!#$He(B
e$BDI5-$9$l$P:Q$`OC$G$O$J$$$+$J$!e(B

e$B%3!<%IJQ49$,$$$A$I$KJ#?tJ8;[email protected]@.$7$?$H$-!"e(B
e$BFI$9~$%a%=%C%I$,$=$l$i$r$9$Y$F$O>CHq$;$:!"e(B
e$B0lIt$re(B cbuf e$B$K;[email protected]$,9M$($i$l$^$9!#e(B

e$B8=;[email protected]$G6qBNE*$K$"$k$+$H$$$&$He(B LF -> CR LF
e$BJQ49$rFI$_=P$7B&$G9T$&$H$+e(B
e$B$+$J$j$`$j$d$j$JNc$7$+;W$$$D$+$J$$$s$G$9$,!"e(B
e$B$$$A$*$&!“e(BUnicode e$B$Ne(B normalization
e$B$J$IA[Dj$5$l$kMQES$O$”$j$^$9!#e(B

2010e$BG/e(B2e$B7ne(B26e$BF|e(B20:19 Yusuke ENDOH [email protected]:

IO#readpartial e$B$He(B ungetc e$B$Ne(B rdoc e$B$r$Q$C$H8+$F$be(B “buffer” e$B$N<oN`$,e(B
e$BJ#?t$"$k$H$OFI$_<h$l$J$+$C$?$N$G$9$,!"$I$3$+$K=q$$$F$"$k$3$H$G$9$+!)e(B

readpartial e$B$H$$$&$h$j$O!"%P%$%HC10L$N%5%$%:$r;XDj$9$k%a%=%C%I$Oe(B
e$B4pK\E*$K%P%$%HNs%l%Y%k$GF0:n$9$k$H$$$&!"$h$j0lHLE*$JOC$J$s$G$9$,!“e(B
e$B=q$$$F$”$C$?$+$J$!!#e(B

e$B%P%C%U%!%j%s%0$7$F$$$k$H$+%f!<%6$,5$$K$7$J$/$F$b$$$$$h$&$K$J$i$J$$e(B
e$B$b$N$+$J$"!#e(B

e$B$=$N$3$H<+BN$ONI$$$H;W$&$N$G!"$=$N$?$a$K$G$-$k$3$H$r;W$$$D$$$F!“e(B
e$B32$,L5$1$l$P!”<BAu$7$FF~$l$F$$$/$N$,$$$$$s$8$c$J$$$G$9$+$M!#e(B

e$B40`z$K$d$k$N$OL5M}[email protected]$H;W$&$s$G$9$,!#e(B

2010e$BG/e(B2e$B7ne(B27e$BF|e(B0:10 Tanaka A. [email protected]:

2010e$BG/e(B2e$B7ne(B26e$BF|e(B20:19 Yusuke ENDOH [email protected]:

IO#readpartial e$B$He(B ungetc e$B$Ne(B rdoc e$B$r$Q$C$H8+$F$be(B “buffer” e$B$N<oN`$,e(B
e$BJ#?t$"$k$H$OFI$_<h$l$J$+$C$?$N$G$9$,!"$I$3$+$K=q$$$F$"$k$3$H$G$9$+!)e(B

readpartial e$B$H$$$&$h$j$O!"%P%$%HC10L$N%5%$%:$r;XDj$9$k%a%=%C%I$Oe(B
e$B4pK\E*$K%P%$%HNs%l%Y%k$GF0:n$9$k$H$$$&!"$h$j0lHLE*$JOC$J$s$G$9$,!“e(B
e$B=q$$$F$”$C$?$+$J$!!#e(B

http://doc.okkez.net/static/191/class/IO.html

e$B$N!V%(%s%3!<%G%#%s%0$N1F6A$r<u$1$k%a%=%C%I$H<u$1$J$$%a%=%C%I!W$KJ,N`$,=q$$$F$"$k$N$G$9$,!“e(B
ungetc()e$B$N$h$&$J%P%$%J%jFI$9~$%a%=%C%I$KBP$7$FI{:nMQ$,$”$k%a%=%C%IB&$K!"$=$N;]$Ne(B
e$B5-:$,$J$$$N$,LdBj$H$$$&G’<1$G$$$k$N$G$9$,!&!&!&e(B

e$B%A%1%C%He(B #2795 e$B$,99?7$5$l$^$7$?!#e(B (by Akira T.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

This issue was solved with changeset r27470.
Yusuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


http://redmine.ruby-lang.org/issues/show/2795

e$B%A%1%C%He(B #2795 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$BC4Ev<Te(B Akira T.e$B$K%;%C%He(B
Target version 1.9.2e$B$K%;%C%He(B
ruby -v ruby 1.9.2dev (2010-04-20 trunk 27405)
[i686-linux]e$B$K%;%C%He(B

akr e$B$5$se(B
e$B1sF#$G$9!#e(B

e$B$3$N5sF0$Oe(B by design e$B$H$$$&$3$H$G$9$,!"e(BIO#ungetc e$B$Ne(B
rdoc e$B$Ke(B

Pushes back one character (passed as a parameter) onto ios,
such that a subsequent buffered read will return it.

e$B$H=q$$$F$"$j!"$+$De(B IO#readpartial e$B$Ne(B rdoc e$B$Ke(B

If the buffer is not empty, read from the buffer instead of
“sysread for buffered IO (IOError)”.

e$B$H=q$$$F$"$k$N$G!“e(Brdoc
e$B$,4V0c$C$F$$$k$+!”$^$?$OHs>o$K$o$+$j$K$/$$e(B
e$B$H;W$$$^$9!#e(B

IO e$B$Ne(B rdoc e$B$K$O<j$,=P$;$J$$e(B (e$B;EMM$Oe(B akr
e$B$5$s$NF,$NCf$K$7$+$J$$e(B
e$B$h$&$J5$$,$9$ke(B) e$B$N$G!"[email protected][email protected]$1$^$;$s$G$7$g$&$+!#e(B
[email protected]$r0J$F$3$N%A%1%C%H$rJD$8$k!"$H$$$&$3$H$G$I$&$G$7$g$&!#e(B


Yusuke E. [email protected]

http://redmine.ruby-lang.org/issues/show/2795

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs