Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FFI::Platform::IS_MAC constant #2096

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions kernel/platform/ffi.rb
Expand Up @@ -223,25 +223,38 @@ def initialize(struct)


## ##
# Namespace for holding platform-specific C constants. # Namespace for holding platform-specific C constants.
##


module FFI::Platform module FFI::Platform
case case
when Rubinius.windows? when Rubinius.windows?
LIBSUFFIX = "dll" LIBSUFFIX = "dll"
IS_WINDOWS = true IS_WINDOWS = true
IS_MAC = false
IS_LINUX = false
OS = 'windows' OS = 'windows'
when Rubinius.darwin? when Rubinius.darwin?
LIBSUFFIX = "dylib" LIBSUFFIX = "dylib"
IS_WINDOWS = false IS_WINDOWS = false
IS_MAC = true
IS_LINUX = false
OS = 'darwin' OS = 'darwin'
else else
LIBSUFFIX = "so" LIBSUFFIX = "so"
IS_WINDOWS = false IS_WINDOWS = false
IS_MAC = false
IS_LINUX = true
OS = 'linux' OS = 'linux'
end end


ARCH = Rubinius::CPU ARCH = Rubinius::CPU


NAME = "#{ARCH}-#{OS}"
IS_GNU = defined?(FFI::Library::LIBC)
IS_FREEBSD = OS == "freebsd"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

IS_OPENBSD = OS == "openbsd"
IS_BSD = IS_MAC || IS_FREEBSD || IS_OPENBSD

# ruby-ffi compatible # ruby-ffi compatible
LONG_SIZE = Rubinius::SIZEOF_LONG * 8 LONG_SIZE = Rubinius::SIZEOF_LONG * 8
ADDRESS_SIZE = Rubinius::WORDSIZE ADDRESS_SIZE = Rubinius::WORDSIZE
Expand Down
40 changes: 40 additions & 0 deletions spec/ruby/optional/ffi/platform_spec.rb
Expand Up @@ -40,6 +40,46 @@
end end
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec description ("returns true") and the expectation disagree.

end
end

platform_is :darwin do
it "returns true" do
FFI::Platform::IS_MAC.should == true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here.

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 describe "FFI::Platform::ARCH" do
it "returns the architecture type" do it "returns the architecture type" do
FFI::Platform::ARCH.should == Rubinius::CPU FFI::Platform::ARCH.should == Rubinius::CPU
Expand Down