Skip to content

Commit

Permalink
rewrite 351ebd7 and 954a8c7 because they cause crash when refer to cl…
Browse files Browse the repository at this point in the history
…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
Watson1978 committed Mar 30, 2011
1 parent fd961f3 commit ec68679
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions vm.cpp
Expand Up @@ -1542,9 +1542,9 @@ rb_vm_alias2(VALUE outer, VALUE name, VALUE def, unsigned char dynamic_class)
if (k != NULL) { if (k != NULL) {
outer = (VALUE)k; outer = (VALUE)k;
} }
} else if (RCLASS_SUPER(outer) == 0) {
if (NIL_P(outer)) { rb_raise(rb_eTypeError, "no class to make alias");
rb_raise(rb_eTypeError, "no class to make alias"); }
} }


// Given arguments should always be symbols (compiled as such). // Given arguments should always be symbols (compiled as such).
Expand Down Expand Up @@ -2064,9 +2064,9 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
klass = *(Class *)klass; klass = *(Class *)klass;
} }
} }
} else if (RCLASS_SUPER(klass) == 0) {
if (NIL_P(klass)) { rb_raise(rb_eTypeError, "no class/module to add method");
rb_raise(rb_eTypeError, "no class/module to add method"); }
} }


const long v = RCLASS_VERSION(klass); const long v = RCLASS_VERSION(klass);
Expand Down
4 changes: 2 additions & 2 deletions vm_eval.c
Expand Up @@ -513,7 +513,7 @@ rb_obj_instance_eval_imp(VALUE self, SEL sel, VALUE top, int argc, VALUE *argv)
VALUE klass; VALUE klass;


if (SPECIAL_CONST_P(self) || CLASS_OF(self) == rb_cSymbol) { if (SPECIAL_CONST_P(self) || CLASS_OF(self) == rb_cSymbol) {
klass = Qnil; klass = 0;
} }
else { else {
klass = rb_singleton_class(self); klass = rb_singleton_class(self);
Expand Down Expand Up @@ -561,7 +561,7 @@ rb_obj_instance_exec(VALUE self, SEL sel, int argc, VALUE *argv)
VALUE klass; VALUE klass;


if (SPECIAL_CONST_P(self)) { if (SPECIAL_CONST_P(self)) {
klass = Qnil; klass = 0;
} }
else { else {
klass = rb_singleton_class(self); klass = rb_singleton_class(self);
Expand Down

0 comments on commit ec68679

Please sign in to comment.