ffi-icu 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ffi-icu/lib.rb CHANGED
@@ -52,7 +52,6 @@ module ICU
52
52
  raise LoadError, "no idea how to load ICU on #{ICU.platform.inspect}, patches appreciated! (#{ex.message})"
53
53
  end
54
54
 
55
- # And last figure out the version we just loaded
56
55
  icu_version(libs)
57
56
  end
58
57
 
@@ -73,6 +72,38 @@ module ICU
73
72
  version
74
73
  end
75
74
 
75
+ def self.figure_suffix(version)
76
+ # For some reason libicu prepends its exported functions with version information,
77
+ # which differs across all platforms. Some examples:
78
+ #
79
+ # OSX:
80
+ # u_errorName
81
+ #
82
+ # CentOS 5
83
+ # u_errorName_3_6
84
+ #
85
+ # Fedora 14 and Windows (using mingw)
86
+ # u_errorName_44
87
+ #
88
+ # So we need to figure out which one it is.
89
+
90
+ # Here are the possible suffixes
91
+ suffixes = [""]
92
+ if version
93
+ suffixes << "_#{version}" << "_#{version[0].chr}_#{version[1].chr}"
94
+ end
95
+
96
+ # Try to find the u_errorName function using the possible suffixes
97
+ suffixes.find do |suffix|
98
+ function_name = "u_errorName#{suffix}"
99
+ function_names(function_name, nil).find do |fname|
100
+ ffi_libraries.find do |lib|
101
+ lib.find_function(fname)
102
+ end
103
+ end
104
+ end
105
+ end
106
+
76
107
  def self.check_error
77
108
  ptr = FFI::MemoryPointer.new(:int)
78
109
  ret = yield(ptr)
@@ -111,7 +142,7 @@ module ICU
111
142
  end
112
143
 
113
144
  version = load_icu
114
- suffix = version ? "_#{version}" : ""
145
+ suffix = figure_suffix(version)
115
146
 
116
147
  attach_function :u_errorName, "u_errorName#{suffix}", [:int], :string
117
148
  attach_function :uenum_count, "uenum_count#{suffix}", [:pointer, :pointer], :int
@@ -1,3 +1,3 @@
1
1
  module ICU
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-icu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 1.8.21
120
+ rubygems_version: 1.8.24
121
121
  signing_key:
122
122
  specification_version: 3
123
123
  summary: Simple Ruby FFI wrappers for things I need from ICU.