Skip to content

Commit

Permalink
TTY-screen fixes
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/601
  • Loading branch information
eregon committed Feb 7, 2019
2 parents 024f27d + 6947469 commit e4211f0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
7 changes: 4 additions & 3 deletions lib/truffle/fiddle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.

require 'fiddle/fiddle'
require 'fiddle/handle'
require 'fiddle/function'
require_relative 'fiddle/fiddle'
require_relative 'fiddle/error'
require_relative 'fiddle/handle'
require_relative 'fiddle/function'
12 changes: 12 additions & 0 deletions lib/truffle/fiddle/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0, or
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.

module Fiddle
class DLError < StandardError
end
end
2 changes: 2 additions & 0 deletions lib/truffle/fiddle/handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Handle

def initialize(library=nil)
@handle = Truffle::Interop.eval('application/x-native', library ? "load #{library}" : 'default')
rescue RuntimeError
raise Fiddle::DLError, "#{library}: cannot open shared object file: No such file or directory"
end

def sym(symbol)
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/io/ioctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

platform_is :linux do
platform_is "86" do # x86 / x86_64
guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64
it "resizes an empty String to match the output size" do
File.open(__FILE__, 'r') do |f|
buffer = ''
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/io/ioctl_tags.txt

This file was deleted.

13 changes: 7 additions & 6 deletions src/main/ruby/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ def internal_encoding
# interpreted as a binary sequence of bytes (Array#pack
# might be a useful way to build this string). On Unix
# platforms, see fcntl(2) for details. Not implemented on all platforms.
def ioctl(command, arg=0)
def ioctl(command, arg = 0)
ensure_open

if !arg
Expand All @@ -1738,16 +1738,17 @@ def ioctl(command, arg=0)
# Most Linux ioctl codes predate the convention, so a fallback like this
# is still necessary.
buffer_size = 4096 if buffer_size < 4096
buffer = FFI::MemoryPointer.new buffer_size
buffer.write_string arg, arg.bytesize
buffer = FFI::MemoryPointer.new(buffer_size)
buffer.write_string(arg, arg.bytesize)
real_arg = buffer.address
else
real_arg = Truffle::Type.coerce_to_int arg
real_arg = Truffle::Type.coerce_to_int(arg)
end

command = Truffle::Type.coerce_to_int command
ret = Truffle::POSIX.ioctl descriptor, command, real_arg
command = Truffle::Type.coerce_to_int(command)
ret = Truffle::POSIX.ioctl(descriptor, command, real_arg)
Errno.handle if ret < 0

if arg.kind_of?(String)
arg.replace buffer.read_string(buffer_size)
buffer.free
Expand Down
1 change: 1 addition & 0 deletions src/main/ruby/core/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
attach_function :fsync, [:int], :int
attach_function :ftruncate, [:int, :off_t], :int
attach_function :getcwd, [:pointer, :size_t], :string
attach_function :ioctl, [:int, :ulong, :long], :int
attach_function :isatty, [:int], :int
attach_function :lchmod, [:string, :mode_t], :int
attach_function :lchown, [:string, :uid_t, :gid_t], :int
Expand Down

0 comments on commit e4211f0

Please sign in to comment.