New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRuby instance-eval is applied to the wrong object #3543

Closed
fundamental opened this Issue Mar 24, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@fundamental

When upgrading from commit 36fc1f1 to 3703aed a regression is observed in the behavior of instance_eval. In this period I see 6 commits to eval.c:

fca17b4 Avoid trampoline when #eval is called from mrb_funcall(); fix #3522
f8b31a0 `instance_eval` method does not introduce C function boundary; fix #3508
73e5a19 Configure callinfo target_class as CRuby; ref #3429
097da23 Avoid executing OP_STOP in eval(); fix #3429
5e3c329 Adjust callinfo env and target_class; ref #3429
48e0bbb Make `eval` to use trampoline technique; fix #3415

Presumably one of these commits is setting the target class for instance eval incorrectly. The test case used to observe the behavior is shown below:

class A
    def method
        :a
    end
end

class B
    def initialize()
        @a = A.new
        @a.instance_eval "def method;:a_eval;end"
        nil
    end

    attr_reader :a

    def method
        :b
    end
end

a = A.new
b = B.new

puts "Expected unmodified method value ':a'.      Got '#{a.method}'"
puts "Expected unmodified method value ':b'.      Got '#{b.method}'"
puts "Expected   modified method value ':a_eval'. Got '#{b.a.method}'"

Behavior observed with mruby and CRuby (2.2.3p173) show the bug:

mark@darkstar:~/mytmp/mruby$ ruby instance_eval_test.rb
Expected unmodified method value ':a'.      Got 'a'
Expected unmodified method value ':b'.      Got 'b'
Expected   modified method value ':a_eval'. Got 'a_eval'
mark@darkstar:~/mytmp/mruby$ ./bin/mruby instance_eval_test.rb
Expected unmodified method value ':a'.      Got 'a'
Expected unmodified method value ':b'.      Got 'a_eval'
Expected   modified method value ':a_eval'. Got 'a'
@fundamental

This comment has been minimized.

Show comment
Hide comment
@fundamental

fundamental Mar 24, 2017

Some quick printf() based debugging latter it looks like the RProc's target_class field might be being ignored in the mrb_exec_irep() function in vm.c.

Some quick printf() based debugging latter it looks like the RProc's target_class field might be being ignored in the mrb_exec_irep() function in vm.c.

@matz matz closed this in a49c9f8 Apr 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment