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: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9be5e6a52ecf
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: faea8f0552d7
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 14, 2015

  1. Copy the full SHA
    afa37e5 View commit details
  2. Copy the full SHA
    58c28cd View commit details
  3. Add File::NONBLOCK for Windows.

    According to jnr-constants, this is not a defined value on
    Windows, but MRI appears to use the value "1".
    headius committed Jan 14, 2015
    Copy the full SHA
    faea8f0 View commit details
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -153,6 +153,9 @@ public static RubyClass createFileClass(Ruby runtime) {
}
/* do not block on open or for data to become available */
constants.setConstant("NONBLOCK", runtime.newFixnum(OpenFlags.O_NONBLOCK.intValue()));
} else if (Platform.IS_WINDOWS) {
// FIXME: Should NONBLOCK exist for Windows fcntl flags?
constants.setConstant("NONBLOCK", runtime.newFixnum(1));
}
/* truncate size to 0 */
constants.setConstant("TRUNC", runtime.newFixnum(OpenFlags.O_TRUNC.intValue()));
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.fcntl.FcntlLibrary;
import org.jruby.platform.Platform;
import org.jruby.runtime.Arity;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
@@ -608,7 +609,7 @@ public boolean doNotReverseLookup(ThreadContext context) {
protected static ChannelFD newChannelFD(Ruby runtime, Channel channel) {
ChannelFD fd = new ChannelFD(channel, runtime.getPosix(), runtime.getFilenoUtil());

if (runtime.getPosix().isNative() && fd.realFileno >= 0) {
if (runtime.getPosix().isNative() && fd.realFileno >= 0 && !Platform.IS_WINDOWS) {
runtime.getPosix().fcntlInt(fd.realFileno, Fcntl.F_SETFD, FcntlLibrary.FD_CLOEXEC);
}

77 changes: 0 additions & 77 deletions lib/ruby/stdlib/fiddle.rb
Original file line number Diff line number Diff line change
@@ -67,83 +67,6 @@ def dlopen library
end
module_function :dlopen

class DLError < StandardError; end

class Handle
RTLD_GLOBAL = FFI::DynamicLibrary::RTLD_GLOBAL
RTLD_LAZY = FFI::DynamicLibrary::RTLD_LAZY
RTLD_NOW = FFI::DynamicLibrary::RTLD_NOW

def initialize(libname = nil, flags = RTLD_LAZY | RTLD_GLOBAL)
@lib = FFI::DynamicLibrary.open(libname, flags)
raise RuntimeError, "Could not open #{libname}" unless @lib

@open = true

begin
yield(self)
ensure
self.close
end if block_given?
end

def close
raise DLError.new("closed handle") unless @open
@open = false
0
end

def self.sym(func)
DEFAULT.sym(func)
end

def sym(func)
raise TypeError.new("invalid function name") unless func.is_a?(String)
raise DLError.new("closed handle") unless @open
address = @lib.find_function(func)
raise DLError.new("unknown symbol #{func}") if address.nil? || address.null?
address.to_i
end

def self.[](func)
self.sym(func)
end

def [](func)
sym(func)
end

def enable_close
@enable_close = true
end

def close_enabled?
@enable_close
end

def disable_close
@enable_close = false
end
end

ALIGN_VOIDP = Fiddle::JRuby::FFITypes[TYPE_VOIDP].alignment
ALIGN_CHAR = Fiddle::JRuby::FFITypes[TYPE_CHAR].alignment
ALIGN_SHORT = Fiddle::JRuby::FFITypes[TYPE_SHORT].alignment
ALIGN_INT = Fiddle::JRuby::FFITypes[TYPE_INT].alignment
ALIGN_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG].alignment
ALIGN_LONG_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG_LONG].alignment
ALIGN_FLOAT = Fiddle::JRuby::FFITypes[TYPE_FLOAT].alignment
ALIGN_DOUBLE = Fiddle::JRuby::FFITypes[TYPE_DOUBLE].alignment

SIZEOF_VOIDP = Fiddle::JRuby::FFITypes[TYPE_VOIDP].size
SIZEOF_CHAR = Fiddle::JRuby::FFITypes[TYPE_CHAR].size
SIZEOF_SHORT = Fiddle::JRuby::FFITypes[TYPE_SHORT].size
SIZEOF_INT = Fiddle::JRuby::FFITypes[TYPE_INT].size
SIZEOF_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG].size
SIZEOF_LONG_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG_LONG].size
SIZEOF_FLOAT = Fiddle::JRuby::FFITypes[TYPE_FLOAT].size
SIZEOF_DOUBLE = Fiddle::JRuby::FFITypes[TYPE_DOUBLE].size

# Add constants for backwards compat

RTLD_GLOBAL = Handle::RTLD_GLOBAL # :nodoc:
222 changes: 221 additions & 1 deletion lib/ruby/stdlib/fiddle/jruby.rb
Original file line number Diff line number Diff line change
@@ -47,7 +47,13 @@ class Function
DEFAULT = "default"
STDCALL = "stdcall"

def initialize(ptr, args, return_type, abi = DEFAULT)
def initialize(ptr, args, return_type, abi = DEFAULT, kwargs = nil)
if kwargs.nil?
if abi.kind_of? Hash
kwargs = abi
abi = DEFAULT
end
end
@ptr, @args, @return_type, @abi = ptr, args, return_type, abi
raise TypeError.new "invalid return type" unless return_type.is_a?(Integer)
raise TypeError.new "invalid return type" unless args.is_a?(Array)
@@ -83,4 +89,218 @@ def to_i
@function.to_i
end
end

class DLError < StandardError; end

class Pointer
attr_reader :ffi_ptr
extend FFI::DataConverter
native_type FFI::Type::Builtin::POINTER

def self.to_native(value, ctx)
if value.is_a?(Pointer)
value.ffi_ptr

elsif value.is_a?(Integer)
FFI::Pointer.new(value)

elsif value.is_a?(String)
value
end
end

def self.from_native(value, ctx)
self.new(value)
end

def self.to_ptr(value)
if value.is_a?(String)
cptr = Pointer.malloc(value.bytesize + 1)
size = value.bytesize + 1
cptr.ffi_ptr.put_string(0, value)
cptr

elsif value.respond_to?(:to_ptr)
ptr = value.to_ptr
ptr.is_a?(Pointer) ? ptr : Pointer.new(ptr)

else
Pointer.new(value)
end
end

class << self
alias [] to_ptr
end

def initialize(addr, size = nil, free = nil)
ptr = if addr.is_a?(FFI::Pointer)
addr

elsif addr.is_a?(Integer)
FFI::Pointer.new(addr)
end

@size = size ? size : ptr.size
@free = free
@ffi_ptr = free.nil? ? ptr : FFI::AutoPointer.new(ptr, self.class.__freefunc__(free))
end

def self.__freefunc__(free)
if free.is_a?(FFI::Function)
free

elsif free.is_a?(FFI::Pointer)
free.null? ? Proc.new { |ptr| } : FFI::Function.new(:void, [ :pointer ], free)

elsif free.is_a?(Integer)
free == 0 ? Proc.new { |ptr| } : FFI::Function.new(:void, [ :pointer ], FFI::Pointer.new(free))

elsif free.respond_to?(:call)
free

else
raise ArgumentError.new("invalid free func")
end
end

def self.malloc(size, free = nil)
self.new(LibC.malloc(size), size, free ? free : LibC::FREE)
end

def null?
@ffi_ptr.null?
end

def to_ptr
@ffi_ptr
end

def size
defined?(@layout) ? @layout.size : @size
end

def size=(size)
@size = size
end

def [](index, length = nil)
if length
ffi_ptr.get_string(index, length)
else
ffi_ptr.get_int(index)
end
end

def to_i
ffi_ptr.to_i
end
alias to_int to_i

def to_str(len = nil)
if len
ffi_ptr.get_string(0, len)
else
ffi_ptr.get_string(0)
end
end
alias to_s to_str

def inspect
"#<#{self.class.name} ptr=#{ffi_ptr.address.to_s(16)} size=#{@size} free=#{@free.inspect}>"
end

def +(delta)
self.class.new(ffi_ptr + delta, @size - delta)
end

def -(delta)
self.class.new(ffi_ptr - delta, @size + delta)
end

def ptr
Pointer.new(ffi_ptr.get_pointer(0))
end

def ref
cptr = Pointer.malloc(FFI::Type::POINTER.size)
cptr.ffi_ptr.put_pointer(0, ffi_ptr)
cptr
end
end

class Handle
RTLD_GLOBAL = FFI::DynamicLibrary::RTLD_GLOBAL
RTLD_LAZY = FFI::DynamicLibrary::RTLD_LAZY
RTLD_NOW = FFI::DynamicLibrary::RTLD_NOW

def initialize(libname = nil, flags = RTLD_LAZY | RTLD_GLOBAL)
@lib = FFI::DynamicLibrary.open(libname, flags)
raise RuntimeError, "Could not open #{libname}" unless @lib

@open = true

begin
yield(self)
ensure
self.close
end if block_given?
end

def close
raise DLError.new("closed handle") unless @open
@open = false
0
end

def self.sym(func)
DEFAULT.sym(func)
end

def sym(func)
raise TypeError.new("invalid function name") unless func.is_a?(String)
raise DLError.new("closed handle") unless @open
address = @lib.find_function(func)
raise DLError.new("unknown symbol #{func}") if address.nil? || address.null?
address.to_i
end

def self.[](func)
self.sym(func)
end

def [](func)
sym(func)
end

def enable_close
@enable_close = true
end

def close_enabled?
@enable_close
end

def disable_close
@enable_close = false
end
end

ALIGN_VOIDP = Fiddle::JRuby::FFITypes[TYPE_VOIDP].alignment
ALIGN_CHAR = Fiddle::JRuby::FFITypes[TYPE_CHAR].alignment
ALIGN_SHORT = Fiddle::JRuby::FFITypes[TYPE_SHORT].alignment
ALIGN_INT = Fiddle::JRuby::FFITypes[TYPE_INT].alignment
ALIGN_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG].alignment
ALIGN_LONG_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG_LONG].alignment
ALIGN_FLOAT = Fiddle::JRuby::FFITypes[TYPE_FLOAT].alignment
ALIGN_DOUBLE = Fiddle::JRuby::FFITypes[TYPE_DOUBLE].alignment

SIZEOF_VOIDP = Fiddle::JRuby::FFITypes[TYPE_VOIDP].size
SIZEOF_CHAR = Fiddle::JRuby::FFITypes[TYPE_CHAR].size
SIZEOF_SHORT = Fiddle::JRuby::FFITypes[TYPE_SHORT].size
SIZEOF_INT = Fiddle::JRuby::FFITypes[TYPE_INT].size
SIZEOF_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG].size
SIZEOF_LONG_LONG = Fiddle::JRuby::FFITypes[TYPE_LONG_LONG].size
SIZEOF_FLOAT = Fiddle::JRuby::FFITypes[TYPE_FLOAT].size
SIZEOF_DOUBLE = Fiddle::JRuby::FFITypes[TYPE_DOUBLE].size
end
9 changes: 8 additions & 1 deletion lib/ruby/stdlib/win32/registry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'win32/importer'
require 'Win32API'

module Win32

@@ -167,7 +168,7 @@ module Constants
# Error
#
class Error < ::StandardError
FormatMessageA = Win32API.new('kernel32.dll', 'FormatMessageA', 'LPLLPLP', 'L')
FormatMessageW = Win32API.new('kernel32.dll', 'FormatMessageW', 'LPLLPLP', 'L')
def initialize(code)
@code = code
buff = WCHAR_NUL * 1024
@@ -227,6 +228,12 @@ module API
%w/RegEnumKeyExA LLPPLLLP L/,
%w/RegQueryValueExA LPLPPP L/,
%w/RegSetValueExA LPLLPL L/,
%w/RegOpenKeyExW LPLLP L/,
%w/RegCreateKeyExW LPLLLLPPP L/,
%w/RegEnumValueW LLPPPPPP L/,
%w/RegEnumKeyExW LLPPLLLP L/,
%w/RegQueryValueExW LPLPPP L/,
%w/RegSetValueExW LPLLPL L/,
%w/RegDeleteValue LP L/,
%w/RegDeleteKey LP L/,
%w/RegFlushKey L L/,