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: a164d2c748a7
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 03d4923118a4
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Feb 1, 2015

  1. Copy the full SHA
    7759e94 View commit details
  2. Copy the full SHA
    03d4923 View commit details
Showing with 59 additions and 18 deletions.
  1. +59 −18 kernel/common/io.rb
77 changes: 59 additions & 18 deletions kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ def sysseek(offset, whence=SEEK_SET)
Errno.handle("seek failed") if FFI.call_failed?(position)

@offset = position
@eof = position == @total_size
determine_eof

return position
end
@@ -186,6 +186,9 @@ def read(length, output_string=nil)
elsif bytes_read == 0
@eof = true if length > 0
return nil
#elsif bytes_read < length
#@eof = true
#break
else
break
end
@@ -198,7 +201,7 @@ def read(length, output_string=nil)
end

@offset += bytes_read
@eof = true if @offset == @total_size
determine_eof

return output_string
end
@@ -281,6 +284,17 @@ def close

return nil
end

def determine_eof
if @offset >= @total_size
@eof = true
@total_size += (@total_size - @offset)
@total_size = @offset if @offset > @total_size
else
@eof = false
end
end
private :determine_eof

def eof?
@eof
@@ -358,8 +372,8 @@ def reopen(other_fd)
return nil
end

set_mode
reset_positioning
#set_mode
#reset_positioning

return true
end
@@ -382,8 +396,8 @@ def reopen_path(path, mode)
FFI::Platform::POSIX.close(other_fd)
end

set_mode
reset_positioning
#set_mode
#reset_positioning

return true
end
@@ -392,10 +406,15 @@ def reset_positioning(stat=nil)
# Discover final size of file so we can set EOF properly
stat = Stat.fstat(@descriptor) unless stat
@total_size = stat.size
@offset = 0
@eof = @offset == @total_size
seek_positioning
#@eof = @offset >= @total_size
determine_eof
end

def seek_positioning
@offset = sysseek(0, SEEK_CUR) # find current position if we are reopening!
end
private :reset_positioning
private :seek_positioning

def set_mode
if IO::F_GETFL
@@ -453,6 +472,7 @@ def read(length, output_string=nil)
str2 = super(length, output_string)

if str.size == 0 && str2.nil?
determine_eof
return nil
elsif str2
str += str2
@@ -479,8 +499,7 @@ def read(length, output_string=nil)
output_string = str.force_encoding(Encoding::ASCII_8BIT)
end

@eof = true if @offset == @total_size

determine_eof
return output_string
end

@@ -525,16 +544,31 @@ def initialize(fd, mode)
@descriptor = fd
@mode = mode
@sync = true
@offset = 0
@eof = false

@unget_buffer = []
reset_positioning
@eof = false # force to false
end

def determine_eof
if @offset >= @total_size
@eof = true

# No seeking allowed on a pipe, so its size is always its offset
@total_size = @offset
end
end

def eof?
# The only way to confirm we are EOF with a pipe is to try to read from
# it. If we fail, then we are EOF. If we succeed, then unget the byte
# so that EOF is false (i.e. more to read).
str = read(1)
unget(str) if str
@eof
super
end

def seek_positioning
# no seeking allowed for pipes
@offset = 0
end
end # class PipeFileDescriptor

@@ -1978,7 +2012,7 @@ def fileno
# no newline
def flush
ensure_open
@fd.flush
@fd.reset_positioning
return self
end

@@ -2453,6 +2487,10 @@ def reopen(other, mode=undefined)
# io.reset_buffering

@fd.reopen(io.descriptor)

# When reopening we may be going from a Pipe to a File or vice versa. Let the
# system figure out the proper FD class.
@fd = FileDescriptor.choose_type(descriptor)
Rubinius::Unsafe.set_class self, io.class
if io.respond_to?(:path)
@path = io.path
@@ -2473,14 +2511,17 @@ def reopen(other, mode=undefined)
end

reopen_path Rubinius::Type.coerce_to_path(other), mode
@fd = FileDescriptor.choose_type(descriptor)
seek 0, SEEK_SET unless closed?
end

self
end

def reopen_path(path, mode)
return @fd.reopen_path(path, mode)
status = @fd.reopen_path(path, mode)
@fd = FileDescriptor.choose_type(descriptor)
return status
end

##