* ext/dl/lib/dl/func.rb (DL::Function#unbind, #bound?): suppress NoMethodError when Fiddle is available. [ruby-core:50756] [Bug #7543]
* test/dl/test_func.rb (test_bound*, test_unbind*): tests for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
80e1f46ff0
commit
1fcde7c2e2
@ -1,3 +1,9 @@
|
|||||||
|
Wed Dec 12 00:13:34 2012 Naohisa Goto <ngotogenome@gmail.com>
|
||||||
|
|
||||||
|
* ext/dl/lib/dl/func.rb (DL::Function#unbind, #bound?): suppress
|
||||||
|
NoMethodError when Fiddle is available. [ruby-core:50756] [Bug #7543]
|
||||||
|
* test/dl/test_func.rb (test_bound*, test_unbind*): tests for the above.
|
||||||
|
|
||||||
Tue Dec 11 19:38:37 2012 Naohisa Goto <ngotogenome@gmail.com>
|
Tue Dec 11 19:38:37 2012 Naohisa Goto <ngotogenome@gmail.com>
|
||||||
|
|
||||||
* ext/fiddle/function.c (Fiddle::Function.new): new keyword argument
|
* ext/fiddle/function.c (Fiddle::Function.new): new keyword argument
|
||||||
|
@ -36,6 +36,9 @@ module DL
|
|||||||
def name
|
def name
|
||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
|
def ptr
|
||||||
|
to_i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private_constant :FiddleClosureCFunc
|
private_constant :FiddleClosureCFunc
|
||||||
|
|
||||||
@ -157,6 +160,25 @@ module DL
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unbind()
|
def unbind()
|
||||||
|
if DL.fiddle? then
|
||||||
|
if @cfunc.kind_of?(Fiddle::Closure) and @cfunc.ptr != 0 then
|
||||||
|
call_type = case abi
|
||||||
|
when CALL_TYPE_TO_ABI[nil]
|
||||||
|
nil
|
||||||
|
when CALL_TYPE_TO_ABI[:stdcall]
|
||||||
|
:stdcall
|
||||||
|
else
|
||||||
|
raise(RuntimeError, "unsupported abi: #{abi}")
|
||||||
|
end
|
||||||
|
@cfunc = CFunc.new(0, @cfunc.ctype, name, call_type)
|
||||||
|
return 0
|
||||||
|
elsif @cfunc.ptr != 0 then
|
||||||
|
@cfunc.ptr = 0
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
if( @cfunc.ptr != 0 )
|
if( @cfunc.ptr != 0 )
|
||||||
case @cfunc.calltype
|
case @cfunc.calltype
|
||||||
when :cdecl
|
when :cdecl
|
||||||
|
@ -15,6 +15,49 @@ module DL
|
|||||||
assert_equal('<callback>qsort', cb.name)
|
assert_equal('<callback>qsort', cb.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_bound
|
||||||
|
f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
|
||||||
|
assert_equal false, f.bound?
|
||||||
|
begin
|
||||||
|
f.bind { |x,y| x + y }
|
||||||
|
assert_equal true, f.bound?
|
||||||
|
ensure
|
||||||
|
f.unbind # max number of callbacks is limited to MAX_CALLBACK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bound_for_callback_closure
|
||||||
|
begin
|
||||||
|
f = Function.new(CFunc.new(0, TYPE_INT, 'test'),
|
||||||
|
[TYPE_INT, TYPE_INT]) { |x,y| x + y }
|
||||||
|
assert_equal true, f.bound?
|
||||||
|
ensure
|
||||||
|
f.unbind if f # max number of callbacks is limited to MAX_CALLBACK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unbind
|
||||||
|
f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
|
||||||
|
begin
|
||||||
|
f.bind { |x, y| x + y }
|
||||||
|
assert_nothing_raised { f.unbind }
|
||||||
|
assert_equal false, f.bound?
|
||||||
|
# unbind() after unbind() should not raise error
|
||||||
|
assert_nothing_raised { f.unbind }
|
||||||
|
ensure
|
||||||
|
f.unbind # max number of callbacks is limited to MAX_CALLBACK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unbind_normal_function
|
||||||
|
f = Function.new(CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy'),
|
||||||
|
[TYPE_VOIDP, TYPE_VOIDP])
|
||||||
|
assert_nothing_raised { f.unbind }
|
||||||
|
assert_equal false, f.bound?
|
||||||
|
# unbind() after unbind() should not raise error
|
||||||
|
assert_nothing_raised { f.unbind }
|
||||||
|
end
|
||||||
|
|
||||||
def test_bind
|
def test_bind
|
||||||
f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
|
f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
|
||||||
assert_nothing_raised {
|
assert_nothing_raised {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user