Skip to content

Commit

Permalink
Follow up for PR "Add IO#pread and IO#pwrite methods"
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4447
  • Loading branch information
andrykonchin committed Jan 10, 2025
2 parents 67ab7f5 + 349d118 commit ea16943
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/main/ruby/truffleruby/core/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def self.read_string_polyglot(io, length)
end
end

def self.pread_string_native(io, length, offset)
def self.pread_string(io, length, offset)
fd = io.fileno
buffer = Primitive.io_thread_buffer_allocate(length)

Expand All @@ -508,10 +508,6 @@ def self.pread_string_native(io, length, offset)
end
end

def self.pread_string_polyglot(io, length, offset)
raise 'Not implemented' # there is not way to read starting from a specific position
end

# #write_string (either #write_string_native or #write_string_polyglot) is
# called by IO#syswrite, IO#write, and IO::InternalBuffer#empty_to

Expand Down Expand Up @@ -604,7 +600,7 @@ def self.write_string_nonblock_polyglot(io, string)
end
end

def self.pwrite_string_native(io, string, offset)
def self.pwrite_string(io, string, offset)
fd = io.fileno
length = string.bytesize
buffer = Primitive.io_thread_buffer_allocate(length)
Expand All @@ -621,30 +617,22 @@ def self.pwrite_string_native(io, string, offset)
end
end

def self.pwrite_string_polyglot(io, length, offset)
raise 'Not implemented' # there is not way to write starting from a specific position
end

# Select between native and polyglot variants

Truffle::Boot.delay do
if Truffle::Boot.get_option('polyglot-stdio')
class << self
alias_method :read_string, :read_string_polyglot
alias_method :read_to_buffer, :read_to_buffer_polyglot
alias_method :pread_string, :pread_string_polyglot
alias_method :write_string, :write_string_polyglot
alias_method :write_string_nonblock, :write_string_nonblock_polyglot
alias_method :pwrite_string, :pwrite_string_polyglot
end
else
class << self
alias_method :read_string, :read_string_native
alias_method :read_to_buffer, :read_to_buffer_native
alias_method :pread_string, :pread_string_native
alias_method :write_string, :write_string_native
alias_method :write_string_nonblock, :write_string_nonblock_native
alias_method :pwrite_string, :pwrite_string_native
end
end
end
Expand Down

0 comments on commit ea16943

Please sign in to comment.