summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-15 10:52:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-15 10:52:31 +0000
commitfa65df0d084077f6766c8a2580016de49cbf42f9 (patch)
tree97e76882107593c9a0c8b3d2d13f6da3eafd2900
parentdf5867a2a7f08af8239b4c7a1eaf961bd9019c11 (diff)
* ext/fiddle/closure.c (callback): same as r34506.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/fiddle/closure.c2
-rw-r--r--test/fiddle/test_closure.rb25
3 files changed, 30 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c649166b95a..5331ddca684 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Feb 15 19:52:28 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/fiddle/closure.c (callback): same as r34506.
+
Wed Feb 15 17:41:31 2012 NARUSE, Yui <naruse@ruby-lang.org>
* io.c (io_strsetbuf): call rb_str_modify to make str independent
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
index 962f9267fef..c601818ad40 100644
--- a/ext/fiddle/closure.c
+++ b/ext/fiddle/closure.c
@@ -125,7 +125,7 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
break;
#if HAVE_LONG_LONG
case TYPE_LONG_LONG:
- *(unsigned LONG_LONG *)resp = rb_big2ull(ret);
+ *(unsigned LONG_LONG *)resp = NUM2ULL(ret);
break;
#endif
default:
diff --git a/test/fiddle/test_closure.rb b/test/fiddle/test_closure.rb
index 5878e72a708..381b3f96c16 100644
--- a/test/fiddle/test_closure.rb
+++ b/test/fiddle/test_closure.rb
@@ -55,5 +55,30 @@ module Fiddle
n = 10000
assert_equal(n, n.times {ObjectSpace.memsize_of(Closure.allocate)}, bug)
end
+
+ %w[INT SHORT CHAR LONG LONG_LONG].each do |name|
+ type = DL.const_get("TYPE_#{name}") rescue next
+ size = DL.const_get("SIZEOF_#{name}")
+ [[type, size-1, name], [-type, size, "unsigned_"+name]].each do |t, s, n|
+ define_method("test_conversion_#{n.downcase}") do
+ arg = nil
+
+ clos = Class.new(Closure) do
+ define_method(:call) {|x| arg = x}
+ end.new(t, [t])
+
+ v = ~(~0 << (8*s))
+
+ arg = nil
+ assert_equal(v, clos.call(v))
+ assert_equal(arg, v, n)
+
+ arg = nil
+ func = Function.new(clos, [t], t)
+ assert_equal(v, func.call(v))
+ assert_equal(arg, v, n)
+ end
+ end
+ end
end
end if defined?(Fiddle)