Skip to content

Commit

Permalink
[PlistHelper] Add support for Ruby 1.9.3 implementation of Fiddle.
Browse files Browse the repository at this point in the history
Fixes #206.
  • Loading branch information
alloy authored and neonichu committed Jan 12, 2015
1 parent c16dd89 commit f1b6c35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/xcodeproj/ext.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
begin
require 'xcodeproj/plist_helper'
rescue LoadError, NameError
rescue LoadError
require 'rbconfig'
if RUBY_VERSION == '1.8.7' && RbConfig::CONFIG['prefix'] =~ %r{^/System/Library/Frameworks/Ruby.framework/}
$:.unshift(File.expand_path('../../../ext', __FILE__))
Expand Down
28 changes: 27 additions & 1 deletion lib/xcodeproj/plist_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fiddle'
require 'dl'

module Xcodeproj
# TODO: Delete me (compatibility with Ruby 1.8.7 C ext bundle)
Expand Down Expand Up @@ -81,6 +82,29 @@ def ruby_hash_write_xcode(hash, path)
end
end

# Define compatibility with older Fiddle implementation in Ruby 1.9.3.
#
# @!visibility private
#
module Fiddle
SIZEOF_INTPTR_T = DL::SIZEOF_VOIDP unless defined?(SIZEOF_INTPTR_T)
NULL = DL::NULL unless defined?(NULL)

unless respond_to?(:dlopen)
def self.dlopen(library)
DL.dlopen(library)
end
end

class Function
unless public_method_defined?(:to_i)
def to_i
@ptr.to_i
end
end
end
end

# This module provides an interface to the CoreFoundation OS X framework.
# Specifically it bridges the functions required to be able to read and write
# property lists.
Expand All @@ -90,6 +114,8 @@ def ruby_hash_write_xcode(hash, path)
#
# @todo Move this out into its own gem.
#
# @!visibility private
#
module CoreFoundation
PATH = '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation'

Expand Down Expand Up @@ -205,7 +231,7 @@ def self.image
end

def self.free_function
@ruby_free ||= Fiddle::Function.new(Fiddle::RUBY_FREE, [VoidPointer], Void)
@free_function ||= Fiddle::Function.new(DL::Handle.new['free'], [VoidPointer], Void)
end

def self.CFRelease_function
Expand Down

0 comments on commit f1b6c35

Please sign in to comment.