mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 49922,50111,50112: [Backport #11012]
* proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not. * vm.c: ditto. * vm_dump.c: ditto. * vm_insnhelper.c: ditto. * vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE(). * proc.c (proc_binding): replicate env from method object, and allocate the local variable area for the iseq local table. [ruby-core:68673] [Bug #11012] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3f1fc07e05
commit
9eb78a2138
8 changed files with 62 additions and 12 deletions
18
ChangeLog
18
ChangeLog
|
|
@ -1,3 +1,21 @@
|
||||||
|
Wed May 20 03:25:34 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* proc.c (proc_binding): replicate env from method object, and
|
||||||
|
allocate the local variable area for the iseq local table.
|
||||||
|
[ruby-core:68673] [Bug #11012]
|
||||||
|
|
||||||
|
Wed May 20 03:25:34 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not.
|
||||||
|
|
||||||
|
* vm.c: ditto.
|
||||||
|
|
||||||
|
* vm_dump.c: ditto.
|
||||||
|
|
||||||
|
* vm_insnhelper.c: ditto.
|
||||||
|
|
||||||
|
* vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE().
|
||||||
|
|
||||||
Wed May 20 03:10:49 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed May 20 03:10:49 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* benchmark/bm_hash_aref_flo.rb: make more realistic data.
|
* benchmark/bm_hash_aref_flo.rb: make more realistic data.
|
||||||
|
|
|
||||||
30
proc.c
30
proc.c
|
|
@ -719,7 +719,7 @@ proc_call(int argc, VALUE *argv, VALUE procval)
|
||||||
GetProcPtr(procval, proc);
|
GetProcPtr(procval, proc);
|
||||||
|
|
||||||
iseq = proc->block.iseq;
|
iseq = proc->block.iseq;
|
||||||
if (BUILTIN_TYPE(iseq) == T_NODE || iseq->param.flags.has_block) {
|
if (RUBY_VM_IFUNC_P(iseq) || iseq->param.flags.has_block) {
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
rb_proc_t *passed_proc;
|
rb_proc_t *passed_proc;
|
||||||
RB_GC_GUARD(passed_procval) = rb_block_proc();
|
RB_GC_GUARD(passed_procval) = rb_block_proc();
|
||||||
|
|
@ -843,7 +843,7 @@ rb_block_min_max_arity(rb_block_t *block, int *max)
|
||||||
{
|
{
|
||||||
rb_iseq_t *iseq = block->iseq;
|
rb_iseq_t *iseq = block->iseq;
|
||||||
if (iseq) {
|
if (iseq) {
|
||||||
if (BUILTIN_TYPE(iseq) != T_NODE) {
|
if (!RUBY_VM_IFUNC_P(iseq)) {
|
||||||
return rb_iseq_min_max_arity(iseq, max);
|
return rb_iseq_min_max_arity(iseq, max);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -1717,7 +1717,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
|
||||||
rb_proc_t *proc;
|
rb_proc_t *proc;
|
||||||
body = proc_dup(body);
|
body = proc_dup(body);
|
||||||
GetProcPtr(body, proc);
|
GetProcPtr(body, proc);
|
||||||
if (BUILTIN_TYPE(proc->block.iseq) != T_NODE) {
|
if (!RUBY_VM_IFUNC_P(proc->block.iseq)) {
|
||||||
proc->block.iseq->defined_method_id = id;
|
proc->block.iseq->defined_method_id = id;
|
||||||
RB_OBJ_WRITE(proc->block.iseq->self, &proc->block.iseq->klass, mod);
|
RB_OBJ_WRITE(proc->block.iseq->self, &proc->block.iseq->klass, mod);
|
||||||
proc->is_lambda = TRUE;
|
proc->is_lambda = TRUE;
|
||||||
|
|
@ -2477,22 +2477,40 @@ static VALUE
|
||||||
proc_binding(VALUE self)
|
proc_binding(VALUE self)
|
||||||
{
|
{
|
||||||
rb_proc_t *proc;
|
rb_proc_t *proc;
|
||||||
VALUE bindval;
|
VALUE bindval, envval;
|
||||||
rb_binding_t *bind;
|
rb_binding_t *bind;
|
||||||
rb_iseq_t *iseq;
|
rb_iseq_t *iseq;
|
||||||
|
|
||||||
GetProcPtr(self, proc);
|
GetProcPtr(self, proc);
|
||||||
|
envval = proc->envval;
|
||||||
iseq = proc->block.iseq;
|
iseq = proc->block.iseq;
|
||||||
if (RB_TYPE_P((VALUE)iseq, T_NODE)) {
|
if (RUBY_VM_IFUNC_P(iseq)) {
|
||||||
|
rb_env_t *env;
|
||||||
if (!IS_METHOD_PROC_NODE((NODE *)iseq)) {
|
if (!IS_METHOD_PROC_NODE((NODE *)iseq)) {
|
||||||
rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
|
rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
|
||||||
}
|
}
|
||||||
iseq = rb_method_get_iseq(RNODE(iseq)->u2.value);
|
iseq = rb_method_get_iseq(RNODE(iseq)->u2.value);
|
||||||
|
GetEnvPtr(envval, env);
|
||||||
|
if (iseq && env->local_size < iseq->local_size) {
|
||||||
|
int prev_local_size = env->local_size;
|
||||||
|
int local_size = iseq->local_size;
|
||||||
|
VALUE newenvval = TypedData_Wrap_Struct(RBASIC_CLASS(envval), RTYPEDDATA_TYPE(envval), 0);
|
||||||
|
rb_env_t *newenv = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
|
||||||
|
RTYPEDDATA_DATA(newenvval) = newenv;
|
||||||
|
newenv->env_size = local_size + 2;
|
||||||
|
newenv->local_size = local_size;
|
||||||
|
newenv->prev_envval = env->prev_envval;
|
||||||
|
newenv->block = env->block;
|
||||||
|
MEMCPY(newenv->env, env->env, VALUE, prev_local_size + 1);
|
||||||
|
rb_mem_clear(newenv->env + prev_local_size + 1, local_size - prev_local_size);
|
||||||
|
newenv->env[local_size + 1] = newenvval;
|
||||||
|
envval = newenvval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindval = rb_binding_alloc(rb_cBinding);
|
bindval = rb_binding_alloc(rb_cBinding);
|
||||||
GetBindingPtr(bindval, bind);
|
GetBindingPtr(bindval, bind);
|
||||||
bind->env = proc->envval;
|
bind->env = envval;
|
||||||
bind->blockprocval = proc->blockprocval;
|
bind->blockprocval = proc->blockprocval;
|
||||||
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
|
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
|
||||||
bind->path = iseq->location.path;
|
bind->path = iseq->location.path;
|
||||||
|
|
|
||||||
|
|
@ -877,4 +877,18 @@ class TestMethod < Test::Unit::TestCase
|
||||||
obj.bar
|
obj.bar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_to_proc_binding
|
||||||
|
bug11012 = '[ruby-core:68673] [Bug #11012]'
|
||||||
|
class << (obj = Object.new)
|
||||||
|
src = 1000.times.map {|i|"v#{i} = nil"}.join("\n")
|
||||||
|
eval("def foo()\n""#{src}\n""end")
|
||||||
|
end
|
||||||
|
|
||||||
|
b = obj.method(:foo).to_proc.binding
|
||||||
|
b.local_variables.each_with_index {|n, i|
|
||||||
|
b.local_variable_set(n, i)
|
||||||
|
}
|
||||||
|
assert_equal([998, 999], %w[v998 v999].map {|n| b.local_variable_get(n)}, bug11012)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.2.3"
|
#define RUBY_VERSION "2.2.3"
|
||||||
#define RUBY_RELEASE_DATE "2015-05-20"
|
#define RUBY_RELEASE_DATE "2015-05-20"
|
||||||
#define RUBY_PATCHLEVEL 107
|
#define RUBY_PATCHLEVEL 108
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2015
|
#define RUBY_RELEASE_YEAR 2015
|
||||||
#define RUBY_RELEASE_MONTH 5
|
#define RUBY_RELEASE_MONTH 5
|
||||||
|
|
|
||||||
4
vm.c
4
vm.c
|
|
@ -380,7 +380,7 @@ env_mark(void * const ptr)
|
||||||
RUBY_MARK_UNLESS_NULL(env->block.proc);
|
RUBY_MARK_UNLESS_NULL(env->block.proc);
|
||||||
|
|
||||||
if (env->block.iseq) {
|
if (env->block.iseq) {
|
||||||
if (BUILTIN_TYPE(env->block.iseq) == T_NODE) {
|
if (RUBY_VM_IFUNC_P(env->block.iseq)) {
|
||||||
RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq);
|
RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -768,7 +768,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
|
||||||
if (SPECIAL_CONST_P(block->iseq)) {
|
if (SPECIAL_CONST_P(block->iseq)) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
else if (BUILTIN_TYPE(block->iseq) != T_NODE) {
|
else if (!RUBY_VM_IFUNC_P(block->iseq)) {
|
||||||
VALUE ret;
|
VALUE ret;
|
||||||
const rb_iseq_t *iseq = block->iseq;
|
const rb_iseq_t *iseq = block->iseq;
|
||||||
const rb_control_frame_t *cfp;
|
const rb_control_frame_t *cfp;
|
||||||
|
|
|
||||||
|
|
@ -913,7 +913,7 @@ rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp);
|
||||||
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
|
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
|
||||||
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
|
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
|
||||||
|
|
||||||
#define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE)
|
#define RUBY_VM_IFUNC_P(ptr) RB_TYPE_P((VALUE)(ptr), T_NODE)
|
||||||
#define RUBY_VM_NORMAL_ISEQ_P(ptr) \
|
#define RUBY_VM_NORMAL_ISEQ_P(ptr) \
|
||||||
((ptr) && !RUBY_VM_IFUNC_P(ptr))
|
((ptr) && !RUBY_VM_IFUNC_P(ptr))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||||
const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
|
const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
if (cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE) {
|
if (cfp->block_iseq != 0 && !RUBY_VM_IFUNC_P(cfp->block_iseq)) {
|
||||||
biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */
|
biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2073,7 +2073,7 @@ vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci
|
||||||
}
|
}
|
||||||
iseq = block->iseq;
|
iseq = block->iseq;
|
||||||
|
|
||||||
if (BUILTIN_TYPE(iseq) != T_NODE) {
|
if (!RUBY_VM_IFUNC_P(iseq)) {
|
||||||
int opt_pc;
|
int opt_pc;
|
||||||
const int arg_size = iseq->param.size;
|
const int arg_size = iseq->param.size;
|
||||||
int is_lambda = block_proc_is_lambda(block->proc);
|
int is_lambda = block_proc_is_lambda(block->proc);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue