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: 52275eb17ded
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8884d8b44062
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 23, 2016

  1. Copy the full SHA
    ff81603 View commit details
  2. Copy the full SHA
    8fa05ea View commit details
  3. call method on self via send

    Before the code was looking up 'self' by getting the current
    call frame and pulling self from it. This was returning a
    different object than expected. So now we just call #send
    against the current object; this works consistently.
    chuckremes committed Mar 23, 2016
    Copy the full SHA
    8d62572 View commit details
  4. Copy the full SHA
    8884d8b View commit details
Showing with 13 additions and 16 deletions.
  1. +11 −10 core/io.rb
  2. +2 −6 machine/builtin/io.cpp
21 changes: 11 additions & 10 deletions core/io.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ def socket_recv(bytes, flags, type)
end

module TransferIO
def send_io
def send_io(io)
Rubinius.primitive :io_send_io
raise PrimitiveFailure, "IO#send_io failed"
end
@@ -1674,13 +1674,17 @@ def self.setup(io, fd, mode=nil, sync=false)
end
end

# Check the given +io+ for a valid fd instance first. If it has one, don't
# allocate another because we could double up on finalizers for the same
# fd. Only allocate one here if +fd+ ivar is nil.
if io.instance_variable_get(:@fd).nil?
fd_obj = FileDescriptor.choose_type(fd, io)
io.instance_variable_set(:@fd, fd_obj)
# Check the given +io+ for a valid fd instance first. If it has one, cancel
# the existing finalizer since we are about to allocate a new fd instance.
if fd_obj = io.instance_variable_get(:@fd)
fd_obj.cancel_finalizer
end

fd_obj = FileDescriptor.choose_type(fd, io)
io.instance_variable_set(:@fd, fd_obj)
raise "FD could not be allocated for fd [#{fd}]" unless fd_obj
raise "No descriptor set for fd [#{fd}]" unless fd_obj.descriptor

io.mode = mode || cur_mode
io.sync = !!sync

@@ -1708,9 +1712,6 @@ def initialize(fd, mode=undefined, options=undefined)
mode, binary, external, internal, @autoclose = IO.normalize_options(mode, options)

fd = Rubinius::Type.coerce_to fd, Integer, :to_int
@fd = FileDescriptor.choose_type(fd, self)
raise "FD could not be allocated for fd [#{fd}]" unless @fd
raise "No descriptor set for fd [#{fd}]" unless @fd.descriptor
autoclose = @autoclose
IO.setup self, fd, mode
@lineno = 0
8 changes: 2 additions & 6 deletions machine/builtin/io.cpp
Original file line number Diff line number Diff line change
@@ -81,20 +81,16 @@ namespace rubinius {
}

native_int IO::descriptor(STATE) {
Object* io_object = state->vm()->get_ruby_frame()->self();

if(Fixnum* fd = try_as<Fixnum>(io_object->send(state, state->symbol("descriptor")))) {
if(Fixnum* fd = try_as<Fixnum>(send(state, state->symbol("descriptor")))) {
return fd->to_native();
}

Exception::raise_runtime_error(state, "IO descriptor is not a Fixnum");
}

void IO::ensure_open(STATE) {
Object* io_object = state->vm()->get_ruby_frame()->self();

// Will raise an exception if the file descriptor is not open
io_object->send(state, state->symbol("ensure_open"));
send(state, state->symbol("ensure_open"));
}

Array* ipaddr(STATE, struct sockaddr* addr, socklen_t len) {