Skip to content

Commit

Permalink
Pass an IO#ioctl spec
Browse files Browse the repository at this point in the history
* The 3rd argument of ioctl() needs to be long to pass integer values to it.
  Otherwise, NFI doesn't accept an integer as a pointer.
  • Loading branch information
eregon committed Feb 6, 2019
1 parent 8c45252 commit 6947469
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion 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
2 changes: 1 addition & 1 deletion src/main/ruby/core/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +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, :pointer], :int
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 6947469

Please sign in to comment.