Skip to content

Add FFI::Platform::IS_MAC constant #2096

Closed
wants to merge 3 commits into from
View
13 kernel/platform/ffi.rb
@@ -223,25 +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"
@subwindow
Rubinius member
subwindow added a note Dec 16, 2012

I don't think this is right, because IS_LINUX and IS_.*BSD can be true at the same time.

I would suggest adding Rubinius.bsd? to the case statement and doing the distinguishing between free/open inside that block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
40 spec/ruby/optional/ffi/platform_spec.rb
@@ -40,6 +40,46 @@
end
end
+describe "FFI::Platform::IS_MAC" do
+ platform_is :linux do
+ it "returns false" do
+ FFI::Platform::IS_MAC.should == false
+ end
+ end
+
+ platform_is :windows do
+ it "returns false" do
+ FFI::Platform::IS_MAC.should == false
+ end
+ end
+
+ platform_is :darwin 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
Something went wrong with that request. Please try again.