From 7b103012dc9fa53f138ea7aa6db9133a3f02081b Mon Sep 17 00:00:00 2001 From: ngoto Date: Tue, 4 Dec 2012 09:00:23 +0000 Subject: * 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 --- ext/fiddle/lib/fiddle/import.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'ext/fiddle/lib/fiddle') 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 -- cgit v1.2.3