Skip to content

Commit 950ddf3

Browse files
committed
[GR-17457] Simplify the logic for the default value of IO#sync
PullRequest: truffleruby/2717
2 parents 53c2541 + be0aaab commit 950ddf3

File tree

1 file changed

+5
-13
lines changed
  • src/main/ruby/truffleruby/core

1 file changed

+5
-13
lines changed

src/main/ruby/truffleruby/core/io.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ def self.sysopen(path, mode = nil, perm = nil)
923923
#
924924
# The +sync+ attribute will also be set.
925925
#
926-
def self.setup(io, fd, mode=nil, sync=false)
926+
def self.setup(io, fd, mode, sync)
927927
if !Truffle::Boot.preinitializing? && Truffle::POSIX::NATIVE
928928
cur_mode = Truffle::POSIX.fcntl(fd, F_GETFL, 0)
929929
Errno.handle if cur_mode < 0
@@ -946,21 +946,11 @@ def self.setup(io, fd, mode=nil, sync=false)
946946

947947
Primitive.io_set_fd(io, fd)
948948
io.instance_variable_set :@mode, Truffle::IOOperations.translate_omode_to_fmode(mode)
949-
io.sync = Primitive.as_boolean(sync)
949+
io.sync = sync
950950
io.autoclose = true
951951
ibuffer = mode != WRONLY ? IO::InternalBuffer.new : nil
952952
io.instance_variable_set :@ibuffer, ibuffer
953953
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
964954
end
965955

966956
#
@@ -977,7 +967,9 @@ def initialize(fd, mode=nil, options=undefined)
977967

978968
mode, binary, external, internal, autoclose_tmp, _perm = IO.normalize_options(mode, nil, options)
979969

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)
981973

982974
binmode if binary
983975
set_encoding external, internal

0 commit comments

Comments
 (0)