# Eval with binding

e\$B\$3\$s\$K\$A\$O!"\$J\$+\$`\$ie(B(e\$B\$&e(B)e\$B\$G\$9!#e(B

e\$B0J2<\$Ne(B2e\$B\$D\$N%3!<%I\$,!"e(B1.8e\$B\$He(Btrunke\$B\$GF0:n\$,0[\$J\$j\$^\$9!#e(B
e\$B\$J\$<\$G\$7\$g\$&e(B?
e\$B;d\$K\$Oe(B1.8e\$B\$N5sF0\$,<+A3\$K;W\$(\$^\$9!#e(B

# e\$B\$=\$Ne(B1

x = 0
eval(“p x”, TOPLEVEL_BINDING)

# e\$B\$=\$Ne(B2

BEGIN{\$b = binding}
eval(“p x”, \$b)

# trunk => 0

e\$B\$=\$l\$G\$O!#e(B

e\$B\$3\$s\$K\$A\$O!"\$J\$+\$`\$ie(B(e\$B\$&e(B)e\$B\$G\$9!#e(B

e\$B\$A\$g\$C\$H4V0c\$(\$^\$7\$?!#e(B

In message “[ruby-dev:37142] eval with binding”
on Nov.21,2008 22:02:04, [email protected] wrote:

# e\$B\$=\$Ne(B2

BEGIN{\$b = binding}
x = 0
eval(“p x”, \$b)

# trunk => 0

e\$B\$G\$9!#e(B

e\$B\$=\$l\$G\$O!#e(B

e\$B\$3\$s\$K\$A\$O!"\$J\$+\$`\$ie(B(e\$B\$&e(B)e\$B\$G\$9!#e(B

e\$BC/\$b65\$(\$F\$/\$l\$J\$\$\$N\$Ge(Bbuge\$B\$K\$7\$^\$9!#e(B

# e\$B\$3\$l\$G\$J\$k\$N\$+\$Je(B

In message “[ruby-dev:37142] eval with binding”
on Nov.21,2008 22:02:04, [email protected] wrote:

# e\$B\$=\$Ne(B2

BEGIN{\$b = binding}
x = 0
eval(“p x”, \$b)

# trunk => 0

e\$B\$=\$l\$G\$O!#e(B

e\$B%A%1%C%He(B #803 e\$B\$,99?7\$5\$l\$^\$7\$?!#e(B (by Yuki S.)

e\$BM%@hEYe(B Lowe\$B\$+\$ie(BHighe\$B\$KJQ99e(B
Target version 1.9.1 Release Candidatee\$B\$K%;%C%He(B

@ Rubye\$B3+H/2q5De(B

• e\$B\$=\$Ne(B1e\$B\$O4hD%\$ke(B
• e\$B\$=\$Ne(B2e\$B\$O=EMWEYDc\$\$!#e(BKNOWN BUGe\$B07\$\$!#e(B

http://redmine.ruby-lang.org/issues/show/803

[email protected]\$G\$9!%e(B

Yuki S. wrote::

• e\$B\$=\$Ne(B2e\$B\$O=EMWEYDc\$\$!#e(BKNOWN BUGe\$B07\$\$!#e(B

e\$B!!e(BKNOWN BUG e\$B\$H\$\$\$&\$+!\$5v\$5\$l\$k\$N\$J\$i;EMMJQ99\$K\$7\$?\$\$!%e(B
e\$B!J=EMWEY\$ODc\$=\$&!\$<BAu\$OBgJQ!Ke(B

[email protected]\$G\$9!%e(B

U.Nakamura wrote::

# e\$B\$=\$Ne(B1

x = 0
eval(“p x”, TOPLEVEL_BINDING)

# Index: vm.c

— vm.c (e\$B%j%S%8%g%se(B 20969)
+++ vm.c (e\$B:n6H%3%T!<e(B)
@@ -1240,7 +1240,10 @@ rb_iseq_eval(VALUE iseqval)
vm_set_top_stack(th, iseqval);

`````` if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) {
``````
• rb_define_global_const(“TOPLEVEL_BINDING”, rb_binding_new());
• VALUE bind;
• rb_vm_set_finish_env(th); /* push dummy frame */
• rb_define_global_const(“TOPLEVEL_BINDING”, bind);
• vm_pop_frame(th); /* pop dummy frame /
}
val = vm_exec(th);
tmp = iseqval; /
prohibit tail call optimization */

e\$B!!\$3\$l\$GD>\$k\$N\$G\$O\$J\$\$\$+\$H;W\$\$\$^\$9!%\$43NG’[email protected]\$1\$^\$;\$s\$+!%e(B

# e\$B\$=\$Ne(B2

BEGIN{\$b = binding}
x = 0
eval(“p x”, \$b)

# trunk => 0

e\$B!!\$3\$A\$i\$O!\$A0\$+\$i=q\$\$\$F\$\$\$?\$H\$*\$j!\$;[email protected]\$1\$k\$H!%!V\$3\$&\$\$\$&>le(B
[email protected]!W\$H\$+!\$\$=\$&\$\$\$&OC\$C\$F\$"\$j\$^\$9\$+\$M!%e(B

e\$B\$3\$s\$K\$A\$O!"\$J\$+\$`\$ie(B(e\$B\$&e(B)e\$B\$G\$9!#e(B

In message “[ruby-dev:37585] Re: [Bug:trunk] eval with binding”
on Dec.25,2008 00:20:48, [email protected] wrote:

e\$B!!\$3\$l\$GD>\$k\$N\$G\$O\$J\$\$\$+\$H;W\$\$\$^\$9!%\$43NG’[email protected]\$1\$^\$;\$s\$+!%e(B

e\$BJQ?te(Bbinde\$B\$K0lEY\$bCM\$rBeF~\$7\$?\$3\$H\$,\$J\$\$\$N\$KD>\$k\$3\$H\$O\$"\$j\$(\$Je(B
e\$B\$\$\$H;W\$&\$s\$G\$9\$,!#e(B

e\$B\$=\$l\$O\$H\$b\$+\$/!"\$I\$3\$G\$bDLMQ\$9\$k:F8=%1!<%9\$r<(\$7\$F\$b!"Js9p<Te(B
e\$B\$,3NG’\$7\$J\$\$\$H%@%a\$G\$9\$+!#[email protected]\$o\$l\$l\$P\$d\$j\$^\$9\$1\$I\$M!#e(B

# e\$B\$=\$Ne(B2

e\$B!!\$3\$A\$i\$O!\$A0\$+\$i=q\$\$\$F\$\$\$?\$H\$*\$j!\$;[email protected]\$1\$k\$H!%!V\$3\$&\$\$\$&>le(B
[email protected]!W\$H\$+!\$\$=\$&\$\$\$&OC\$C\$F\$"\$j\$^\$9\$+\$M!%e(B

e\$B\$=\$b\$=\$b!V%P%[email protected]!W\$H;XE&\$7\$F\$\$\$k\$o\$1\$G\$O\$J\$/\$F!“e(B1.8e\$B\$H0c\$&\$N\$Oe(B
e\$B\$J\$<\$G\$9\$+!”[email protected]\$1\$J\$N\$G!"M}M3\$5\$(@bL@\$5\$l\$F\$\$\$l\$Pe(B
e\$B0c\$C\$F\$\$\$F\$b\$+\$^\$o\$J\$\$\$H\$O;W\$\$\$^\$9!#e(B

e\$B\$=\$l\$G\$O!#e(B

[email protected]\$G\$9!%e(B

U.Nakamura wrote::

e\$BJQ?te(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$&\$K\$*4j\$\$\$7\$?\$D\$b\$j\$G\$7\$?!%e(B

e\$B!J\$G!\$\$=\$b\$=\$bD>\$C\$F\$J\$+\$C\$?!Ke(B

e\$B!!:#2s\$O!\$2?\$r;[email protected]\$K%a!<%k\$G3NG’\$7\$^\$7\$?\$,!\$\$H\$j\$"\$(\$:!\$:#8e\$O5\$\$Ke(B
e\$B\$;\$:%3%_%C%H\$7\$h\$&\$H;W\$\$\$^\$9!%e(B

e\$B!J%F%9%HIU\$-\$G!Ke(B

# e\$B\$=\$Ne(B2

e\$B!!\$3\$A\$i\$O!\$A0\$+\$i=q\$\$\$F\$\$\$?\$H\$*\$j!\$;[email protected]\$1\$k\$H!%!V\$3\$&\$\$\$&>le(B
[email protected]!W\$H\$+!\$\$=\$&\$\$\$&OC\$C\$F\$"\$j\$^\$9\$+\$M!%e(B

e\$B\$=\$b\$=\$b!V%P%[email protected]!W\$H;XE&\$7\$F\$\$\$k\$o\$1\$G\$O\$J\$/\$F!“e(B1.8e\$B\$H0c\$&\$N\$Oe(B
e\$B\$J\$<\$G\$9\$+!”[email protected]\$1\$J\$N\$G!"M}M3\$5\$(@bL@\$5\$l\$F\$\$\$l\$Pe(B
e\$B0c\$C\$F\$\$\$F\$b\$+\$^\$o\$J\$\$\$H\$O;W\$\$\$^\$9!#e(B

e\$B!!M}M3\$Oe(B [ruby-dev:37376]
e\$B\$G=q\$\$\$?\$H\$*\$j!\$!V<BAu\$,[email protected]\$+\$i\$G\$9!%e(B

e\$B!!\$^\$D\$b\$H\$5\$s\$KJ9\$\$\$?\$i!\$\$H\$/\$KLdBj\$J\$\$!J<BAu\$He([email protected]\$NE7Gi\$K\$+\$1e(B
[email protected]!\$,LdBj\$K\$J\$k\$3\$H\$O\$J\$\$\$N\$G\$O\$J\$\$\$+!K\$H\$\$\$&[email protected]\$F\$\$e(B
e\$B\$^\$9!%\$,!\$\$&\$5\$5\$s\$K\$O:\$\$C\$?;v>p\$,\$"\$C\$?\$N\$G\$O\$J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$-\$k\$+!We(B
e\$B\$H\$\$\$&%/%\$%:e(B)[email protected]\$C\$?\$N\$G!“B>\$N2?\$NA0Ds\$b\$J\$/!“LdBj%1!<%9\$=\$Ne(B1
e\$B\$N%3!<%I\$,=q\$+\$l\$F\$\$\$^\$9!#e(B
e\$B\$J\$N\$G!”;d\$N<j85\$GFC\$K\$3\$l\$,860x\$G:\$\$C\$?%W%m%0%i%`\$,\$”\$k\$o\$1e(B
e\$B\$G\$O\$"\$j\$^\$;\$s!#e(B

[email protected]\$7!"\$3\$N5sF0\$rA0Ds\$H\$7\$?%3!<%I\$r\$I\$3\$+\$G8+\$?5-21\$O\$"\$k\$Ne(B
e\$B\$Ge(B(e\$B;d\$,=q\$\$\$?\$b\$N\$8\$c\$J\$\$\$G\$9\$,e(B)e\$B!"@\$3&\$N\$I\$3\$+\$K\$O\$3\$l\$G:\$\$ke(B
[email protected]\$m\$&\$H;W\$o\$l\$^\$9!#e(B

e\$B\$=\$b\$=\$b!V%P%[email protected]!W\$H;XE&\$7\$F\$\$\$k\$o\$1\$G\$O\$J\$/\$F!“e(B1.8e\$B\$H0c\$&\$N\$Oe(B
e\$B\$J\$<\$G\$9\$+!”[email protected]\$1\$J\$N\$G!"M}M3\$5\$(@bL@\$5\$l\$F\$\$\$l\$Pe(B
e\$B0c\$C\$F\$\$\$F\$b\$+\$^\$o\$J\$\$\$H\$O;W\$\$\$^\$9!#e(B

e\$B!!M}M3\$Oe(B [ruby-dev:37376] e\$B\$G=q\$\$\$?\$H\$*\$j!\$!V<BAu\$,[email protected]\$+\$i\$G\$9!%e(B

e\$B!!\$^\$D\$b\$H\$5\$s\$KJ9\$\$\$?\$i!\$\$H\$/\$KLdBj\$J\$\$!J<BAu\$He([email protected]\$NE7Gi\$K\$+\$1e(B
[email protected]!\$,LdBj\$K\$J\$k\$3\$H\$O\$J\$\$\$N\$G\$O\$J\$\$\$+!K\$H\$\$\$&[email protected]\$F\$\$e(B
e\$B\$^\$9!%\$,!\$\$&\$5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

e\$B\$=\$l\$G\$O!#e(B

e\$B%A%1%C%He(B #803 e\$B\$,99?7\$5\$l\$^\$7\$?!#e(B (by Koichi Sasada)

e\$B%9%F!<%?%9e(B Opene\$B\$+\$ie(BClosede\$B\$KJQ99e(B
e\$B?JD=e(B % 0e\$B\$+\$ie(B100e\$B\$KJQ99e(B

## Applied in changeset r21079.

http://redmine.ruby-lang.org/issues/show/803