1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ngoto 2012-12-04 09:00:23 +00:00
parent b2e6a26a37
commit 7b103012dc
2 changed files with 18 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Tue Dec 4 17:57:09 2012 Naohisa Goto <ngotogenome@gmail.com>
* 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]
Tue Dec 4 16:54:00 2012 Eric Hodel <drbrain@segment7.net> Tue Dec 4 16:54:00 2012 Eric Hodel <drbrain@segment7.net>
* .document: Added ChangeLog and doc/ChangeLog-* as documentation * .document: Added ChangeLog and doc/ChangeLog-* as documentation

View file

@ -147,6 +147,14 @@ module Fiddle
end end
private :parse_bind_options 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+. # Creates a global method from the given C +signature+.
def extern(signature, *opts) def extern(signature, *opts)
symname, ctype, argtype = parse_signature(signature, @type_alias) symname, ctype, argtype = parse_signature(signature, @type_alias)
@ -280,7 +288,7 @@ module Fiddle
if( !addr ) if( !addr )
raise(DLError, "cannot find the function: #{name}()") raise(DLError, "cannot find the function: #{name}()")
end end
Function.new(addr, argtype, ctype, call_type) Function.new(addr, argtype, ctype, CALL_TYPE_TO_ABI[call_type])
end end
# Returns a new closure wrapper for the +name+ function. # Returns a new closure wrapper for the +name+ function.
@ -292,11 +300,12 @@ module Fiddle
# #
# See Fiddle::Closure # See Fiddle::Closure
def bind_function(name, ctype, argtype, call_type = nil, &block) def bind_function(name, ctype, argtype, call_type = nil, &block)
abi = CALL_TYPE_TO_ABI[call_type]
closure = Class.new(Fiddle::Closure) { closure = Class.new(Fiddle::Closure) {
define_method(:call, block) 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 end
end end