Permalink
Browse files

Add platform constants for Linux and BSD

This commit creates constants and specs for the remaining
FFI::Platform::IS_LINUX constant.

Additional constants have been added for compatibility with MRI's
FFI gem: IS_GNU, NAME, IS_FREEBSD, IS_OPENBSD, IS_BSD.

BSD constants are pointless since RBX does not currently check for
BSD platforms other than OSX. IS_BSD is the only constant which can
be true at the moment since IS_MAC can be true as well.
IS_GNU should be reviewed and potentially spec'ed as it currently
checks definition of FFI::Library::LIBC for its boolean value which
may not be the correct approach. MRI implementation checked for
the definition of "GNU_LIBC" constant which appears analogous to
our FFI::Library::LIBC.
  • Loading branch information...
1 parent 6c27466 commit 0f124953682d40860c0926de47224c9b8753743d RageLtMan committed Dec 16, 2012
Showing with 32 additions and 2 deletions.
  1. +10 −0 kernel/platform/ffi.rb
  2. +22 −2 spec/ruby/optional/ffi/platform_spec.rb
View
10 kernel/platform/ffi.rb
@@ -223,28 +223,38 @@ def initialize(struct)
##
# Namespace for holding platform-specific C constants.
+##
module FFI::Platform
case
when Rubinius.windows?
LIBSUFFIX = "dll"
IS_WINDOWS = true
IS_MAC = false
+ IS_LINUX = false
OS = 'windows'
when Rubinius.darwin?
LIBSUFFIX = "dylib"
IS_WINDOWS = false
IS_MAC = true
+ IS_LINUX = false
OS = 'darwin'
else
LIBSUFFIX = "so"
IS_WINDOWS = false
IS_MAC = false
+ IS_LINUX = true
OS = 'linux'
end
ARCH = Rubinius::CPU
+ NAME = "#{ARCH}-#{OS}"
+ IS_GNU = defined?(FFI::Library::LIBC)
+ IS_FREEBSD = OS == "freebsd"
+ IS_OPENBSD = OS == "openbsd"
+ IS_BSD = IS_MAC || IS_FREEBSD || IS_OPENBSD
+
# ruby-ffi compatible
LONG_SIZE = Rubinius::SIZEOF_LONG * 8
ADDRESS_SIZE = Rubinius::WORDSIZE
View
24 spec/ruby/optional/ffi/platform_spec.rb
@@ -48,18 +48,38 @@
end
platform_is :windows do
- it "returns true" do
+ it "returns false" do
FFI::Platform::IS_MAC.should == false
end
end
platform_is :darwin do
- it "returns false" do
+ it "returns true" do
FFI::Platform::IS_MAC.should == true
end
end
end
+describe "FFI::Platform::IS_LINUX" do
+ platform_is :linux do
+ it "returns true" do
+ FFI::Platform::IS_LINUX.should == true
+ end
+ end
+
+ platform_is :windows do
+ it "returns false" do
+ FFI::Platform::IS_LINUX.should == false
+ end
+ end
+
+ platform_is :darwin do
+ it "returns false" do
+ FFI::Platform::IS_LINUX.should == false
+ end
+ end
+end
+
describe "FFI::Platform::ARCH" do
it "returns the architecture type" do
FFI::Platform::ARCH.should == Rubinius::CPU

0 comments on commit 0f12495

Please sign in to comment.