From 1f99d95729fd18bf3dc98cf9eea62df6b8353e40 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 12 Aug 2002 07:39:12 +0000 Subject: * bignum.c (rb_big_cmp): use dbl2big() for Floats, instead of big2dbl(). * bignum.c (Init_Bignum): rb_big_zero_p() removed. There may be Bignum zero. * eval.c (rb_call0): new argument added for original method name. preserve original method name in frame->orig_func. * eval.c (is_defined): use frame->orig_func, not last_func. * eval.c (rb_eval): ditto. * eval.c (method_call): supply data->oid also to rb_call0(). * object.c (rb_class_allocate_instance): call rb_obj_alloc() when called from alias, thus invoke original "allocate". * eval.c (remove_method): removing allocate from classes should cause NameError. * hash.c (rb_hash_equal): should check default values. * ext/socket/socket.c (s_recvfrom): update RSTRING len. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- eval.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 4a1aaefdaa..8de0756c2a 100644 --- a/eval.c +++ b/eval.c @@ -315,6 +315,10 @@ rb_get_method_body(klassp, idp, noexp) return body; } +static ID init, alloc, eqq, each, aref, aset, match, missing; +static ID added, singleton_added; +static ID __id__, __send__; + static void remove_method(klass, mid) VALUE klass; @@ -329,6 +333,16 @@ remove_method(klass, mid) rb_raise(rb_eSecurityError, "Insecure: can't remove method"); } if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); + if (mid == __id__ || mid == __send__ || mid == init) { + rb_warn("removing `%s' may cause serious problem", rb_id2name(mid)); + } + if (mid == alloc) { + if (klass == rb_cClass || + (FL_TEST(klass, FL_SINGLETON) && + rb_obj_is_kind_of(rb_iv_get(klass, "__attached__"), rb_cClass))) { + rb_name_error(mid, "removing `%s'", rb_id2name(mid)); + } + } if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body) || !body->nd_body) { rb_name_error(mid, "method `%s' not defined in %s", rb_id2name(mid), rb_class2name(klass)); @@ -454,10 +468,6 @@ rb_method_boundp(klass, id, ex) return Qfalse; } -static ID init, alloc, eqq, each, aref, aset, match, missing; -static ID added, singleton_added; -static ID __id__, __send__; - void rb_attr(klass, id, read, write, ex) VALUE klass; @@ -1324,6 +1334,7 @@ rb_eval_string_wrap(str, state) rb_extend_object(ruby_top_self, ruby_wrapper); PUSH_FRAME(); ruby_frame->last_func = 0; + ruby_frame->orig_func = 0; ruby_frame->last_class = 0; ruby_frame->self = self; ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,ruby_wrapper,0,0); @@ -1415,6 +1426,7 @@ rb_eval_cmd(cmd, arg, tcheck) ruby_scope = top_scope; PUSH_FRAME(); ruby_frame->last_func = 0; + ruby_frame->orig_func = 0; ruby_frame->last_class = 0; ruby_frame->self = ruby_top_self; ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,0,0,0); @@ -1621,13 +1633,10 @@ rb_undef(klass, id) rb_secure(4); } if (ruby_safe_level >= 4 && !OBJ_TAINTED(klass)) { - rb_raise(rb_eSecurityError, "Insecure: can't undef"); - if (id == __id__ || id == __send__ || id == init) { - rb_name_error(id, "undefining `%s' prohibited", rb_id2name(id)); - } + rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'", rb_id2name(id)); } rb_frozen_class_p(klass); - if (id == __id__ || id == __send__ || id == init) { + if (id == __id__ || id == __send__ || id == init || id == alloc) { rb_warn("undefining `%s' may cause serious problem", rb_id2name(id)); } body = search_method(klass, id, &origin); @@ -1844,10 +1853,10 @@ is_defined(self, node, buf) switch (nd_type(node)) { case NODE_SUPER: case NODE_ZSUPER: - if (ruby_frame->last_func == 0) return 0; + if (ruby_frame->orig_func == 0) return 0; else if (ruby_frame->last_class == 0) return 0; else if (rb_method_boundp(RCLASS(ruby_frame->last_class)->super, - ruby_frame->last_func, 0)) { + ruby_frame->orig_func, 0)) { if (nd_type(node) == NODE_SUPER) { return arg_defined(self, node->nd_args, buf, "super"); } @@ -2759,10 +2768,10 @@ rb_eval(self, n) TMP_PROTECT; if (ruby_frame->last_class == 0) { - if (ruby_frame->last_func) { + if (ruby_frame->orig_func) { rb_name_error(ruby_frame->last_func, "superclass method `%s' disabled", - rb_id2name(ruby_frame->last_func)); + rb_id2name(ruby_frame->orig_func)); } else { rb_raise(rb_eNoMethodError, "super called outside of method"); @@ -2780,7 +2789,7 @@ rb_eval(self, n) PUSH_ITER(ruby_iter->iter?ITER_PRE:ITER_NOT); result = rb_call(RCLASS(ruby_frame->last_class)->super, - ruby_frame->self, ruby_frame->last_func, + ruby_frame->self, ruby_frame->orig_func, argc, argv, 3); POP_ITER(); } @@ -4458,9 +4467,10 @@ call_cfunc(func, recv, len, argc, argv) } static VALUE -rb_call0(klass, recv, id, argc, argv, body, nosuper) +rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) VALUE klass, recv; ID id; + ID oid; int argc; /* OK */ VALUE *argv; /* OK */ NODE *body; /* OK */ @@ -4490,6 +4500,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper) PUSH_FRAME(); ruby_frame->last_func = id; + ruby_frame->orig_func = oid; ruby_frame->last_class = nosuper?0:klass; ruby_frame->self = recv; ruby_frame->argc = argc; @@ -4747,7 +4758,7 @@ rb_call(klass, recv, mid, argc, argv, scope) } } - return rb_call0(klass, recv, id, argc, argv, body, noex & NOEX_UNDEF); + return rb_call0(klass, recv, mid, id, argc, argv, body, noex & NOEX_UNDEF); } VALUE @@ -6914,7 +6925,7 @@ method_call(argc, argv, method) ruby_safe_level = 4; } if ((state = EXEC_TAG()) == 0) { - result = rb_call0(data->klass,data->recv,data->id,argc,argv,data->body,0); + result = rb_call0(data->klass,data->recv,data->id,data->oid,argc,argv,data->body,0); } POP_TAG(); POP_ITER(); -- cgit v1.2.3