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

ruby-changes:69831

From: Nobuyoshi <ko1@a...>
Date: Sun, 21 Nov 2021 01:35:45 +0900 (JST)
Subject: [ruby-changes:69831] 8f3432cd44 (master): Fix setting struct member by public_send

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

From 8f3432cd4466c35cd9f482de3779d76f3957968f Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 21 Nov 2021 00:31:51 +0900
Subject: Fix setting struct member by public_send

---
 test/ruby/test_struct.rb | 8 ++++++++
 vm_eval.c                | 4 ++--
 vm_insnhelper.c          | 9 ++++-----
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 19577266c74..03016123953 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -489,6 +489,14 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L489
     }
   end
 
+  def test_public_send
+    klass = @Struct.new(:a)
+    x = klass.new(1)
+    assert_equal(1, x.public_send("a"))
+    assert_equal(42, x.public_send("a=", 42))
+    assert_equal(42, x.public_send("a"))
+  end
+
   class TopStruct < Test::Unit::TestCase
     include TestStruct
 
diff --git a/vm_eval.c b/vm_eval.c
index 140912f218a..983baf7de67 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -275,11 +275,11 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L275
 	    }
           case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
             vm_call_check_arity(calling, 0, argv);
-            ret = vm_call_opt_struct_aref0(ec, ec->cfp, calling);
+            ret = vm_call_opt_struct_aref0(ec, calling);
             goto success;
           case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
             vm_call_check_arity(calling, 1, argv);
-            ret = vm_call_opt_struct_aset0(ec, ec->cfp, calling);
+            ret = vm_call_opt_struct_aset0(ec, calling, argv[0]);
             goto success;
 	  default:
 	    rb_bug("vm_call0: unsupported optimized method type (%d)", vm_cc_cme(cc)->def->body.optimized.type);
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index baf77acb143..d1930d146c9 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3531,7 +3531,7 @@ vm_call_opt_block_call(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3531
 }
 
 static VALUE
-vm_call_opt_struct_aref0(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling)
+vm_call_opt_struct_aref0(rb_execution_context_t *ec, struct rb_calling_info *calling)
 {
     VALUE recv = calling->recv;
 
@@ -3548,16 +3548,15 @@ vm_call_opt_struct_aref(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3548
 {
     RB_DEBUG_COUNTER_INC(ccf_opt_struct_aref);
 
-    VALUE ret = vm_call_opt_struct_aref0(ec, reg_cfp, calling);
+    VALUE ret = vm_call_opt_struct_aref0(ec, calling);
     reg_cfp->sp -= 1;
     return ret;
 }
 
 static VALUE
-vm_call_opt_struct_aset0(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling)
+vm_call_opt_struct_aset0(rb_execution_context_t *ec, struct rb_calling_info *calling, VALUE val)
 {
     VALUE recv = calling->recv;
-    VALUE val = *(reg_cfp->sp - 1);
 
     VM_ASSERT(RB_TYPE_P(recv, T_STRUCT));
     VM_ASSERT(vm_cc_cme(calling->cc)->def->type == VM_METHOD_TYPE_OPTIMIZED);
@@ -3576,7 +3575,7 @@ vm_call_opt_struct_aset(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3575
 {
     RB_DEBUG_COUNTER_INC(ccf_opt_struct_aset);
 
-    VALUE ret = vm_call_opt_struct_aset0(ec, reg_cfp, calling);
+    VALUE ret = vm_call_opt_struct_aset0(ec, calling, *(reg_cfp->sp - 1));
     reg_cfp->sp -= 2;
     return ret;
 }
-- 
cgit v1.2.1


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

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