Permalink
Browse files

rewrite 351ebd7 and 954a8c7 because they cause crash when refer to cl…

…ass variable within instance_{eval, exec}'s block.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

@@a = 4
assert_equal(4, 1.instance_eval { @@a } )
assert_equal(4, 1.instance_exec { @@a } )

assert_raise(TypeError){ 1.instance_eval { def foo; end } }
assert_raise(TypeError){ 1.instance_eval { alias :foo :to_s} }

assert_raise(TypeError){ 1.instance_exec { def foo; end } }
assert_raise(TypeError){ 1.instance_exec { alias :foo :to_s} }

puts :ok
}}}
  • Loading branch information...
1 parent fd961f3 commit ec6867998331c873e79ce758a1fa701894d17a01 @Watson1978 Watson1978 committed Mar 30, 2011
Showing with 8 additions and 8 deletions.
  1. +6 −6 vm.cpp
  2. +2 −2 vm_eval.c
View
12 vm.cpp
@@ -1542,9 +1542,9 @@ rb_vm_alias2(VALUE outer, VALUE name, VALUE def, unsigned char dynamic_class)
if (k != NULL) {
outer = (VALUE)k;
}
- }
- if (NIL_P(outer)) {
- rb_raise(rb_eTypeError, "no class to make alias");
+ else if (RCLASS_SUPER(outer) == 0) {
+ rb_raise(rb_eTypeError, "no class to make alias");
+ }
}
// Given arguments should always be symbols (compiled as such).
@@ -2064,9 +2064,9 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
klass = *(Class *)klass;
}
}
- }
- if (NIL_P(klass)) {
- rb_raise(rb_eTypeError, "no class/module to add method");
+ else if (RCLASS_SUPER(klass) == 0) {
+ rb_raise(rb_eTypeError, "no class/module to add method");
+ }
}
const long v = RCLASS_VERSION(klass);
View
@@ -513,7 +513,7 @@ rb_obj_instance_eval_imp(VALUE self, SEL sel, VALUE top, int argc, VALUE *argv)
VALUE klass;
if (SPECIAL_CONST_P(self) || CLASS_OF(self) == rb_cSymbol) {
- klass = Qnil;
+ klass = 0;
}
else {
klass = rb_singleton_class(self);
@@ -561,7 +561,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
VALUE klass;
if (SPECIAL_CONST_P(self)) {
- klass = Qnil;
+ klass = 0;
}
else {
klass = rb_singleton_class(self);

0 comments on commit ec68679

Please sign in to comment.