From 949f6fe394817675aee9277fbd7777bf360fabdf Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 7 Dec 2005 17:08:40 +0000 Subject: [PATCH] * eval.c (umethod_bind): adjust invoking class for module method. [ruby-dev:27964] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 ++++++++--- eval.c | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b8e50c1a0..70fd2d3aa6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 8 02:07:19 2005 Nobuyoshi Nakada + + * eval.c (umethod_bind): adjust invoking class for module method. + [ruby-dev:27964] + Thu Dec 8 00:40:52 2005 Yukihiro Matsumoto * eval.c (call_trace_func): klass parameter should be a @@ -27,11 +32,11 @@ Wed Dec 7 01:02:04 2005 Hidetoshi NAGAI * ext/tk/README.macosx-aqua: [new document] tips to avoid the known bug on platform specific dialogs of Tcl/Tk Aqua on MacOS X. - * ext/tk/tcltklib.c: fix bug on switching threads and waiting on the - deleted interpreter on vwait and tkwait command. + * ext/tk/tcltklib.c: fix bug on switching threads and waiting on the + deleted interpreter on vwait and tkwait command. * ext/tk/lib/multi-tk.rb: kill the meaningless loop for the deleted Tk - interpreter. + interpreter. * ext/tk/sample/demos-jp/image3.rb: [bug fix] wrong argument. diff --git a/eval.c b/eval.c index c46bb5e69c..fe4d521c31 100644 --- a/eval.c +++ b/eval.c @@ -8967,13 +8967,22 @@ static VALUE umethod_bind(VALUE method, VALUE recv) { struct METHOD *data, *bound; + VALUE rklass = CLASS_OF(recv), klass = rklass; Data_Get_Struct(method, struct METHOD, data); - if (data->rklass != CLASS_OF(recv)) { + if (data->rklass != rklass) { if (FL_TEST(data->rklass, FL_SINGLETON)) { rb_raise(rb_eTypeError, "singleton method called for a different object"); } - if(!rb_obj_is_kind_of(recv, data->rklass)) { + if (TYPE(data->rklass) == T_MODULE) { + st_table *m_tbl = RCLASS(data->rklass)->m_tbl; + while (RCLASS(rklass)->m_tbl != m_tbl) { + rklass = RCLASS(rklass)->super; + if (!rklass) goto not_instace; + } + } + else if (!rb_obj_is_kind_of(recv, data->rklass)) { + not_instace: rb_raise(rb_eTypeError, "bind argument must be an instance of %s", rb_class2name(data->rklass)); } @@ -8982,7 +8991,8 @@ umethod_bind(VALUE method, VALUE recv) method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound); *bound = *data; bound->recv = recv; - bound->rklass = CLASS_OF(recv); + bound->klass = klass; + bound->rklass = rklass; return method; }