@@ -923,7 +923,7 @@ def self.sysopen(path, mode = nil, perm = nil)
923
923
#
924
924
# The +sync+ attribute will also be set.
925
925
#
926
- def self . setup ( io , fd , mode = nil , sync = false )
926
+ def self . setup ( io , fd , mode , sync )
927
927
if !Truffle ::Boot . preinitializing? && Truffle ::POSIX ::NATIVE
928
928
cur_mode = Truffle ::POSIX . fcntl ( fd , F_GETFL , 0 )
929
929
Errno . handle if cur_mode < 0
@@ -946,21 +946,11 @@ def self.setup(io, fd, mode=nil, sync=false)
946
946
947
947
Primitive . io_set_fd ( io , fd )
948
948
io . instance_variable_set :@mode , Truffle ::IOOperations . translate_omode_to_fmode ( mode )
949
- io . sync = Primitive . as_boolean ( sync )
949
+ io . sync = sync
950
950
io . autoclose = true
951
951
ibuffer = mode != WRONLY ? IO ::InternalBuffer . new : nil
952
952
io . instance_variable_set :@ibuffer , ibuffer
953
953
io . instance_variable_set :@lineno , 0
954
-
955
- # Truffle: STDOUT isn't defined by the time this call is made during bootstrap, so we need to guard it.
956
- if defined? STDOUT and STDOUT . respond_to? ( :fileno ) and not STDOUT . closed?
957
- io . sync ||= STDOUT . fileno == fd
958
- end
959
-
960
- # Truffle: STDERR isn't defined by the time this call is made during bootstrap, so we need to guard it.
961
- if defined? STDERR and STDERR . respond_to? ( :fileno ) and not STDERR . closed?
962
- io . sync ||= STDERR . fileno == fd
963
- end
964
954
end
965
955
966
956
#
@@ -977,7 +967,9 @@ def initialize(fd, mode=nil, options=undefined)
977
967
978
968
mode , binary , external , internal , autoclose_tmp , _perm = IO . normalize_options ( mode , nil , options )
979
969
980
- IO . setup self , Truffle ::Type . coerce_to ( fd , Integer , :to_int ) , mode
970
+ fd = Truffle ::Type . coerce_to ( fd , Integer , :to_int )
971
+ sync = fd == 2 # stderr is always unbuffered, see setvbuf(3)
972
+ IO . setup ( self , fd , mode , sync )
981
973
982
974
binmode if binary
983
975
set_encoding external , internal
0 commit comments