[前][次][番号順一覧][スレッド一覧]

ruby-changes:26125

From: ngoto <ko1@a...>
Date: Tue, 4 Dec 2012 18:03:49 +0900 (JST)
Subject: [ruby-changes:26125] ngoto:r38182 (trunk): * ext/fiddle/lib/fiddle/import.rb (import_function, bind_function):

ngoto	2012-12-04 18:00:23 +0900 (Tue, 04 Dec 2012)

  New Revision: 38182

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38182

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/ext/fiddle/lib/fiddle/import.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38181)
+++ ChangeLog	(revision 38182)
@@ -1,3 +1,9 @@
+Tue Dec  4 17:57:09 2012  Naohisa Goto  <ngotogenome@g...>
+
+	* 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@s...>
 
 	* .document:  Added ChangeLog and doc/ChangeLog-* as documentation
Index: ext/fiddle/lib/fiddle/import.rb
===================================================================
--- ext/fiddle/lib/fiddle/import.rb	(revision 38181)
+++ ext/fiddle/lib/fiddle/import.rb	(revision 38182)
@@ -147,6 +147,14 @@
     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 @@
       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 @@
     #
     # 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]