# \[Bug #1150\] calling instance\_eval in extended library cause exception

**URL:** <https://www.ruby-forum.com/t/bug-1150-calling-instance-eval-in-extended-library-cause-exception/160182>\
**Category:** Development\
**Created:** [February 12, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/bug-1150-calling-instance-eval-in-extended-library-cause-exception/160182 "2009-02-12T17:17:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akio\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e5b9ba/32.png) [@Akio\_T](https://www.ruby-forum.com/u/Akio_T)\
**Post date:** [February 12, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/bug-1150-calling-instance-eval-in-extended-library-cause-exception/160182/1 "2009-02-12T17:17:43Z")

</div>

Bug #1150: calling instance\_eval in extended library cause exception  
[http://redmine.ruby-lang.org/issues/show/1150](http://redmine.ruby-lang.org/issues/show/1150)

e$B5/I\<\<Te(B: Akio T.  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Normal  
Target version: 1.9.1  
ruby -v: ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mswin32]

e$B3HD%%i%$%V%i%jFb$N%a%=%C%I$Ge(Binstance\_evale$B$r8F$S=P$9$H!"e(BCan’t  
eval on top of Fiber or Thread (RuntimeError)e$B$K$J$j$^$9!#e(B  
e$B:F8=%3!\<%I$r0J2\<$K\<($7$^$9!#e(B  
// cmodev.c  
#include “ruby.h”  
#include “extconf.h”  
static VALUE cmodev;  
static VALUE xtest\_func(VALUE self, VALUE s)  
{  
return rb\_funcall2(self, rb\_intern(“instance\_eval”), 1, &s);  
}  
void Init\_cmodev()  
{  
cmodev = rb\_define\_class(“XTest”, rb\_cObject);  
rb\_define\_method(cmodev, “xtest”, xtest\_func, 1);  
}

#t.rb  
require ‘cmodev’  
x = XTest.new  
x.xtest(“puts ‘hello’”)

e$B\<B9TNce(B  
c:\test\modev\test\>ruby t.rb  
t.rb:3:in `instance_eval': Can't eval on top of Fiber or Thread (RuntimeError) from t.rb:3:in `xtest’  
from t.rb:3:in `’

---

<div class="post-metadata">

**Author:** ![Akio\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e5b9ba/32.png) [@Akio\_T](https://www.ruby-forum.com/u/Akio_T)\
**Post date:** [February 12, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/bug-1150-calling-instance-eval-in-extended-library-cause-exception/160182/2 "2009-02-12T22:34:15Z")

</div>

e$B!!$5$5$@$G$9!%e(B

Akio T. wrote::

> e$B3HD%%i%$%V%i%jFb$N%a%=%C%I$Ge(Binstance\_evale$B$r8F$S=P$9$H!"e(BCan’t eval on top of Fiber or Thread (RuntimeError)e$B$K$J$j$^$9!#e(B

e$B!!$4;XE&$"$j$,$H$&$4$6$$$^$9!%%P%0$G$7$?!%e(B

# Index: vm\_core.h

— vm\_core.h (e$B%j%S%8%g%se(B 22272)  
+++ vm\_core.h (e$B:n6H%3%T!\<e(B)  
@@ -593,10 +593,14 @@ int ruby\_thread\_has\_gvl\_p(void);  
VALUE rb\_make\_backtrace(void);  
typedef int rb\_backtrace\_iter\_func(void \*, const char \*, int, const  
char \*);  
VALUE rb\_backtrace\_each(rb\_backtrace\_iter\_func \*iter, void \*arg);  
+rb\_control\_frame\_t \*rb\_vm\_get\_ruby\_level\_next\_cfp(rb\_thread\_t \*th,  
rb\_control\_frame\_t \*cfp);

NOINLINE(void rb\_gc\_save\_machine\_context(rb\_thread\_t \*));

# Index: vm\_eval.c

— vm\_eval.c (e$B%j%S%8%g%se(B 22272)  
+++ vm\_eval.c (e$B:n6H%3%T!\<e(B)  
@@ -706,7 +706,7 @@ eval\_string\_with\_cref(VALUE self, VALUE  
th-\>base\_block = &env-\>block;  
}  
else {

- 

```
 rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(th, 

```

th-\>cfp);

- 

```
 rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, 

```

th-\>cfp);

```
   if (cfp != 0) {
 block = *RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);

```

# Index: proc.c

— proc.c (e$B%j%S%8%g%se(B 22272)  
+++ proc.c (e$B:n6H%3%T!\<e(B)  
@@ -274,8 +274,6 @@ binding\_clone(VALUE self)  
return bindval;  
}

## -rb\_control\_frame\_t \*rb\_vm\_get\_ruby\_level\_next\_cfp(rb\_thread\_t \*th, rb\_control\_frame\_t \*cfp);

VALUE  
rb\_binding\_new(void)  
{

e$B!!$A$J$\_$K!$K\Ev$Ke(B eval e$B$,$d$j$?$$$s$G$9$+$M!%e(Bbinding  
e$B$r9M$($J$1$l$P!$e(B

```
rb_iseq_eval(rb_iseq_compile(VALUE src, VALUE file, VALUE line))

```

e$B$J$s$F\<j$,$"$j$^$9!%$,!$$^$@$3$l$ON"5;!Je(Bintern.h  
e$B$K$J$$$H$$$&0UL#!K$@e(B  
e$B$J!%e(B1.9.2 e$B$^$G$K@0M}$7$h$&!%$3$l$r$$$C$Z$s$K$d$ke(B API  
e$B$b$[$7$$$s$G$9$,!$e(B  
e$BL\>A0$,7h$a$i$l$J$/$F!%e(B
