# \[BUG:trunk\] eval with binding, without location

**URL:** <https://www.ruby-forum.com/t/bug-trunk-eval-with-binding-without-location/172005>\
**Category:** Development\
**Created:** [July 13, 2009, 10:51am UTC](https://www.ruby-forum.com/t/bug-trunk-eval-with-binding-without-location/172005 "2009-07-13T10:51:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yugui\_SYuki\_S.S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/dec6dc/32.png) [@Yugui\_SYuki\_S.S](https://www.ruby-forum.com/u/Yugui_SYuki_S.S)\
**Post date:** [July 13, 2009, 10:51am UTC](https://www.ruby-forum.com/t/bug-trunk-eval-with-binding-without-location/172005/1 "2009-07-13T10:51:36Z")

</div>

evale$B$NBhe(B3, 4e$B0z?t$r\>JN,$7$?:]$Ke(Bbindinge$B$,;}$C$F$$$ke(Bfile,  
linee$B$,EAGE$7$J$/e(B  
e$B$J$C$F$$$^$9!#$3$l$O0U?^$7$?$3$H$G$7$g$&$+!#e(B  
irbe$B$N%P%C%/%H%l!\<%9$,$3$l$N$?$a$K$A$g$C$HIT?F@Z$K$J$C$F$$$^$9!#e(B

% cat test.rb  
b = binding  
p eval(“ **FILE** ”, b)

b = eval(‘binding’, TOPLEVEL\_BINDING, **FILE** , **LINE** )  
p eval(“ **FILE** ”, b)

% ruby18 -v test.rb  
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9]  
“test.rb”  
“test.rb”

% ruby-trunk -v test.rb  
ruby 1.9.2dev (2009-07-13 trunk 24067) [i386-darwin9.7.0]  
“(eval)”  
“(eval)”

---

<div class="post-metadata">

**Author:** ![Yugui\_SYuki\_S.S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/dec6dc/32.png) [@Yugui\_SYuki\_S.S](https://www.ruby-forum.com/u/Yugui_SYuki_S.S)\
**Post date:** [May 9, 2010, 8:47pm UTC](https://www.ruby-forum.com/t/bug-trunk-eval-with-binding-without-location/172005/2 "2010-05-09T20:47:22Z")

</div>

e$B%A%1%C%He(B #1769 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

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

This issue was solved with changeset r27716.  
Yuki, thank you for reporting this issue.  
Your contribution to Ruby is greatly appreciated.  
May Ruby be with you.

* * *

[http://redmine.ruby-lang.org/issues/show/1769](http://redmine.ruby-lang.org/issues/show/1769)

---

<div class="post-metadata">

**Author:** ![Yugui\_SYuki\_S.S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/dec6dc/32.png) [@Yugui\_SYuki\_S.S](https://www.ruby-forum.com/u/Yugui_SYuki_S.S)\
**Post date:** [April 27, 2010, 6:00pm UTC](https://www.ruby-forum.com/t/bug-trunk-eval-with-binding-without-location/172005/3 "2010-04-27T18:00:47Z")

</div>

e$B%A%1%C%He(B #1769 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$BC4Ev\<Te(B Koichi Sasadae$B$+$ie(BYusuke E.e$B$KJQ99e(B

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

> evale$B$NBhe(B3, 4e$B0z?t$r\>JN,$7$?:]$Ke(Bbindinge$B$,;}$C$F$$$ke(Bfile, linee$B$,EAGE$7$J$/e(B  
> e$B$J$C$F$$$^$9!#$3$l$O0U?^$7$?$3$H$G$7$g$&$+!#e(B

rb\_binding\_t e$B$K%U%!%$%kL\>$H9THV9f$r;}$?$;$F$\_$^$7$?!#e(B  
bootstraptest/test\_eval.rb e$B$Ke(B 1 e$B$+=j!"e(Brubyspec e$B$Ke(B 4  
e$B2U=j=$@5$re(B  
e$B2C$($?\>e$G!"e(Bmake check e$B$He(B make test-rubyspec  
e$B$rDL2a$7$^$7$?!#e(B

e$BH?BP$,$J$1$l$P%3%\_%C%H$7$^$9!#e(B

diff --git a/bootstraptest/test\_eval.rb b/bootstraptest/test\_eval.rb  
index c5ab953…9ae50a6 100644  
— a/bootstraptest/test\_eval.rb  
+++ b/bootstraptest/test\_eval.rb  
@@ -287,7 +287,7 @@ assert\_normal\_exit %q{  
eval(“”, method(:proc).call {}.binding)  
}

-assert\_equal "(eval):1:in `block in ‘: ", %q{  
+assert\_equal “”, %q{  
b = binding  
10.times{  
eval(’', b)  
diff --git a/proc.c b/proc.c  
index 7e8e0e1…035897c 100644  
— a/proc.c  
+++ b/proc.c  
@@ -254,6 +254,7 @@ binding\_mark(void \*ptr)  
if (ptr) {  
bind = ptr;  
RUBY\_MARK\_UNLESS\_NULL(bind-\>env);

- RUBY\_MARK\_UNLESS\_NULL(bind-\>filename);  
}  
RUBY\_MARK\_LEAVE(“binding”);  
}  
@@ -289,6 +290,8 @@ binding\_dup(VALUE self)  
GetBindingPtr(self, src);  
GetBindingPtr(bindval, dst);  
dst-\>env = src-\>env;
- dst-\>filename = src-\>filename;
- dst-\>line\_no = src-\>line\_no;  
return bindval;  
}

@@ -315,6 +318,8 @@ rb\_binding\_new(void)

```
 GetBindingPtr(bindval, bind);
 bind->env = rb_vm_make_env_object(th, cfp);

```

- bind-\>filename = cfp-\>iseq-\>filename;
- bind-\>line\_no = rb\_vm\_get\_sourceline(cfp);  
return bindval;  
}

@@ -1893,6 +1898,8 @@ proc\_binding(VALUE self)  
bindval = binding\_alloc(rb\_cBinding);  
GetBindingPtr(bindval, bind);  
bind-\>env = proc-\>envval;

- bind-\>filename = proc-\>block.iseq-\>filename;
- bind-\>line\_no = rb\_iseq\_first\_lineno(proc-\>block.iseq);  
return bindval;  
}

diff --git a/vm\_core.h b/vm\_core.h  
index b5c1bf0…15f7c59 100644  
— a/vm\_core.h  
+++ b/vm\_core.h  
@@ -519,6 +519,8 @@ typedef struct {

typedef struct {  
VALUE env;

- VALUE filename;
- unsigned short line\_no;  
} rb\_binding\_t;

/\* used by compile time and send insn \*/  
diff --git a/vm\_eval.c b/vm\_eval.c  
index fefe6d6…9806762 100644  
— a/vm\_eval.c  
+++ b/vm\_eval.c  
@@ -963,6 +963,10 @@ eval\_string\_with\_cref(VALUE self, VALUE src, VALUE  
scope, NODE \*cref, const char  
if (rb\_obj\_is\_kind\_of(scope, rb\_cBinding)) {  
GetBindingPtr(scope, bind);  
envval = bind-\>env;

- if (strcmp(file, “(eval)”) == 0) {
- 

```
   file = RSTRING_PTR(bind->filename);

```

- 

```
   line = bind->line_no;

```

- }  
}  
else {  
rb\_raise(rb\_eTypeError,

rubyspec e$BB&$N%Q%C%Ae(B:

diff --git a/core/kernel/caller\_spec.rb b/core/kernel/caller\_spec.rb  
index 3ecde8a…923a1ec 100644  
— a/core/kernel/caller\_spec.rb  
+++ b/core/kernel/caller\_spec.rb  
@@ -93,7 +93,7 @@ describe “Kernel#caller in a Proc or eval” do  
ruby\_version\_is “1.9” do  
it “returns the definition trace of a block when evaluated in a  
Proc binding” do  
stack = CallerFixture.caller\_of(CallerFixture.block)

- 

```
 stack[0].should == "(eval):1:in `<top (required)>'"

```

- 

```
 stack[0].should =~ /caller_fixture1\.rb:4:in `<top 

```

(required)\>‘/  
stack[1].should =~ /caller\_fixture2.rb:18:in `eval'/ stack[2].should =~ /caller_fixture2\.rb:18:in `caller\_of’/  
stack[3].should =~ /caller\_spec.rb:95:in `block (3 levels) in  
\<top (required)\>'/  
@@ -101,7 +101,7 @@ describe “Kernel#caller in a Proc or eval” do

```
 it "returns the definition trace of a Proc" do
   stack = CallerFixture.caller_of(CallerFixture.example_proc)

```

- 

```
 stack[0].should == "(eval):1:in `example_proc'"

```

- 

```
 stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/
 stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
 stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
 stack[3].should =~ /caller_spec\.rb:103:in `block \(3 levels\) in 

```

\<top (required)\>'/  
@@ -119,7 +119,7 @@ describe “Kernel#caller in a Proc or eval” do  
# the correct behaviour  
it “returns the correct definition line for a complex Proc trace”  
do  
stack = CallerFixture.caller\_of(CallerFixture.entry\_point)

- 

```
 stack[0].should == "(eval):1:in `third'"

```

- 

```
 stack[0].should =~ /caller_fixture1\.rb:29:in `third'/
 stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
 stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
 stack[3].should =~ /caller_spec.rb:121:in `block \(3 levels\) in 

```

\<top (required)\>'/  
diff --git a/core/kernel/eval\_spec.rb b/core/kernel/eval\_spec.rb  
index 187c8f3…4bc731b 100644  
— a/core/kernel/eval\_spec.rb  
+++ b/core/kernel/eval\_spec.rb  
@@ -252,26 +252,13 @@ describe “Kernel#eval” do  
end  
end

- ruby\_version\_is “”…“1.9” do
- it “uses the filename of the binding if none is provided” do
- 

```
 eval(" __FILE__").should == "(eval)"

```

- 

```
 eval(" __FILE__", binding).should == __FILE__

```

- 

```
 eval(" __FILE__", binding, "success").should == "success"

```

- 

```
 eval("eval ' __FILE__', binding").should == "(eval)"

```

- 

```
 eval("eval ' __FILE__', binding", binding).should == __FILE__

```

- 

```
 eval("eval ' __FILE__', binding", binding, 'success').should == 

```

‘success’

- end
- end
- 
- ruby\_version\_is “1.9” do
- it “uses a filename of (eval) if none is provided” do
- 

```
 eval(" __FILE__").should == "(eval)"

```

- 

```
 eval(" __FILE__", binding).should == "(eval)"

```

- 

```
 eval(" __FILE__", binding, "success").should == "success"

```

- 

```
 eval("eval ' __FILE__', binding").should == "(eval)"

```

- 

```
 eval("eval ' __FILE__', binding", binding).should == "(eval)"

```

- 

```
 eval("eval ' __FILE__', binding", binding, 'success').should == 

```

‘(eval)’

- end

- it “uses the filename of the binding if none is provided” do
- eval(“ **FILE** ”).should == “(eval)”
- eval(“ **FILE** ”, binding).should == **FILE**
- eval(“ **FILE** ”, binding, “success”).should == “success”
- eval(“eval ‘ **FILE** ’, binding”).should == “(eval)”
- eval(“eval ‘ **FILE** ’, binding”, binding).should == **FILE**
- eval(“eval ‘ **FILE** ’, binding”, binding, ‘success’).should ==  
‘success’  
end

# Found via Rubinius bug github:#149

## – Yusuke E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[http://redmine.ruby-lang.org/issues/show/1769](http://redmine.ruby-lang.org/issues/show/1769)
