* proc.c (umethod_bind, rb_mod_define_method): Fix bug that disallowed methods from singleton classes to be used for UnboundMethod#bind, Kernel#define_singleton_method and Module#define_method, even when that singleton class was of the right kind_of. A patch by Shane O'Brien [ruby-core:25632]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
78ddb4f603
commit
92304aa3cd
@ -1,3 +1,11 @@
|
|||||||
|
Wed Sep 23 05:03:36 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* proc.c (umethod_bind, rb_mod_define_method): Fix bug that
|
||||||
|
disallowed methods from singleton classes to be used for
|
||||||
|
UnboundMethod#bind, Kernel#define_singleton_method and
|
||||||
|
Module#define_method, even when that singleton class was of the right
|
||||||
|
kind_of. A patch by Shane O'Brien [ruby-core:25632]
|
||||||
|
|
||||||
Tue Sep 22 16:34:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Sep 22 16:34:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* st.c (st_table_entry, st_get_key): use st_index_t.
|
* st.c (st_table_entry, st_get_key): use st_index_t.
|
||||||
|
9
proc.c
9
proc.c
@ -1249,12 +1249,12 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
|
|||||||
if (rb_obj_is_method(body)) {
|
if (rb_obj_is_method(body)) {
|
||||||
struct METHOD *method = (struct METHOD *)DATA_PTR(body);
|
struct METHOD *method = (struct METHOD *)DATA_PTR(body);
|
||||||
VALUE rclass = method->rclass;
|
VALUE rclass = method->rclass;
|
||||||
if (rclass != mod) {
|
if (rclass != mod && !RTEST(rb_class_inherited_p(mod, rclass))) {
|
||||||
if (FL_TEST(rclass, FL_SINGLETON)) {
|
if (FL_TEST(rclass, FL_SINGLETON)) {
|
||||||
rb_raise(rb_eTypeError,
|
rb_raise(rb_eTypeError,
|
||||||
"can't bind singleton method to a different class");
|
"can't bind singleton method to a different class");
|
||||||
}
|
}
|
||||||
if (!RTEST(rb_class_inherited_p(mod, rclass))) {
|
else {
|
||||||
rb_raise(rb_eTypeError,
|
rb_raise(rb_eTypeError,
|
||||||
"bind argument must be a subclass of %s",
|
"bind argument must be a subclass of %s",
|
||||||
rb_class2name(rclass));
|
rb_class2name(rclass));
|
||||||
@ -1481,12 +1481,13 @@ umethod_bind(VALUE method, VALUE recv)
|
|||||||
struct METHOD *data, *bound;
|
struct METHOD *data, *bound;
|
||||||
|
|
||||||
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
|
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
|
||||||
if (data->rclass != CLASS_OF(recv)) {
|
|
||||||
|
if (data->rclass != CLASS_OF(recv) && !rb_obj_is_kind_of(recv, data->rclass)) {
|
||||||
if (FL_TEST(data->rclass, FL_SINGLETON)) {
|
if (FL_TEST(data->rclass, FL_SINGLETON)) {
|
||||||
rb_raise(rb_eTypeError,
|
rb_raise(rb_eTypeError,
|
||||||
"singleton method called for a different object");
|
"singleton method called for a different object");
|
||||||
}
|
}
|
||||||
if (!rb_obj_is_kind_of(recv, data->rclass)) {
|
else {
|
||||||
rb_raise(rb_eTypeError, "bind argument must be an instance of %s",
|
rb_raise(rb_eTypeError, "bind argument must be an instance of %s",
|
||||||
rb_class2name(data->rclass));
|
rb_class2name(data->rclass));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user