From 068170e47ac498d4c905bae04fe55c5addf05d64 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 15 May 2003 07:57:07 +0000 Subject: * object.c (rb_mod_le): returns nil if two classes/modules are not in class-superclass relationship. * object.c (rb_mod_cmp): uses new rb_mod_le() behavior. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ class.c | 20 ++++++++++---------- object.c | 24 +++++++++++++++--------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d94bcbc1e..9df8373627 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu May 15 16:55:16 2003 Yukihiro Matsumoto + + * object.c (rb_mod_le): returns nil if two classes/modules are not + in class-superclass relationship. + + * object.c (rb_mod_cmp): uses new rb_mod_le() behavior. + Thu May 15 07:45:30 2003 why the lucky stiff * ext/ruby/ext/syck/rubyext.c, lib/implicit.re: timestamp repairs to @@ -7,6 +14,9 @@ Thu May 15 07:45:30 2003 why the lucky stiff Thu May 15 13:26:48 2003 Yukihiro Matsumoto + * class.c (rb_class_instance_methods): default will be changed in + 1.8.1. + * io.c (set_stdio): better message. Thu May 15 13:18:11 2003 Yukihiro Matsumoto diff --git a/class.c b/class.c index 4b93841d9f..298161860f 100644 --- a/class.c +++ b/class.c @@ -564,8 +564,8 @@ rb_class_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { -#if RUBY_RELEASE_CODE < 20040101 - rb_warn("instance_methods parameter will default to 'true' in Jan 2004"); +#if RUBY_VERSION_CODE < 181 + rb_warn("instance_methods parameter will default to 'true' after 1.8.1"); #else recur = Qtrue; #endif @@ -583,8 +583,8 @@ rb_class_protected_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { -#if RUBY_RELEASE_CODE < 20040101 - rb_warn("protected_instance_methods parameter will default to 'true' in Jan 2004"); +#if RUBY_VERSION_CODE < 181 + rb_warn("protected_instance_methods parameter will default to 'true' after 1.8.1"); #else recur = Qtrue; #endif @@ -602,8 +602,8 @@ rb_class_private_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { -#if RUBY_RELEASE_CODE < 20040101 - rb_warn("private_instance_methods parameter will default to 'true' in Jan 2004"); +#if RUBY_VERSION_CODE < 181 + rb_warn("private_instance_methods parameter will default to 'true' after 1.8.1"); #else recur = Qtrue; #endif @@ -621,8 +621,8 @@ rb_class_public_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { -#if RUBY_RELEASE_CODE < 20040101 - rb_warn("public_instance_methods parameter will default to 'true' in Jan 2004"); +#if RUBY_VERSION_CODE < 181 + rb_warn("public_instance_methods parameter will default to 'true' after 1.8.1"); #else recur = Qtrue; #endif @@ -641,8 +641,8 @@ rb_obj_singleton_methods(argc, argv, obj) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { -#if RUBY_RELEASE_CODE < 20040101 - rb_warn("singleton_methods parameter will default to 'true' in Jan 2004"); +#if RUBY_VERSION_CODE < 181 + rb_warn("singleton_methods parameter will default to 'true' after 1.8.1"); #else recur = Qtrue; #endif diff --git a/object.c b/object.c index 49e7347ee0..c9fc29d5bd 100644 --- a/object.c +++ b/object.c @@ -597,6 +597,8 @@ static VALUE rb_mod_le(mod, arg) VALUE mod, arg; { + VALUE start = mod; + if (mod == arg) return Qtrue; switch (TYPE(arg)) { case T_MODULE: @@ -611,7 +613,13 @@ rb_mod_le(mod, arg) return Qtrue; mod = RCLASS(mod)->super; } - return Qfalse; + /* not mod < arg; check if mod > arg */ + while (arg) { + if (RCLASS(arg)->m_tbl == RCLASS(start)->m_tbl) + return Qfalse; + arg = RCLASS(arg)->super; + } + return Qnil; } static VALUE @@ -650,6 +658,7 @@ rb_mod_cmp(mod, arg) VALUE mod, arg; { VALUE start = mod; + VALUE cmp; if (mod == arg) return INT2FIX(0); switch (TYPE(arg)) { @@ -660,16 +669,13 @@ rb_mod_cmp(mod, arg) return Qnil; } - if (rb_mod_le(mod, arg)) { - return INT2FIX(-1); - } + cmp = rb_mod_le(mod, arg); - while (arg) { - if (RCLASS(arg)->m_tbl == RCLASS(start)->m_tbl) - return INT2FIX(1); - arg = RCLASS(arg)->super; + if (cmp) { + return INT2FIX(-1); } - return Qnil; + if (NIL_P(cmp)) return Qnil; + return INT2FIX(1); } static VALUE -- cgit v1.2.3