Permalink
Browse files

[fix #74] should not define the method into special constant objects …

…and symbols via instance_{eval, exec}
  • Loading branch information...
1 parent c1bb396 commit 092ad9e0176b89c092b6cdf51ea05b9f2b40d27b @Watson1978 Watson1978 committed May 16, 2012
Showing with 12 additions and 9 deletions.
  1. +12 −9 vm.cpp
View
21 vm.cpp
@@ -1607,12 +1607,12 @@ rb_vm_alias2(VALUE outer, VALUE name, VALUE def, unsigned char dynamic_class)
{
if (dynamic_class) {
Class k = GET_VM()->get_current_class();
- if (k != NULL) {
- outer = (VALUE)k;
- }
- else if (RCLASS_SUPER(outer) == 0) {
+ if (NIL_P(outer)) {
rb_raise(rb_eTypeError, "no class to make alias");
}
+ else if (k != NULL) {
+ outer = (VALUE)k;
+ }
}
// Given arguments should always be symbols (compiled as such).
@@ -2132,20 +2132,20 @@ prepare_method(Class klass, bool dynamic_class, SEL sel, void *data,
else {
k = o->klass;
}
- if (k != NULL) {
+ if (NIL_P(k)) {
+ rb_raise(rb_eTypeError, "no class/module to add method");
+ }
+ else if (klass != NULL) {
const bool meta = class_isMetaClass(klass);
klass = k;
if (meta && !class_isMetaClass(klass)) {
klass = *(Class *)klass;
}
}
- else if (RCLASS_SUPER(klass) == 0) {
- rb_raise(rb_eTypeError, "no class/module to add method");
- }
}
else {
rb_vm_outer_t *o = GET_VM()->get_outer_stack();
- if (o != NULL && o->klass == NULL) {
+ if ((o != NULL && o->klass == NULL) || NIL_P(o)) {
rb_raise(rb_eTypeError, "no class/module to add method");
}
}
@@ -4229,6 +4229,9 @@ rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node,
klass = (VALUE)o->klass;
}
}
+ if (NIL_P(klass)) {
+ klass = 0;
+ }
if (self != 0) {
vm->set_current_top_object(self);
}

0 comments on commit 092ad9e

Please sign in to comment.