diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-10 11:49:14 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-10 11:49:14 +0000 |
commit | b416c57c0a998c6f2435e419860b7645508816d6 (patch) | |
tree | ef5294184f4d584d318e96c7174a6d41080dde11 /eval.c | |
parent | 509fa974311b936279d9c25544fb06f41771ea0b (diff) | |
download | ruby-b416c57c0a998c6f2435e419860b7645508816d6.tar.gz |
* eval.c (method_proc): return bound Proc object. [ruby-dev:22854]
* eval.c (rb_mod_define_method): bind method body itself for Method
object.
* node.h (NODE_DMETHOD): deprecated.
* object.c (rb_class_inherited_p): export.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -5437,10 +5437,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) result = rb_eval(recv, body); break; - case NODE_DMETHOD: - result = method_call(argc, argv, umethod_bind(body->nd_cval, recv)); - break; - case NODE_BMETHOD: result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass); break; @@ -8781,7 +8777,6 @@ method_arity(method) case NODE_IVAR: return INT2FIX(0); case NODE_BMETHOD: - case NODE_DMETHOD: return proc_arity(body->nd_cval); default: body = body->nd_next; /* skip NODE_SCOPE */ @@ -8907,8 +8902,11 @@ method_proc(method) struct METHOD *mdata; struct BLOCK *bdata; - proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, bmcall, method); Data_Get_Struct(method, struct METHOD, mdata); + if (nd_type(mdata->body) == NODE_BMETHOD) { + return mdata->body->nd_cval; + } + proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, bmcall, method); Data_Get_Struct(proc, struct BLOCK, bdata); bdata->body->nd_file = mdata->body->nd_file; nd_set_line(bdata->body, nd_line(mdata->body)); @@ -8991,7 +8989,18 @@ rb_mod_define_method(argc, argv, mod) rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc); } if (RDATA(body)->dmark == (RUBY_DATA_FUNC)bm_mark) { - node = NEW_DMETHOD(method_unbind(body)); + struct METHOD *method = (struct METHOD *)DATA_PTR(body); + VALUE rklass = method->rklass; + if (rklass != mod) { + if (FL_TEST(rklass, FL_SINGLETON)) { + rb_raise(rb_eTypeError, "cannot bind singleton method to a different class"); + } + if (RCLASS(rklass)->super && !RTEST(rb_class_inherited_p(mod, rklass))) { + rb_raise(rb_eTypeError, "bind argument must be a subclass of %s", + rb_class2name(rklass)); + } + } + node = method->body; } else if (RDATA(body)->dmark == (RUBY_DATA_FUNC)blk_mark) { struct BLOCK *block; |