[Bug #1582] IO.new Raises Other Errors between 1.8 and 1.9


#1

Bug #1582: IO.new Raises Other Errors between 1.8 and 1.9
http://redmine.ruby-lang.org/issues/show/1582

e$B5/I<<Te(B: ujihisa .
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2009-06-05 trunk 23641) [i386-darwin9.7.0]

IO.newe$B$G0z?t$KM?$($?%U%!%$%k5-=R;R$N%U%!%$%k%b!<%I$H8_49@-$N$J$$%U%!%$%k%b!<%I$rM?$($?$H$-!"e(Bruby
1.8e$B7O$G$Oe(BErrno::EINVALe$B$rEj$2$k$N$KBP$7!“e(Bruby
1.9e$B7O$G$ONc30$rEj$2$:!”<B:]$K8_49@-$N$J$$9T0Y$r<B9T$7$?$H$-$Ke(BErrno::EBADFe$B$rEj$2$^$9!#e(B

io = File.open('aaa.txt', 'w')
io2 = IO.new(io.fileno, 'r') # 1.8e$B$G$O$3$N;~E@$Ge(BErrno::EINVAL

io.syswrite '111'
puts io2.read # 1.9e$B$G$O$3$N;~E@$Ge(BErrno::EBADF

e$B;d$K$Oe(Bruby
1.8e$B7O$N5sF0$NJ}$,?4M%$7$$5$$,$9$k$N$G$9$,!"$I$&$G$7$g$&!#E:IU$N%Q%C%A$rE,MQ$9$k$H!"e(B1.9e$B$G$be(BIO.newe$B$N;~E@$Ge(BErrno::EINVALe$B$rEj$2$k$h$&$K$J$j$^$9!#e(B


#2

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

32bit Solaris e$B$Ne(B FILE e$B9=B$BN$Oe(B fd e$B$,e(B 1byte
e$B$GI=8=$5$l$F$$$k$?$a!"e(Brb_fdopen e$B$Ge(B
FILEe$B9=B$BN$r@8@.$9$k$H!"e(B256e$B0J>e$Ne(B fd
e$B$r07$($J$/$J$j$^$9!#e(B


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


#3

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

e$B$H$9$k$H$3$N%Q%C%A$N;29M85$N!"e(Bruby1.8e$B7O$Ne(Bio.ce$B$Ne(Brb_io_initialize()e$B$Ge(Brb_fdopen()e$B$r8F$S=P$7$F$$$kItJ,$,5$$K$J$j$^$9!#e(B

ruby_1_8_7/io.c r23641 line4366
fp->f = rb_fdopen(fd, rb_io_modenum_mode(flags));

e$B$[$+$K$bB??t!#e(B

e$B$$$C$]$&e(Bruby1.9e$B7O$G$9$He(Brb_io_stdio_file()e$B$GF1MM$Ke(B

trunk/io.c r23641 line5993
fptr->stdio_file = rb_fdopen(fptr->fd,
rb_io_oflags_modestr(oflags));

e$B$He(Brb_fdopen()e$B$,8F$P$l$F$$$k$b$N$N!"$3$3$G$Oe(Bstdin, stdout,
stderre$B$7$+M?$($i$l$J$$$H2>Dj$7$F$$$k$?$ae(BSolarise$B$G$bBg>fIW!"$H$=$s$JIw$K8+$($^$9!#e(B

e$B<j85$Ke(B32bit
Solarise$B$,$J$/$F;n$9$3$H$,$G$-$:?4$b$H$J$$$G$9$,!"Js9p$^$G$K!#e(B

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


#4

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

e$B$=$N$H$*$j$G!"e(B1.8 e$B$G$OF0$-$^$;$s!#e(B

1.9
e$B$G$OF0$/$h$&$K$7$?$N$G!"$=$l$rF0$+$J$$$h$&$K$9$k$N$O<u$1F~$l$i$l$^$;$s!#e(B

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


#5

e$B%A%1%C%He(B #1582 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BRejectede$B$KJQ99e(B

e$BK\7o$Oe(Brejecte$B$H$$$&$3$H$GNI$$$G$7$g$&$+e(B?

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


#6

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

e$B%9%F!<%?%9e(B Closede$B$+$ie(BOpene$B$KJQ99e(B

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

e$B$J$+$@$5$s$N=$@5$Ke(B regression e$B$,$"$k$_$?$$$G$9!#e(B
e$B$$$^$+$ie(B kosaki e$B$5$s$,>:Y$r=q$$$F$/$l$^$9!#e(B


Yusuke E. removed_email_address@domain.invalid

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


#7

e$B%A%1%C%He(B #1582 e$B$,99?7$5$l$^$7$?!#e(B (by Nobuyoshi N.)

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

Applied in changeset r24102.

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


#8

e$B$J$+$@$G$9!#e(B

At Sat, 27 Feb 2010 01:45:54 +0900,
Motohiro KOSAKI wrote in [ruby-dev:40509]:

    from -e:1:in `<main>'

1.8e$B$^$G$HF0:n$r9g$o$;$F$"$j$^$9!#e(B

http://doc.okkez.net/static/191/class/IO.html e$B$r$_$k$He(B

new(fd, mode = “r”) -> IO

1.9e$B$Ne(Brdoce$B$G$Oe(Bmodee$B$N%G%U%)%k%HCM$K$D$$$F$N5-=R$O:o$i$l$F$$$^$9!#e(B

e$B$3$l$O0U?^E*$G$7$g$&$+!)0U?^$7$?$b$N$G$"$k>l9g!"%I%-%e%a%s%H$N=$@5$r$48!F$$/$@$5$$$^$;e(B

1.8e$B$^$G$N%I%-%e%a%s%H$N%P%0$@$H;W$$$^$9!#e(B


#9

2010e$BG/e(B2e$B7ne(B27e$BF|e(B9:43 Nobuyoshi N.
removed_email_address@domain.invalid:

1.9e$B$Ne(Brdoce$B$G$Oe(Bmodee$B$N%G%U%)%k%HCM$K$D$$$F$N5-=R$O:o$i$l$F$$$^$9!#e(B

e$B>e5-e(BURLe$B$O$$$A$*$&e(B1.9.1e$BMQ$N$O$:$J$s$G$9$,!“C/$,=$@5C4Ev$J$s$G$7$g$&!)!)e(B
e$B$”$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’
-e:1:in gets': not opened for reading (IOError) from -e:1:in

% ./ruby -e ‘f1 = File.open(“foo.txt”, “w”); f1.puts “foo”; f2 =
IO.new(f1.fi
leno, “r”); p f2.gets’
-e:1:in initialize': Invalid argument (Errno::EINVAL) from -e:1:innew’
from -e:1:in `’

http://doc.okkez.net/static/191/class/IO.html e$B$r$_$k$He(B

new(fd, mode = “r”) -> IO

e$B$H=q$$$F$"$k$N$G!“e(BIO.new()e$B$Ne(Bmodee$B0z?t$N%G%U%)%k%H$Oe(B"r"e$B$N$O$:$G!”$3$l$OJQ$G$9!#e(B
e$B$=$N%+%i%/%j$G$9$,!"e(B

rb_io_initialize e$B$Ge(B
#if defined(HAVE_FCNTL) && defined(F_GETFL)
oflags = fcntl(fd, F_GETFL);
(snip)
ofmode = rb_io_oflags_fmode(oflags);
if (NIL_P(vmode)) {
fmode = ofmode;
}

e$B$H$$$&%3!<%I$,$"$k$?$a$K!“0z?t$J$7$N;~$Oe(Bfde$B0z?t$N%”%/%;%98"$r7Q>5$9$k;EMM$KJQ$o$C$F$7$^$C$F$$$^$9!#e(B
e$B%j%U%!%l%s%9$,@5$7$$$J$i!"e(Bmodee$B0z?t$r>JN,$7$?$H$-$bC1$Ke(B"r"e$B$H2r<a$7$Fe(BEINVALe$B$K$J$k$Y$-$K8+$($^$9!#e(B

e$B$3$l$O0U?^E*$G$7$g$&$+!)0U?^$7$?$b$N$G$"$k>l9g!"%I%-%e%a%s%H$N=$@5$r$48!F$$/$@$5$$$^$;e(B


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


#11

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

From: KOSAKI Motohiro <kosaki.motohiro_at_gmail.com>
Date: Sat, 27 Feb 2010 12:07:11 +0900

http://doc.okkez.net/static/191/class/IO.html e$B$r$_$k$He(B

new(fd, mode = “r”) -> IO

1.9e$B$Ne(Brdoce$B$G$Oe(Bmodee$B$N%G%U%)%k%HCM$K$D$$$F$N5-=R$O:o$i$l$F$$$^$9!#e(B

e$B>e5-e(BUR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reference-manual/msg/360
  2. http://redmine.ruby-lang.org/repositories/diff/rurema?rev=3924

e$B3NG’$7$^$7$?!#e(B

e$B%(%s%I%f!<%6$O<+J,$N4D6-$,e(Bfcntle$B$,MxMQ$G$-$k4D6-$+$I$&$+CN$C$F$$$k$N$@$m$&$+!)e(B
e$B$HAGKQ$J5?Ld$,$o$-$^$7$?!#e(B
e$B$^$C$?$/J,$+$C$F$J$/$F62=L$J$N$G$9$,!"%j%U%!%l%s%9$N=,47E*$K$O!Ve(Bxxe$B$,MxMQ$G$-$k4D6-!We(B
e$B$H$$$&I=5-$H!Ve(BWindowse$B4D6-$G$O!W$H$$$&I=5-$N$I$A$i$,0lHLE*$J$N$G$7$g$&$+!#e(B
e$BA0<T$N>l9g!"$J$K$bLdBj$J$$$H;W$$$^$9!#e(B


#14

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

From: KOSAKI Motohiro <kosaki.motohiro_at_jp.fujitsu.com>
Date: Wed, 3 Mar 2010 13:23:29 +0900

e$B:#$N$H$3$m!"%a%=%C%I%7%0%M%A%c$G0z?t$K%G%U%)%k%HCM$,$"$k>l9g$O=q$$$F$*e(B
e$B$/!"$H$$$&%k!<%ke(B[1]e$B$,$"$k$h$&$J$N$G!"@bL@J8$@$1DI2Ce(B[2]e$B$7$^$7$?!#FbMF$,e(B
e$B$"$C$F$$$k$+8+$F$$$?$@$1$k$H$"$j$,$?$$$G$9!#e(B

  1. http://www.fdiary.net/ml/ruby-reference-manual/msg/360
  2. http://redmine.ruby-lang.org/repositories/diff/rurema?rev=3924

e$B3NG’$7$^$7$?!#e(B

e$B$"$j$,$H$&$4$6$$$^$9!#e(B

e$B%(%s%I%f!<%6$O<+J,$N4D6-$,e(Bfcntle$B$,MxMQ$G$-$k4D6-$+$I$&$+CN$C$F$$$k$N$@$m$&$+!)e(B
e$B$HAGKQ$J5?Ld$,$o$-$^$7$?!#e(B

require “fcntl” e$B$G$-$k$H$+!":#2s$NMQES$G$Oe(B Fcntl::F_GETFL
e$B$,Dj5A$5$l$Fe(B
e$B$$$k!"$H$+8+$l$P$$$$$N$+$J!);d<+?H!"$h$/J,$+$C$F$^$;$s!#e(B

e$B$^$C$?$/J,$+$C$F$J$/$F62=L$J$N$G$9$,!"%j%U%!%l%s%9$N=,47E*$K$O!Ve(Bxxe$B$,MxMQ$G$-$k4D6-!We(B
e$B$H$$$&I=5-$H!Ve(BWindowse$B4D6-$G$O!W$H$$$&I=5-$N$I$A$i$,0lHLE*$J$N$G$7$g$&$+!#e(B
e$BA0<T$N>l9g!"$J$K$bLdBj$J$$$H;W$$$^$9!#e(B

e$B9TC10L$G$7$+D4$Y$F$$$^$;$s$,!"!Ve(BWindows
e$B4D6-!W$H$$$&I=8=$O>/$J$/!“Nc$(e(B
e$B$P!“e(BEncoding.locale_charmap e$B$N@bL@$K$O!Ve(Bnl_langinfo
e$BEy$,$J$$4D6-$G$O!We(B
e$B$H$$$&I=8=$,$”$C$?$N$G!”:#2s$O$H$j$"$($:$3$N$^$^$K$7$F$*$3$&$H;W$$$^$9!#e(B


#15

e$B%A%1%C%He(B #1582 e$B$,99?7$5$l$^$7$?!#e(B (by _ wanabe)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

r24102 e$B$K$D$$$F$N5DO@$Oe(B [Bug #2796]
e$B$G!"$H$N$3$H$G$9$N$G%/%m!<%:$5$;$FD:$-$^$9!#e(B
e$BLdBj$,$"$j$^$7$?$i:F%*!<%W%s$r$*4j$$$7$^$9!#e(B

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