diff options
author | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 09:00:23 +0000 |
---|---|---|
committer | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-04 09:00:23 +0000 |
commit | 7b103012dc9fa53f138ea7aa6db9133a3f02081b (patch) | |
tree | c175b8541750d95d0c50aa195d82ff8f1af02b29 /ext | |
parent | b2e6a26a37b3a97b725c69087a6384c0e6fc0bde (diff) |
* ext/fiddle/lib/fiddle/import.rb (import_function, bind_function):
should respect call_type for migration from DL to Fiddle.
[Bug #7484] [ruby-core:50405]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fiddle/lib/fiddle/import.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/fiddle/lib/fiddle/import.rb b/ext/fiddle/lib/fiddle/import.rb index ba0f716a9a..67deedd7ad 100644 --- a/ext/fiddle/lib/fiddle/import.rb +++ b/ext/fiddle/lib/fiddle/import.rb @@ -147,6 +147,14 @@ module Fiddle end private :parse_bind_options + CALL_TYPE_TO_ABI = Hash.new { |h, k| + raise RuntimeError, "unsupported call type: #{k}" + }.merge({ :stdcall => (Function::STDCALL rescue Function::DEFAULT), + :cdecl => Function::DEFAULT, + nil => Function::DEFAULT + }).freeze + private_constant :CALL_TYPE_TO_ABI + # Creates a global method from the given C +signature+. def extern(signature, *opts) symname, ctype, argtype = parse_signature(signature, @type_alias) @@ -280,7 +288,7 @@ module Fiddle if( !addr ) raise(DLError, "cannot find the function: #{name}()") end - Function.new(addr, argtype, ctype, call_type) + Function.new(addr, argtype, ctype, CALL_TYPE_TO_ABI[call_type]) end # Returns a new closure wrapper for the +name+ function. @@ -292,11 +300,12 @@ module Fiddle # # See Fiddle::Closure def bind_function(name, ctype, argtype, call_type = nil, &block) + abi = CALL_TYPE_TO_ABI[call_type] closure = Class.new(Fiddle::Closure) { define_method(:call, block) - }.new(ctype, argtype) + }.new(ctype, argtype, abi) - Function.new(closure, argtype, ctype) + Function.new(closure, argtype, ctype, abi) end end end |