summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-28 03:09:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-28 03:09:16 +0000
commited89a3bb20eafd6a564929833e6a4134ad84fdf0 (patch)
tree81ff0a9316d3abe54e8aff5e33e4729faeaff3f1
parent191e9c2260f4f1a0f572fc4c29eae73c60270b3b (diff)
downloadruby-ed89a3bb20eafd6a564929833e6a4134ad84fdf0.tar.gz
ruby-ed89a3bb20eafd6a564929833e6a4134ad84fdf0.tar.xz
ruby-ed89a3bb20eafd6a564929833e6a4134ad84fdf0.zip
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--method.h3
-rw-r--r--proc.c37
-rw-r--r--test/ruby/test_object.rb3
-rw-r--r--vm_eval.c8
-rw-r--r--vm_insnhelper.c8
-rw-r--r--vm_method.c2
6 files changed, 43 insertions, 18 deletions
diff --git a/method.h b/method.h
index 8090b6354..b6ed9b64e 100644
--- a/method.h
+++ b/method.h
@@ -39,7 +39,8 @@ typedef enum {
VM_METHOD_TYPE_ZSUPER,
VM_METHOD_TYPE_UNDEF,
VM_METHOD_TYPE_NOTIMPLEMENTED,
- VM_METHOD_TYPE_OPTIMIZED /* Kernel#send, Proc#call, etc */
+ VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
+ VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
} rb_method_type_t;
typedef struct rb_method_cfunc_struct {
diff --git a/proc.c b/proc.c
index c9f36b989..1b5e5bc63 100644
--- a/proc.c
+++ b/proc.c
@@ -884,36 +884,36 @@ rb_obj_is_method(VALUE m)
}
static VALUE
-missing_wrap(VALUE dummy, VALUE args, int argc, VALUE *argv)
-{
- VALUE new_args = rb_ary_new4(argc, argv);
- VALUE obj = RARRAY_PTR(args)[0];
- VALUE sym = RARRAY_PTR(args)[1];
-
- rb_ary_unshift(new_args, sym);
- return rb_funcall2(obj, rb_intern("method_missing"),
- check_argc(RARRAY_LEN(new_args)), RARRAY_PTR(new_args));
-}
-
-static VALUE
mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
{
VALUE method;
VALUE rclass = klass;
ID rid = id;
struct METHOD *data;
- rb_method_entry_t *me;
- rb_method_definition_t *def;
+ rb_method_entry_t *me, meb;
+ rb_method_definition_t *def = 0;
again:
- me = rb_method_entry(klass, id);
+ me = rb_method_entry(klass, id);
if (UNDEFINED_METHOD_ENTRY_P(me)) {
ID rmiss = rb_intern("respond_to_missing?");
VALUE sym = ID2SYM(id);
if (obj != Qundef && !rb_method_basic_definition_p(klass, rmiss)) {
if (RTEST(rb_funcall(obj, rmiss, 1, sym))) {
- return rb_proc_new(missing_wrap, rb_assoc_new(obj, sym));
+ def = ALLOC(rb_method_definition_t);
+ def->type = VM_METHOD_TYPE_MISSING;
+ def->original_id = id;
+ def->alias_count = 0;
+
+ meb.flag = 0;
+ meb.called_id = id;
+ meb.klass = klass;
+ meb.def = def;
+ me = &meb;
+ def = 0;
+
+ goto gen_method;
}
}
rb_print_undef(klass, id, 0);
@@ -922,7 +922,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
if (scope && (me->flag & NOEX_MASK) != NOEX_PUBLIC) {
rb_print_undef(rclass, def->original_id, (int)(me->flag & NOEX_MASK));
}
- if (def->type == VM_METHOD_TYPE_ZSUPER) {
+ if (def && def->type == VM_METHOD_TYPE_ZSUPER) {
klass = RCLASS_SUPER(me->klass);
id = def->original_id;
goto again;
@@ -939,6 +939,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
klass = RBASIC(klass)->klass;
}
+ gen_method:
method = TypedData_Make_Struct(mclass, struct METHOD, &method_data_type, data);
data->recv = obj;
@@ -1552,6 +1553,8 @@ rb_method_entry_arity(const rb_method_entry_t *me)
case VM_METHOD_TYPE_UNDEF:
case VM_METHOD_TYPE_NOTIMPLEMENTED:
return 0;
+ case VM_METHOD_TYPE_MISSING:
+ return -1;
case VM_METHOD_TYPE_OPTIMIZED: {
switch (def->body.optimize_type) {
case OPTIMIZED_METHOD_TYPE_SEND:
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index e4026eccb..8effe0231 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -333,9 +333,12 @@ class TestObject < Test::Unit::TestCase
end
foobar = foo.method(:foobar)
+ assert_equal(-1, foobar.arity);
assert_equal([:foo], foobar.call);
assert_equal([:foo, 1], foobar.call(1));
assert_equal([:foo, 1, 2, 3, 4, 5], foobar.call(1, 2, 3, 4, 5));
+ assert_equal(foobar, foo.method(:foobar))
+ assert_not_equal(foobar, c.new.method(:foobar))
c = Class.new(c)
assert_equal(false, c.method_defined?(:foobar))
diff --git a/vm_eval.c b/vm_eval.c
index befe33adc..8597bfb06 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -110,6 +110,14 @@ vm_call0(rb_thread_t* th, VALUE recv, VALUE id, int argc, const VALUE *argv,
if (!(def = me->def)) return Qnil;
goto again;
}
+ case VM_METHOD_TYPE_MISSING: {
+ VALUE new_args = rb_ary_new4(argc, argv);
+
+ RB_GC_GUARD(new_args);
+ rb_ary_unshift(new_args, ID2SYM(id));
+ return rb_funcall2(recv, rb_intern("method_missing"),
+ argc+1, RARRAY_PTR(new_args));
+ }
case VM_METHOD_TYPE_OPTIMIZED: {
switch (def->body.optimize_type) {
case OPTIMIZED_METHOD_TYPE_SEND:
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 8fc7c1dcd..25b0d5b3b 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -527,6 +527,14 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp,
cfp->sp -= 1;
break;
}
+ case VM_METHOD_TYPE_MISSING:{
+ VALUE *argv = ALLOCA_N(VALUE, num+1);
+ argv[0] = ID2SYM(me->def->original_id);
+ MEMCPY(argv+1, cfp->sp - num, VALUE, num);
+ cfp->sp += - num - 1;
+ val = rb_funcall2(recv, rb_intern("method_missing"), num+1, argv);
+ break;
+ }
case VM_METHOD_TYPE_BMETHOD:{
VALUE *argv = ALLOCA_N(VALUE, num);
MEMCPY(argv, cfp->sp - num, VALUE, num);
diff --git a/vm_method.c b/vm_method.c
index c95554db9..637e75df1 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -810,6 +810,8 @@ rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
return d1->body.attr_id == d2->body.attr_id;
case VM_METHOD_TYPE_BMETHOD:
return RTEST(rb_equal(d1->body.proc, d2->body.proc));
+ case VM_METHOD_TYPE_MISSING:
+ return d1->original_id == d2->original_id;
case VM_METHOD_TYPE_ZSUPER:
case VM_METHOD_TYPE_NOTIMPLEMENTED:
case VM_METHOD_TYPE_UNDEF: