summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-02-26 10:06:30 -0800
committerAaron Patterson <tenderlove@ruby-lang.org>2021-02-26 10:06:56 -0800
commitd45466dc5b9b45d5b78d161fc86265e6e19d6e1e (patch)
treee27eb3ec290f92733c27078805f2a44fe723c21a
parent3d8e373a588bca976f7f1a8172b5b1b27d78f60f (diff)
Oops! Add another test and fix to_proc implementation
-rw-r--r--ext/fiddle/lib/fiddle/function.rb3
-rw-r--r--test/fiddle/test_function.rb11
2 files changed, 13 insertions, 1 deletions
diff --git a/ext/fiddle/lib/fiddle/function.rb b/ext/fiddle/lib/fiddle/function.rb
index f9910a0524..dc2e3e6bf5 100644
--- a/ext/fiddle/lib/fiddle/function.rb
+++ b/ext/fiddle/lib/fiddle/function.rb
@@ -22,7 +22,8 @@ module Fiddle
# Turn this function in to a proc
def to_proc
- lambda { |*args| self.call(*args) }
+ this = self
+ lambda { |*args| this.call(*args) }
end
end
end
diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb
index 5dc456b82b..a5284e093a 100644
--- a/test/fiddle/test_function.rb
+++ b/test/fiddle/test_function.rb
@@ -115,6 +115,17 @@ module Fiddle
assert_equal("123", str.to_s)
end
+ def test_function_as_method
+ f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
+ klass = Class.new do
+ define_singleton_method(:strcpy, &f)
+ end
+ buff = +"000"
+ str = klass.strcpy(buff, "123")
+ assert_equal("123", buff)
+ assert_equal("123", str.to_s)
+ end
+
def test_nogvl_poll
# XXX hack to quiet down CI errors on EINTR from r64353
# [ruby-core:88360] [Misc #14937]