[前][次][番号順一覧][スレッド一覧]

ruby-changes:60150

From: Nobuyoshi <ko1@a...>
Date: Sat, 22 Feb 2020 00:45:32 +0900 (JST)
Subject: [ruby-changes:60150] 8c5ca318cb (master): `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]

https://git.ruby-lang.org/ruby.git/commit/?id=8c5ca318cb

From 8c5ca318cbe57269f144a4d0822c5283c1fd4e1a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 22 Feb 2020 00:32:43 +0900
Subject: `Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]

With refinements, too.

diff --git a/internal/proc.h b/internal/proc.h
index 7f2bec8..8643929 100644
--- a/internal/proc.h
+++ b/internal/proc.h
@@ -19,11 +19,11 @@ VALUE rb_proc_location(VALUE self); https://github.com/ruby/ruby/blob/trunk/internal/proc.h#L19
 st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
 int rb_block_arity(void);
 int rb_block_min_max_arity(int *max);
-VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc);
 VALUE rb_block_to_s(VALUE self, const struct rb_block *block, const char *additional_info);
 
 MJIT_SYMBOL_EXPORT_BEGIN
 VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val);
+VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc);
 VALUE rb_iseq_location(const struct rb_iseq_struct *iseq);
 VALUE rb_sym_to_proc(VALUE sym);
 MJIT_SYMBOL_EXPORT_END
diff --git a/proc.c b/proc.c
index e0cba71..7fee55b 100644
--- a/proc.c
+++ b/proc.c
@@ -739,7 +739,7 @@ rb_func_proc_new(rb_block_call_func_t func, VALUE val) https://github.com/ruby/ruby/blob/trunk/proc.c#L739
     return cfunc_proc_new(rb_cProc, (VALUE)ifunc, 0);
 }
 
-VALUE
+MJIT_FUNC_EXPORTED VALUE
 rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
 {
     struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (void *)val, min_argc, max_argc);
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index 2e9710e..632acb3 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -169,6 +169,9 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L169
   def _test_to_proc_arg_with_refinements_call(&block)
     block.call TestToPRocArgWithRefinements.new
   end
+  def _test_to_proc_with_refinements_call(&block)
+    block
+  end
   using Module.new {
     refine TestToPRocArgWithRefinements do
       def hoge
@@ -180,6 +183,10 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L183
     assert_equal(:hoge, _test_to_proc_arg_with_refinements_call(&:hoge))
   end
 
+  def test_to_proc_lambda_with_refinements
+    assert_predicate(_test_to_proc_with_refinements_call(&:hoge), :lambda?)
+  end
+
   def self._test_to_proc_arg_with_refinements_call(&block)
     block.call TestToPRocArgWithRefinements.new
   end
diff --git a/vm_args.c b/vm_args.c
index 13d4e4a..b3f1611 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -869,7 +869,7 @@ vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t * https://github.com/ruby/ruby/blob/trunk/vm_args.c#L869
                     rb_ary_push(callback_arg, block_code);
                     rb_ary_push(callback_arg, ref);
                     OBJ_FREEZE_RAW(callback_arg);
-                    func = rb_func_proc_new(refine_sym_proc_call, callback_arg);
+                    func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 0, UNLIMITED_ARGUMENTS);
 		    rb_hash_aset(ref, block_code, func);
 		}
 		block_code = func;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]