зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
df5867a2a7
Коммит
fa65df0d08
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче