Skip to content

Commit 9eb78a2

Browse files
committed
merge revision(s) 49922,50111,50112: [Backport ruby#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 ruby#11012] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 3f1fc07 commit 9eb78a2

File tree

8 files changed

+62
-12
lines changed

8 files changed

+62
-12
lines changed

ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
Wed May 20 03:25:34 2015 Nobuyoshi Nakada <[email protected]>
2+
3+
* proc.c (proc_binding): replicate env from method object, and
4+
allocate the local variable area for the iseq local table.
5+
[ruby-core:68673] [Bug #11012]
6+
7+
Wed May 20 03:25:34 2015 Koichi Sasada <[email protected]>
8+
9+
* proc.c: use RUBY_VM_IFUNC_P() to recognize IFUNC or not.
10+
11+
* vm.c: ditto.
12+
13+
* vm_dump.c: ditto.
14+
15+
* vm_insnhelper.c: ditto.
16+
17+
* vm_core.h: use RB_TYPE_P() instead of BUILTIN_TYPE().
18+
119
Wed May 20 03:10:49 2015 Nobuyoshi Nakada <[email protected]>
220

321
* benchmark/bm_hash_aref_flo.rb: make more realistic data.

proc.c

+24-6
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ proc_call(int argc, VALUE *argv, VALUE procval)
719719
GetProcPtr(procval, proc);
720720

721721
iseq = proc->block.iseq;
722-
if (BUILTIN_TYPE(iseq) == T_NODE || iseq->param.flags.has_block) {
722+
if (RUBY_VM_IFUNC_P(iseq) || iseq->param.flags.has_block) {
723723
if (rb_block_given_p()) {
724724
rb_proc_t *passed_proc;
725725
RB_GC_GUARD(passed_procval) = rb_block_proc();
@@ -843,7 +843,7 @@ rb_block_min_max_arity(rb_block_t *block, int *max)
843843
{
844844
rb_iseq_t *iseq = block->iseq;
845845
if (iseq) {
846-
if (BUILTIN_TYPE(iseq) != T_NODE) {
846+
if (!RUBY_VM_IFUNC_P(iseq)) {
847847
return rb_iseq_min_max_arity(iseq, max);
848848
}
849849
else {
@@ -1717,7 +1717,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
17171717
rb_proc_t *proc;
17181718
body = proc_dup(body);
17191719
GetProcPtr(body, proc);
1720-
if (BUILTIN_TYPE(proc->block.iseq) != T_NODE) {
1720+
if (!RUBY_VM_IFUNC_P(proc->block.iseq)) {
17211721
proc->block.iseq->defined_method_id = id;
17221722
RB_OBJ_WRITE(proc->block.iseq->self, &proc->block.iseq->klass, mod);
17231723
proc->is_lambda = TRUE;
@@ -2477,22 +2477,40 @@ static VALUE
24772477
proc_binding(VALUE self)
24782478
{
24792479
rb_proc_t *proc;
2480-
VALUE bindval;
2480+
VALUE bindval, envval;
24812481
rb_binding_t *bind;
24822482
rb_iseq_t *iseq;
24832483

24842484
GetProcPtr(self, proc);
2485+
envval = proc->envval;
24852486
iseq = proc->block.iseq;
2486-
if (RB_TYPE_P((VALUE)iseq, T_NODE)) {
2487+
if (RUBY_VM_IFUNC_P(iseq)) {
2488+
rb_env_t *env;
24872489
if (!IS_METHOD_PROC_NODE((NODE *)iseq)) {
24882490
rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
24892491
}
24902492
iseq = rb_method_get_iseq(RNODE(iseq)->u2.value);
2493+
GetEnvPtr(envval, env);
2494+
if (iseq && env->local_size < iseq->local_size) {
2495+
int prev_local_size = env->local_size;
2496+
int local_size = iseq->local_size;
2497+
VALUE newenvval = TypedData_Wrap_Struct(RBASIC_CLASS(envval), RTYPEDDATA_TYPE(envval), 0);
2498+
rb_env_t *newenv = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
2499+
RTYPEDDATA_DATA(newenvval) = newenv;
2500+
newenv->env_size = local_size + 2;
2501+
newenv->local_size = local_size;
2502+
newenv->prev_envval = env->prev_envval;
2503+
newenv->block = env->block;
2504+
MEMCPY(newenv->env, env->env, VALUE, prev_local_size + 1);
2505+
rb_mem_clear(newenv->env + prev_local_size + 1, local_size - prev_local_size);
2506+
newenv->env[local_size + 1] = newenvval;
2507+
envval = newenvval;
2508+
}
24912509
}
24922510

24932511
bindval = rb_binding_alloc(rb_cBinding);
24942512
GetBindingPtr(bindval, bind);
2495-
bind->env = proc->envval;
2513+
bind->env = envval;
24962514
bind->blockprocval = proc->blockprocval;
24972515
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
24982516
bind->path = iseq->location.path;

test/ruby/test_method.rb

+14
Original file line numberDiff line numberDiff line change
@@ -877,4 +877,18 @@ def test_insecure_method
877877
obj.bar
878878
end
879879
end
880+
881+
def test_to_proc_binding
882+
bug11012 = '[ruby-core:68673] [Bug #11012]'
883+
class << (obj = Object.new)
884+
src = 1000.times.map {|i|"v#{i} = nil"}.join("\n")
885+
eval("def foo()\n""#{src}\n""end")
886+
end
887+
888+
b = obj.method(:foo).to_proc.binding
889+
b.local_variables.each_with_index {|n, i|
890+
b.local_variable_set(n, i)
891+
}
892+
assert_equal([998, 999], %w[v998 v999].map {|n| b.local_variable_get(n)}, bug11012)
893+
end
880894
end

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.2.3"
22
#define RUBY_RELEASE_DATE "2015-05-20"
3-
#define RUBY_PATCHLEVEL 107
3+
#define RUBY_PATCHLEVEL 108
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 5

vm.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ env_mark(void * const ptr)
380380
RUBY_MARK_UNLESS_NULL(env->block.proc);
381381

382382
if (env->block.iseq) {
383-
if (BUILTIN_TYPE(env->block.iseq) == T_NODE) {
383+
if (RUBY_VM_IFUNC_P(env->block.iseq)) {
384384
RUBY_MARK_UNLESS_NULL((VALUE)env->block.iseq);
385385
}
386386
else {
@@ -768,7 +768,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
768768
if (SPECIAL_CONST_P(block->iseq)) {
769769
return Qnil;
770770
}
771-
else if (BUILTIN_TYPE(block->iseq) != T_NODE) {
771+
else if (!RUBY_VM_IFUNC_P(block->iseq)) {
772772
VALUE ret;
773773
const rb_iseq_t *iseq = block->iseq;
774774
const rb_control_frame_t *cfp;

vm_core.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp);
913913
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
914914
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
915915

916-
#define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE)
916+
#define RUBY_VM_IFUNC_P(ptr) RB_TYPE_P((VALUE)(ptr), T_NODE)
917917
#define RUBY_VM_NORMAL_ISEQ_P(ptr) \
918918
((ptr) && !RUBY_VM_IFUNC_P(ptr))
919919

vm_dump.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
3636
const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
3737
VALUE tmp;
3838

39-
if (cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE) {
39+
if (cfp->block_iseq != 0 && !RUBY_VM_IFUNC_P(cfp->block_iseq)) {
4040
biseq_name = ""; /* RSTRING(cfp->block_iseq->location.label)->ptr; */
4141
}
4242

vm_insnhelper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci
20732073
}
20742074
iseq = block->iseq;
20752075

2076-
if (BUILTIN_TYPE(iseq) != T_NODE) {
2076+
if (!RUBY_VM_IFUNC_P(iseq)) {
20772077
int opt_pc;
20782078
const int arg_size = iseq->param.size;
20792079
int is_lambda = block_proc_is_lambda(block->proc);

0 commit comments

Comments
 (0)