Skip to content

Commit

Permalink
Merge pull request #1605 from jeremyz/master
Browse files Browse the repository at this point in the history
FFI compatibility enhancement
  • Loading branch information
evanphx committed Mar 14, 2012
2 parents 2406057 + e69781c commit 0b8b633
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 101 deletions.
5 changes: 5 additions & 0 deletions kernel/platform/enum.rb
Expand Up @@ -52,5 +52,10 @@ def [](sym)
@kv_map[sym]
end

def symbol(value)
key,val = @kv_map.detect { |key,val| val==value }
return key
end

end
end
16 changes: 8 additions & 8 deletions kernel/platform/library.rb
Expand Up @@ -230,17 +230,16 @@ def callback(a1, a2, a3=nil)

def typedef(old, add)
@typedefs ||= Rubinius::LookupTable.new

unless old.kind_of? Rubinius::NativeFunction
old = find_type(old)
end

@typedefs[add] = old
@typedefs[add] = find_type(old)
end

def find_type(name)
@typedefs ||= Rubinius::LookupTable.new

if name.kind_of? Rubinius::NativeFunction or name.kind_of? FFI::Enum
return name
end

if type = @typedefs[name]
return type
end
Expand All @@ -263,7 +262,7 @@ def enum(*args)
enum = FFI::Enum.new values, tag

if tag
typedef(:int, tag)
typedef(enum, tag)
@tagged_enums[tag] = enum
else
@anon_enums << enum
Expand All @@ -287,7 +286,8 @@ def enum_value(value)
if enum = @anon_enums.detect { |enum| enum.symbols.include?(value) }
enum
else
@tagged_enums.detect { |tag,enum| enum.symbols.include?(value) }
tag,enum = @tagged_enums.detect { |tag,enum| enum.symbols.include?(value) }
return enum
end

end
Expand Down
2 changes: 1 addition & 1 deletion kernel/platform/load_order18.txt
@@ -1,4 +1,5 @@
ffi.rbc
enum.rbc
library.rbc
pointer_accessors.rbc
pointer.rbc
Expand All @@ -7,4 +8,3 @@ file.rbc
math.rbc
posix.rbc
struct.rbc
enum.rbc
2 changes: 1 addition & 1 deletion kernel/platform/load_order19.txt
@@ -1,4 +1,5 @@
ffi.rbc
enum.rbc
library.rbc
pointer_accessors.rbc
pointer.rbc
Expand All @@ -8,4 +9,3 @@ math.rbc
math19.rbc
posix.rbc
struct.rbc
enum.rbc
1 change: 1 addition & 0 deletions kernel/platform/load_order20.txt
@@ -1,4 +1,5 @@
ffi.rbc
enum.rbc
library.rbc
pointer_accessors.rbc
pointer.rbc
Expand Down

0 comments on commit 0b8b633

Please sign in to comment.