public
Description: Full mirror of JRuby Subversion repository
Homepage: http://jruby.codehaus.org/
Clone URL: git://github.com/vvs/jruby.git
Merge branch 'ffi'

git-svn-id: https://svn.codehaus.org/jruby/trunk/jruby@7271 
961051c9-f516-0410-bf72-c9f7e237a7b7
wmeissner (author)
Wed Jul 23 05:02:45 -0700 2008
commit  f0be9bbac71daf73dee5b7ab235c745fa1b75759
tree    ca42a9c23215d38fa581f073e38966ecc8bba9c9
parent  5745080d137e5a19f3a09ee82828725242240dad
...
204
205
206
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
209
210
 
 
 
 
 
 
 
 
 
 
 
 
 
211
212
213
...
583
584
585
586
 
587
588
589
...
204
205
206
 
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
 
 
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
617
618
619
 
620
621
622
623
0
@@ -204,10 +204,44 @@ module JFFI
0
 
0
   # Use for a C struct with a char [] embedded inside.
0
   add_typedef(NativeType::CHAR_ARRAY, :char_array)
0
-  
0
+
0
+  # Load all the platform dependent types/consts/struct members
0
+  class Config
0
+    CONFIG = Hash.new
0
+    begin
0
+      File.open(File.join(Platform::CONF_DIR, 'platform.conf'), "r") do |f|
0
+        typedef = "rbx.platform.typedef."
0
+        f.each_line { |line|
0
+          if line.index(typedef) == 0
0
+            new_type, orig_type = line.chomp.slice(typedef.length..-1).split(/\s*=\s*/)
0
+            JFFI.add_typedef(orig_type.to_sym, new_type.to_sym)
0
+          else
0
+            key, value = line.chomp.split(/\s*=\s*/)
0
+            puts "key=#{key} value=#{value}"
0
+            CONFIG[key] = value
0
+          end
0
+        }
0
+      end
0
+    rescue Errno::ENOENT
0
+    end
0
+    def self.[](name)
0
+
0
+    end
0
+  end
0
   # Load all the platform dependent types
0
-  require "ffi/platform/#{Config::CONFIG['host_os']}"
0
-  PlatformTypes.each_pair { |k, v| add_typedef(v.to_sym, k.to_sym) }
0
+  begin
0
+    File.open(File.join(Platform::CONF_DIR, 'types.conf'), "r") do |f|
0
+      prefix = "rbx.platform.typedef."
0
+      f.each_line { |line|
0
+        if line.index(prefix) == 0
0
+          new_type, orig_type = line.chomp.slice(prefix.length..-1).split(/\s*=\s*/)
0
+#          puts "new type=#{new_type} orig_type=#{orig_type}"
0
+          add_typedef(orig_type.to_sym, new_type.to_sym)
0
+        end
0
+      }
0
+    end
0
+  rescue Errno::ENOENT
0
+  end
0
   
0
   TypeSizes = {
0
     1 => :char,
0
@@ -583,7 +617,7 @@ class FFI::Struct < JFFI::BaseStruct
0
   end
0
 
0
   def self.config(base, *fields)
0
-    config = Config::CONFIG
0
+    config = JFFI::Config::CONFIG
0
     @size = config["#{base}.sizeof"]
0
     
0
     builder = JFFI::StructLayoutBuilder.new
...
41
42
43
 
 
 
 
 
 
 
 
44
45
46
...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
0
@@ -41,5 +41,13 @@ module JFFI
0
     IS_SOLARIS = OS_NAME_LC.index(SOLARIS) == 0
0
     IS_BSD = IS_MAC || IS_FREEBSD
0
     ARCH = java.lang.System.getProperty("os.arch")
0
+    NAME = if IS_WINDOWS
0
+      "#{ARCH}-windows"
0
+    elsif IS_MAC
0
+      "darwin"
0
+    elsif IS_FREEBSD
0
+      "#{ARCH}-freebsd"
0
+    end
0
+    CONF_DIR = File.join(File.dirname(__FILE__), "platform", NAME)
0
   end
0
 end
0
\ No newline at end of file

Comments