diff --git a/ChangeLog b/ChangeLog index 7481bb7a13..b92d843958 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Sep 13 22:18:33 2009 Nobuyoshi Nakada + + * variable.c (rb_mod_remove_const): do not change VM state when an + exception will occur. + Sun Sep 13 21:25:01 2009 Masaki Suketa * ext/win32ole/win32ole.c (oletypelib_get_libattr): some refactoring diff --git a/variable.c b/variable.c index ea7dfbb0da..4b73b5c0be 100644 --- a/variable.c +++ b/variable.c @@ -1596,8 +1596,6 @@ rb_mod_remove_const(VALUE mod, VALUE name) VALUE val; st_data_t v, n = id; - rb_vm_change_state(); - if (!rb_is_const_id(id)) { rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id)); } @@ -1605,21 +1603,23 @@ rb_mod_remove_const(VALUE mod, VALUE name) rb_raise(rb_eSecurityError, "Insecure: can't remove constant"); if (OBJ_FROZEN(mod)) rb_error_frozen("class/module"); - if (RCLASS_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &v)) { - val = (VALUE)v; - if (val == Qundef) { - autoload_delete(mod, id); - val = Qnil; + if (!RCLASS_IV_TBL(mod) || !st_delete(RCLASS_IV_TBL(mod), &n, &v)) { + if (rb_const_defined_at(mod, id)) { + rb_name_error(id, "cannot remove %s::%s", + rb_class2name(mod), rb_id2name(id)); } - return val; + rb_name_error(id, "constant %s::%s not defined", + rb_class2name(mod), rb_id2name(id)); } - if (rb_const_defined_at(mod, id)) { - rb_name_error(id, "cannot remove %s::%s", - rb_class2name(mod), rb_id2name(id)); + + rb_vm_change_state(); + + val = (VALUE)v; + if (val == Qundef) { + autoload_delete(mod, id); + val = Qnil; } - rb_name_error(id, "constant %s::%s not defined", - rb_class2name(mod), rb_id2name(id)); - return Qnil; /* not reached */ + return val; } static int