Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0a18f68f679f
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cabf83c93bff
Choose a head ref
  • 4 commits
  • 10 files changed
  • 1 contributor

Commits on Oct 5, 2015

  1. Copy the full SHA
    eac851a View commit details
  2. fix indentation

    chuckremes committed Oct 5, 2015
    Copy the full SHA
    58551ea View commit details
  3. Copy the full SHA
    4126901 View commit details
  4. fix indentation

    chuckremes committed Oct 5, 2015
    Copy the full SHA
    cabf83c View commit details
10 changes: 1 addition & 9 deletions kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -328,13 +328,7 @@ def eof?
@eof
end

# /**
# * This is NOT the same as close().
# *
# * @todo Need to build the infrastructure to be able to only
# * remove read or write waiters if a partial shutdown
# * is requested. --rue
# */
# This is NOT the same as close().
def shutdown(how)
ensure_open
fd = descriptor
@@ -3055,8 +3049,6 @@ def sync=(v)
# f = File.new("testfile")
# f.sysread(16) #=> "This is line one"
#
# @todo Improve reading into provided buffer.
#
def sysread(number_of_bytes, buffer=undefined)
str = @fd.sysread number_of_bytes
raise EOFError if str.nil?
56 changes: 30 additions & 26 deletions kernel/delta/io.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
# Redefine STDIN, STDOUT & STDERR to use the new IO class. It reopened and redefined
# all methods used in the bootstrap step. Secondly, update the $std* globals to point
# to the new objects.
module Rubinius
class IOUtility
# Redefine STDIN, STDOUT & STDERR to use the new IO class. It reopened and redefined
# all methods used in the bootstrap step. Secondly, update the $std* globals to point
# to the new objects.

def redefine_io(fd, mode)
# Note that we use IO.open instead of IO.reopen. The reason is that we reopened the
# IO class in common/io.rb and overwrote a lot of the methods that were defined in
# bootstrap/io.rb. So if we try to use IO.reopen on the original IO object, it won't
# be able to reach those original methods anymore. So, we just pass in the file
# descriptor integer directly and wrap it up in a new object. The original object
# will probably get garbage collected but we don't set a finalizer for FDs 0-2 which
# correspond to STDIN, STDOUT and STDERR so we don't need to worry that they'll get
# closed out from under us.
# Hopefully we can find a cleaner way to do this in the future, but for now it's a
# bit ugly.
new_io = IO.open(fd)
new_io.sync = true

if mode == :read_only
new_io.force_read_only
elsif mode == :write_only
new_io.force_write_only
def self.redefine_io(fd, mode)
# Note that we use IO.open instead of IO.reopen. The reason is that we reopened the
# IO class in common/io.rb and overwrote a lot of the methods that were defined in
# bootstrap/io.rb. So if we try to use IO.reopen on the original IO object, it won't
# be able to reach those original methods anymore. So, we just pass in the file
# descriptor integer directly and wrap it up in a new object. The original object
# will probably get garbage collected but we don't set a finalizer for FDs 0-2 which
# correspond to STDIN, STDOUT and STDERR so we don't need to worry that they'll get
# closed out from under us.
# Hopefully we can find a cleaner way to do this in the future, but for now it's a
# bit ugly.
new_io = IO.open(fd)
new_io.sync = true

if mode == :read_only
new_io.force_read_only
elsif mode == :write_only
new_io.force_write_only
end

return new_io
end
end

return new_io
end

STDIN = redefine_io(0, :read_only)
STDOUT = redefine_io(1, :write_only)
STDERR = redefine_io(2, :write_only)
STDIN = Rubinius::IOUtility.redefine_io(0, :read_only)
STDOUT = Rubinius::IOUtility.redefine_io(1, :write_only)
STDERR = Rubinius::IOUtility.redefine_io(2, :write_only)

Rubinius::Globals.set!(:$stdin, STDIN)
Rubinius::Globals.set!(:$stdout, STDOUT)
12 changes: 6 additions & 6 deletions spec/default.mspec
Original file line number Diff line number Diff line change
@@ -48,11 +48,11 @@ class MSpecScript
end

if IO.const_defined?(:POSIX_FADVISE_NORMAL) && IO.const_defined?(:POSIX_FADVISE_DONTNEED)
# Next, check to make sure both those values aren't zero; if they are, then this OS doesn't
# support it. This is a hack and should probably be improved as platform and feature
# detection changes in the build process
unless IO::POSIX_FADVISE_NORMAL.zero? && IO::POSIX_FADVISE_DONTNEED.zero?
MSpec.enable_feature :posix_fadvise
end
# Next, check to make sure both those values aren't zero; if they are, then this OS doesn't
# support it. This is a hack and should probably be improved as platform and feature
# detection changes in the build process
unless IO::POSIX_FADVISE_NORMAL.zero? && IO::POSIX_FADVISE_DONTNEED.zero?
MSpec.enable_feature :posix_fadvise
end
end
end
8 changes: 0 additions & 8 deletions spec/ruby/core/io/read_nonblock_spec.rb
Original file line number Diff line number Diff line change
@@ -45,14 +45,6 @@
@read.read_nonblock(10).should == "ahello"
end

not_compliant_on :rubinius, :jruby do
# TODO: Fix this.
#
# This feature was changed in 1.9
# see also: [ruby-dev:25101] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/25101
# and #2469 http://redmine.ruby-lang.org/issues/show/2469
end

it "raises IOError on closed stream" do
lambda { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError)
end
1 change: 0 additions & 1 deletion spec/ruby/core/io/read_spec.rb
Original file line number Diff line number Diff line change
@@ -544,7 +544,6 @@

describe "IO#read with large data" do
before :each do
# TODO: what is the significance of this mystery math?
@data_size = 8096 * 2 + 1024
@data = "*" * @data_size

237 changes: 237 additions & 0 deletions spec/ruby/core/io/shared/z_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#describe :io_readlines, :shared => true do
# it "raises TypeError if the first parameter is nil" do
# lambda { IO.send(@method, nil, &@object) }.should raise_error(TypeError)
# end
#
# it "raises an Errno::ENOENT if the file does not exist" do
# name = tmp("nonexistent.txt")
# lambda { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT)
# end
#
# it "yields a single string with entire content when the separator is nil" do
# result = IO.send(@method, @name, nil, &@object)
# (result ? result : ScratchPad.recorded).should == [IO.read(@name)]
# end
#
# it "yields a sequence of paragraphs when the separator is an empty string" do
# result = IO.send(@method, @name, "", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_empty_separator
# end
#end

#describe :io_readlines_options_18, :shared => true do
# it "does not change $_" do
# $_ = "test"
# IO.send(@method, @name, &@object)
# $_.should == "test"
# end
#
# describe "when passed name" do
# it "calls #to_str to convert the name" do
# name = mock("io readlines name")
# name.should_receive(:to_str).and_return(@name)
# result = IO.send(@method, name, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines
# end
# end
#
# describe "when passed name, separator" do
# it "calls #to_str to convert the name" do
# name = mock("io readlines name")
# name.should_receive(:to_str).and_return(@name)
# result = IO.send(@method, name, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines
# end
#
# it "calls #to_str to convert the separator" do
# sep = mock("io readlines separator")
# sep.should_receive(:to_str).at_least(1).and_return(" ")
# result = IO.send(@method, @name, sep, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator
# end
# end
#end

describe :io_readlines_options_19, :shared => true do
before :each do
@filename = tmp("io readlines options")
end

after :each do
rm_r @filename
end

# describe "when passed name" do
# it "calls #to_path to convert the name" do
# name = mock("io name to_path")
# name.should_receive(:to_path).and_return(@name)
# IO.send(@method, name, &@object)
# end
#
# it "defaults to $/ as the separator" do
# result = IO.send(@method, @name, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines
# end
# end

describe "when passed name, object" do
# it "calls #to_str to convert the object to a separator" do
# sep = mock("io readlines separator")
# sep.should_receive(:to_str).at_least(1).and_return(" ")
# result = IO.send(@method, @name, sep, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator
# end

describe "when the object is a Fixnum" do
before :each do
@sep = $/
end

after :each do
$/ = @sep
end

# it "defaults to $/ as the separator" do
# $/ = " "
# result = IO.send(@method, @name, 10, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end

it "uses the object as a limit if it is a Fixnum" do
result = IO.send(@method, @name, 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_limit
end
end

# describe "when the object is a String" do
# it "uses the value as the separator" do
# result = IO.send(@method, @name, " ", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator
# end
#
# it "accepts non-ASCII data as separator" do
# result = IO.send(@method, @name, "\303\250".force_encoding("utf-8"), &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_arbitrary_separator
# end
# end
#
# describe "when the object is a Hash" do
# it "uses the value as the options hash" do
# result = IO.send(@method, @name, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines
# end
# end
end

# describe "when passed name, object, object" do
# describe "when the first object is a Fixnum" do
# it "uses the second object as an options Hash" do
# lambda do
# IO.send(@method, @filename, 10, :mode => "w", &@object)
# end.should raise_error(IOError)
# end
#
# it "calls #to_hash to convert the second object to a Hash" do
# options = mock("io readlines options Hash")
# options.should_receive(:to_hash).and_return({ :mode => "w" })
# lambda do
# IO.send(@method, @filename, 10, options, &@object)
# end.should raise_error(IOError)
# end
# end
#
# describe "when the first object is a String" do
# it "uses the second object as a limit if it is a Fixnum" do
# result = IO.send(@method, @name, " ", 10, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "calls #to_int to convert the second object" do
# limit = mock("io readlines limit")
# limit.should_receive(:to_int).at_least(1).and_return(10)
# result = IO.send(@method, @name, " ", limit, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "uses the second object as an options Hash" do
# lambda do
# IO.send(@method, @filename, " ", :mode => "w", &@object)
# end.should raise_error(IOError)
# end
#
# it "calls #to_hash to convert the second object to a Hash" do
# options = mock("io readlines options Hash")
# options.should_receive(:to_hash).and_return({ :mode => "w" })
# lambda do
# IO.send(@method, @filename, " ", options, &@object)
# end.should raise_error(IOError)
# end
# end
#
# describe "when the first object is not a String or Fixnum" do
# it "calls #to_str to convert the object to a String" do
# sep = mock("io readlines separator")
# sep.should_receive(:to_str).at_least(1).and_return(" ")
# result = IO.send(@method, @name, sep, 10, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "uses the second object as a limit if it is a Fixnum" do
# result = IO.send(@method, @name, " ", 10, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "calls #to_int to convert the second object" do
# limit = mock("io readlines limit")
# limit.should_receive(:to_int).at_least(1).and_return(10)
# result = IO.send(@method, @name, " ", limit, &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "uses the second object as an options Hash" do
# lambda do
# IO.send(@method, @filename, " ", :mode => "w", &@object)
# end.should raise_error(IOError)
# end
#
# it "calls #to_hash to convert the second object to a Hash" do
# options = mock("io readlines options Hash")
# options.should_receive(:to_hash).and_return({ :mode => "w" })
# lambda do
# IO.send(@method, @filename, " ", options, &@object)
# end.should raise_error(IOError)
# end
# end
# end

# describe "when passed name, separator, limit, options" do
# it "calls #to_path to convert the name object" do
# name = mock("io name to_path")
# name.should_receive(:to_path).and_return(@name)
# result = IO.send(@method, name, " ", 10, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "calls #to_str to convert the separator object" do
# sep = mock("io readlines separator")
# sep.should_receive(:to_str).at_least(1).and_return(" ")
# result = IO.send(@method, @name, sep, 10, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "calls #to_int to convert the limit argument" do
# limit = mock("io readlines limit")
# limit.should_receive(:to_int).at_least(1).and_return(10)
# result = IO.send(@method, @name, " ", limit, :mode => "r", &@object)
# (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
# end
#
# it "calls #to_hash to convert the options object" do
# options = mock("io readlines options Hash")
# options.should_receive(:to_hash).and_return({ :mode => "w" })
# lambda do
# IO.send(@method, @filename, " ", 10, options, &@object)
# end.should raise_error(IOError)
# end
# end
end
12 changes: 0 additions & 12 deletions spec/ruby/core/io/ungetc_spec.rb
Original file line number Diff line number Diff line change
@@ -81,18 +81,6 @@
@io.pos.should == pos - 1
end

# TODO: file MRI bug
# Another specified behavior that MRI doesn't follow:
# "Has no effect with unbuffered reads (such as IO#sysread)."
#
#it "has no effect with unbuffered reads" do
# length = File.size(@io_name)
# content = @io.sysread(length)
# @io.rewind
# @io.ungetc(100)
# @io.sysread(length).should == content
#end

it "makes subsequent unbuffered operations to raise IOError" do
@io.getc
@io.ungetc(100)
2 changes: 0 additions & 2 deletions spec/ruby/core/io/write_spec.rb
Original file line number Diff line number Diff line change
@@ -20,8 +20,6 @@
rm_r @filename
end

# TODO: impl detail? discuss this with matz. This spec is useless. - rdavis
# I agree. I've marked it not compliant on macruby, as we don't buffer input. -pthomson
not_compliant_on :macruby, :rubinius do
it "writes all of the string's bytes but buffers them" do
written = @file.write("abcde")
Loading