Fixed local variables not separated between copied binding objects#5517
Conversation
|
Hmm, the current behavior seems to comply CRuby behavior. Do we need to fix it? |
|
I'm sorry, it may have been a confusing expression.
|
|
OK, I understand the need for the change. But still, we need to check the following behavior: x = 5
bind1 = binding
bind1.local_variable_set(:y, 10)
bind2 = bind1.dup
p bind2.local_variable_get(:x) #=> 5
p bind2.local_variable_get(:y) #=> 10
bind1.local_variable_set(:y, 20)
p bind2.local_variable_get(:y) #=> 20 (from CRuby, mruby, 10 from the PR)
p bind1.local_variable_get(:y) #=> 20
x = 50
p bind1.local_variable_get(:x) #=> 50
p bind2.local_variable_get(:x) #=> 50 |
|
I'm sorry again, I didn't confirm enough. But there is a concern, and if it repeats
Please give me some time... |
|
OK. |
| #define BINDING_UPPER_DEFAULT 20 | ||
| #define BINDING_UPPER_MINIMUM 10 | ||
| #define BINDING_UPPER_MAXIMUM 100 | ||
|
|
||
| #ifndef MRB_BINDING_UPPER_MAX | ||
| # define BINDING_UPPER_MAX BINDING_UPPER_DEFAULT | ||
| #else | ||
| # define BINDING_UPPER_MAX ((MRB_BINDING_UPPER_MAX) > BINDING_UPPER_MAXIMUM ? BINDING_UPPER_MAXIMUM : \ | ||
| (MRB_BINDING_UPPER_MAX) < BINDING_UPPER_MINIMUM ? BINDING_UPPER_MINIMUM : \ | ||
| (MRB_BINDING_UPPER_MAX)) | ||
| #endif |
There was a problem hiding this comment.
The user can define the depth of the proc with the MRB_BINDING_UPPER_MAX constant macro.
% cat bindingtest.rb
bx = [binding]
50.times { |i|
begin
bx[-1].eval("var#{i} = #{i}")
bx << bx[-1].dup
rescue => e
p [i, e]
break
end
}
% bin/mruby bindingtest.rb
[19, too many upper procs for local variables (mruby limitation; maximum is 20) (RuntimeError)]There was a problem hiding this comment.
This part was wrong.
If MRB_BINDING_UPPER_MAX is defined, the ?: operator is printed as is in the error message.
I will fix this.
This is because I forgot to implement the `Binding#initialize_copy` method.

This is because I forgot to implement the
Binding#initialize_copymethod.