Skip to content

Commit

Permalink
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/io.rb
Original file line number Diff line number Diff line change
@@ -74,4 +74,51 @@ def self.setup(io, fd, mode=nil, sync=false)
end
end

##
# Writes the given objects to ios as with IO#print.
# Writes a record separator (typically a newline)
# after any that do not already end with a newline
# sequence. If called with an array argument, writes
# each element on a new line. If called without arguments,
# outputs a single record separator.
#
# $stdout.puts("this", "is", "a", "test")
# produces:
#
# this
# is
# a
# test
def puts(*args)
if args.empty?
write DEFAULT_RECORD_SEPARATOR
else
args.each do |arg|
if arg.equal? nil
str = ""
elsif Thread.guarding? arg
str = "[...]"
elsif arg.kind_of?(Array)
Thread.recursion_guard arg do
arg.each do |a|
puts a
end
end
else
str = arg.to_s
end

if str
# Truffle: write the string + record separator (\n) atomically so multithreaded #puts is bearable
unless str.suffix?(DEFAULT_RECORD_SEPARATOR)
str += DEFAULT_RECORD_SEPARATOR
end
write str
end
end
end

nil
end

end

3 comments on commit 102da2f

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broke a lot of specs, on Linux at least. Anything that counts the number of times write is called on a mock object seems to have broken.

@eregon
Copy link
Member Author

@eregon eregon commented on 102da2f Jul 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I will investigate. It seems silly to specify the number of calls to write.

@eregon
Copy link
Member Author

@eregon eregon commented on 102da2f Jul 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems I am not the only one to think that. I will fix.

# TODO: need to find a better way to test this. Too fragile to set expectations
# to each write call. Only care that all the characters are sent not the number
# or write calls. Also, these tests do not make sure the ordering of the write calls
# are correct.

Please sign in to comment.