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

ruby-changes:59073

From: Jeremy <ko1@a...>
Date: Thu, 5 Dec 2019 10:05:07 +0900 (JST)
Subject: [ruby-changes:59073] e4db0443bc (master): Make rb_eval_string_wrap specify a cref so constant setting works correctly

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

From e4db0443bcfc94f9183e8ea72fb4ab560aa005bf Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Mon, 22 Jul 2019 19:56:02 -0700
Subject: Make rb_eval_string_wrap specify a cref so constant setting works
 correctly

Fixes [Bug #10466]

diff --git a/vm_eval.c b/vm_eval.c
index 1f3042d..b017942 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1740,6 +1740,21 @@ rb_eval_string_protect(const char *str, int *pstate) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1740
     return rb_protect(eval_string_protect, (VALUE)str, pstate);
 }
 
+struct eval_string_wrap_arg {
+    VALUE top_self;
+    VALUE klass;
+    const char *str;
+};
+
+static VALUE
+eval_string_wrap_protect(VALUE data)
+{
+    const struct eval_string_wrap_arg *const arg = (struct eval_string_wrap_arg*)data;
+    rb_cref_t *cref = rb_vm_cref_new_toplevel();
+    cref->klass = arg->klass;
+    return eval_string_with_cref(arg->top_self, rb_str_new_cstr(arg->str), cref, rb_str_new_cstr("eval"), 1);
+}
+
 /**
  * Evaluates the given string under a module binding in an isolated binding.
  * This is same as the binding for loaded libraries on "load('foo', true)".
@@ -1759,12 +1774,17 @@ rb_eval_string_wrap(const char *str, int *pstate) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1774
     VALUE self = th->top_self;
     VALUE wrapper = th->top_wrapper;
     VALUE val;
+    struct eval_string_wrap_arg data;
 
     th->top_wrapper = rb_module_new();
     th->top_self = rb_obj_clone(rb_vm_top_self());
     rb_extend_object(th->top_self, th->top_wrapper);
 
-    val = rb_eval_string_protect(str, &state);
+    data.top_self = th->top_self;
+    data.klass = th->top_wrapper;
+    data.str = str;
+
+    val = rb_protect(eval_string_wrap_protect, (VALUE)&data, &state);
 
     th->top_self = self;
     th->top_wrapper = wrapper;
-- 
cgit v0.10.2


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

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