ruby-changes:65351
From: Aaron <ko1@a...>
Date: Sat, 27 Feb 2021 03:07:10 +0900 (JST)
Subject: [ruby-changes:65351] d45466dc5b (master): Oops! Add another test and fix to_proc implementation
https://git.ruby-lang.org/ruby.git/commit/?id=d45466dc5b From d45466dc5b9b45d5b78d161fc86265e6e19d6e1e Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Fri, 26 Feb 2021 10:06:30 -0800 Subject: Oops! Add another test and fix to_proc implementation --- ext/fiddle/lib/fiddle/function.rb | 3 ++- test/fiddle/test_function.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ext/fiddle/lib/fiddle/function.rb b/ext/fiddle/lib/fiddle/function.rb index f9910a0..dc2e3e6 100644 --- a/ext/fiddle/lib/fiddle/function.rb +++ b/ext/fiddle/lib/fiddle/function.rb @@ -22,7 +22,8 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/ext/fiddle/lib/fiddle/function.rb#L22 # 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 5dc456b..a5284e0 100644 --- a/test/fiddle/test_function.rb +++ b/test/fiddle/test_function.rb @@ -115,6 +115,17 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L115 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] -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/