[#17881] Re: [ruby-list:35696] Re: サブクラスのオブジェクト生成時に、スーパークラスの初期化を行うには ? — nobu.nakada@...

なかだです。

14 messages 2002/08/02
[#17883] Re: [ruby-list:35696] Re: サブクラスのオブジェクト生成時に、スーパークラスの初期化を行うには ? — nobu.nakada@... 2002/08/02

なかだです。

[#17906] Re: [ruby-list:35696] Re: サブクラスのオブジェクト生成時に、スーパークラスの初期化を行うには ? — Takaaki Tateishi <ttate@...> 2002/08/03

At Fri, 2 Aug 2002 12:17:33 +0900,

[#17908] Re: [ruby-list:35696] Re: サブクラスのオブジェクト生成時に、スーパークラスの初期化を行うには ? — matz@... (Yukihiro Matsumoto) 2002/08/03

まつもと ゆきひろです

[#17909] Re: [ruby-list:35696] Re: サブクラスのオブジェクト生成時に、スーパークラスの初期化を行うには ? — Takaaki Tateishi <ttate@...> 2002/08/03

At Sat, 3 Aug 2002 23:32:39 +0900,

[#17887] next parser (Re: parenthesize argument(s) for future version) — Minero Aoki <aamine@...>

あおきです。スレッド切ります。

18 messages 2002/08/02
[#17895] Re: next parser (Re: parenthesize argument(s) for future version) — matz@... (Yukihiro Matsumoto) 2002/08/03

まつもと ゆきひろです

[#17898] Re: next parser (Re: parenthesize argument(s) for future version) — Minero Aoki <aamine@...> 2002/08/03

あおきです。

[#17904] Re: next parser (Re: parenthesize argument(s) for future version) — matz@... (Yukihiro Matsumoto) 2002/08/03

まつもと ゆきひろです

[#17920] Re: next parser (Re: parenthesize argument(s) for future version) — Minero Aoki <aamine@...> 2002/08/04

あおきです。

[#17933] Re: next parser (Re: parenthesize argument(s) for future version) — matz@... (Yukihiro Matsumoto) 2002/08/06

まつもと ゆきひろです

[#17889] ruby-bugs-ja incoming/277 — Takaaki Tateishi <ttate@...>

立石です.

15 messages 2002/08/02
[#17890] Re: ruby-bugs-ja incoming/277 — Takaaki Tateishi <ttate@...> 2002/08/02

At Sat, 3 Aug 2002 05:13:32 +0900,

[#17927] Re: import-module (Re: Re: scope-in-state) — keiju@... (石塚圭樹)

けいじゅ@日本ラショナルソフトウェアです.

13 messages 2002/08/05
[#17943] Re: import-module (Re: Re: scope-in-state) — Shin-ichiro HARA <sinara@...> 2002/08/06

原です。

[#17949] Re: import-module (Re: Re: scope-in-state) — keiju@... (石塚圭樹) 2002/08/06

けいじゅ@日本ラショナルソフトウェアです.

[#17955] Re: import-module (Re: Re: scope-in-state) — Shin-ichiro HARA <sinara@...> 2002/08/07

原です。

[#17954] Selection IPv4/IPv6 at TCPSocket — NISHI Takao <zophos@...9.com>

にし@おかやまです。

19 messages 2002/08/07
[#18120] Re: Selection IPv4/IPv6 at TCPSocket — "Akinori MUSHA" <knu@...> 2002/08/31

At Wed, 7 Aug 2002 13:23:37 +0900,

[#18121] Re: Selection IPv4/IPv6 at TCPSocket — GOTO Kentaro <gotoken@...> 2002/08/31

At Sun, 1 Sep 2002 03:31:01 +0900,

[#18127] Re: Selection IPv4/IPv6 at TCPSocket — "Akinori MUSHA" <knu@...> 2002/09/01

At Sun, 1 Sep 2002 04:00:33 +0900,

[#18128] Re: Selection IPv4/IPv6 at TCPSocket — "Akinori MUSHA" <knu@...> 2002/09/01

At Sun, 1 Sep 2002 12:37:05 +0900,

[#18130] Re: Selection IPv4/IPv6 at TCPSocket — GOTO Kentaro <gotoken@...> 2002/09/01

At Sun, 1 Sep 2002 13:00:46 +0900,

[#18131] Re: Selection IPv4/IPv6 at TCPSocket — Minero Aoki <aamine@...> 2002/09/01

あおきです。

[#17965] inferior-ruby-mode and irb — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

22 messages 2002/08/09
[#17971] Re: inferior-ruby-mode and irb — matz@... (Yukihiro Matsumoto) 2002/08/10

まつもと ゆきひろです

[#18008] Re: inferior-ruby-mode and irb — keiju@... (石塚圭樹) 2002/08/14

けいじゅ@日本ラショナルソフトウェアです.

[#17966] Hash has default block? — Tanaka Akira <akr@...17n.org>

ふと、ひさしぶりに(一年ぶりくらい?) AMarshal に手を入れていて気になっ

34 messages 2002/08/09
[#17967] Re: Hash has default block? — "K.Kosako" <kosako@...> 2002/08/09

Tanaka Akiraさんの<hvo8z3gnvr6.fsf@coulee.a02.aist.go.jp>から

[#17969] Re: Hash has default block? — Tanaka Akira <akr@...17n.org> 2002/08/09

In article <20020809121059.B6DC51560@helium.ruby-lang.org>,

[#17977] Re: Hash has default block? — "K.Kosako" <kosako@...> 2002/08/12

Tanaka Akiraさんの<hvo65yknitf.fsf@coulee.a02.aist.go.jp>から

[#17989] Re: Hash has default block? — Tanaka Akira <akr@...17n.org> 2002/08/13

In article <20020812052018.C7F9B1671@helium.ruby-lang.org>,

[#17990] Re: Hash has default block? — matz@... (Yukihiro Matsumoto) 2002/08/13

まつもと ゆきひろです

[#17991] Re: Hash has default block? — matz@... (Yukihiro Matsumoto) 2002/08/13

まつもと ゆきひろです

[#17998] Re: Hash has default block? — "K.Kosako" <kosako@...> 2002/08/13

Yukihiro Matsumotoさんの

[#17999] Re: Hash has default block? — Tanaka Akira <akr@...17n.org> 2002/08/13

In article <20020813075933.DBB611415@helium.ruby-lang.org>,

[#18000] Re: Hash has default block? — matz@... (Yukihiro Matsumoto) 2002/08/13

まつもと ゆきひろです

[#18004] allocation framework — Tanaka Akira <akr@...17n.org> 2002/08/13

In article <1029229143.399680.2549.nullmailer@picachu.netlab.jp>,

[#18021] Re: allocation framework — matz@... (Yukihiro Matsumoto) 2002/08/15

まつもと ゆきひろです

[#18022] Re: allocation framework — Tanaka Akira <akr@...17n.org> 2002/08/15

In article <1029423141.763951.25373.nullmailer@picachu.netlab.jp>,

[#18023] Re: allocation framework — matz@... (Yukihiro Matsumoto) 2002/08/16

まつもと ゆきひろです

[#18024] Re: allocation framework — Tanaka Akira <akr@...17n.org> 2002/08/16

In article <1029464034.601483.27585.nullmailer@picachu.netlab.jp>,

[#18074] source file name at -r option — nobu.nakada@...

なかだです。

30 messages 2002/08/24
[#18352] Re: source file name at -r option — nobu.nakada@... 2002/09/22

なかだです。

[#18662] Re: ENABLE/DISABLE_TRACE (was Re: source file name at -r option) — "NAKAMURA, Hiroshi" <nakahiro@...> 2002/11/06

なひです。

[#18663] Re: ENABLE/DISABLE_TRACE (was Re: source file name at -r option) — nobu.nakada@... 2002/11/06

なかだです。

[#18667] Re: ENABLE/DISABLE_TRACE (was Re: source file name at -r option) — matz@... (Yukihiro Matsumoto) 2002/11/06

まつもと ゆきひろです

[#18673] Re: ENABLE/DISABLE_TRACE (was Re: source file name at -r option) — nobu.nakada@... 2002/11/07

なかだです。

[#18076] Win32 signal, process etc — nobu.nakada@...

なかだです。

14 messages 2002/08/24

[#18103] autoload patch for ruby-1.7 — "Yoshinori K. Okuji" <okuji@...>

[ruby-dev:16180]でトップレベル以外の定数についてもautoloadができるよう

24 messages 2002/08/29
[#18132] Re: autoload patch for ruby-1.7 — Minero Aoki <aamine@...> 2002/09/01

あおきです。

[#18139] Re: autoload patch for ruby-1.7 — "Yoshinori K. Okuji" <okuji@...> 2002/09/01

At Sun, 1 Sep 2002 15:53:24 +0900,

[#18145] Re: autoload patch for ruby-1.7 — Minero Aoki <aamine@...> 2002/09/02

あおきです。

[#18109] mkmf.rb and extmk.rb — WATANABE Hirofumi <eban@...>

わたなべです。

24 messages 2002/08/30
[#18157] Re: mkmf.rb and extmk.rb — matz@... (Yukihiro Matsumoto) 2002/09/03

まつもと ゆきひろです

[#18159] Re: mkmf.rb and extmk.rb — WATANABE Hirofumi <eban@...> 2002/09/03

わたなべです。

[ruby-dev:18103] autoload patch for ruby-1.7

From: "Yoshinori K. Okuji" <okuji@...>
Date: 2002-08-29 23:09:41 UTC
List: ruby-dev #18103
[ruby-dev:16180]でトップレベル以外の定数についてもautoloadができるよう
にするパッチを拝見しました。[ruby-dev:16185]でまつもとさんが1.7系に修
正することを提案されてましたが、その後特に動きはないようだったので、

* 今日のCVS版に合わせて修正する
* バグっぽかった所を修正する
* コーディング・スタイルが一部一致していなかった所を修正する

ということを行いました。make testが通ること、[ruby-dev:16180]に添付さ
れていたスクリプトが予期された動作をすること、変更後、誤差の範囲内でし
かパフォーマンスの違いがないこと(これはmake testで計測しました)、の三
点を確認しました。このパッチを添付いたします。

動機を説明しておきます。私が微妙に(?)関係しているBioRubyでは、すでに
たくさんのモジュールやクラスが実装されていて、多くの場合、それらの大部
分を使うことはありません。しかし、現在は利便性を考慮して、全部のファイ
ルをrequireするファイルがあり、それをruby-1.6.7でロードすると、それだ
けで1秒以上の時間がかかります。

まだBioRuby自体ではテストしていないのですが、私が手元で行った簡単なテ
ストで、ほとんど空、つまり、「module モジュール名; end」しか入っていな
いファイルを100個作り、それらをrequireした場合とautoloadした場合で時間
を比較すると、約10倍程度の差がありました。

BioRubyではモジュールの下にモジュールやクラスが多く定義されているので、
autoloadがトップレベル以外でも利用できると、その効果は絶大なのではない
かと期待しています。

おくじ

Attachments (1)

ruby-1.7-autoload.patch (11.1 KB, text/x-diff)
Index: class.c
===================================================================
RCS file: /src/ruby/class.c,v
retrieving revision 1.43
diff -u -r1.43 class.c
--- class.c	2002/08/27 08:31:05	1.43
+++ class.c	2002/08/29 22:35:20
@@ -181,9 +181,6 @@
     ID id;
 
     id = rb_intern(name);
-    if (rb_autoload_defined(id)) {
-	rb_autoload_load(id);
-    }
     if (rb_const_defined(rb_cObject, id)) {
 	klass = rb_const_get(rb_cObject, id);
 	if (TYPE(klass) != T_CLASS) {
@@ -270,9 +267,6 @@
     ID id;
 
     id = rb_intern(name);
-    if (rb_autoload_defined(id)) {
-	rb_autoload_load(id);
-    }
     if (rb_const_defined(rb_cObject, id)) {
 	module = rb_const_get(rb_cObject, id);
 	if (TYPE(module) == T_MODULE)
Index: eval.c
===================================================================
RCS file: /src/ruby/eval.c,v
retrieving revision 1.323
diff -u -r1.323 eval.c
--- eval.c	2002/08/29 09:08:15	1.323
+++ eval.c	2002/08/29 22:35:21
@@ -3300,9 +3300,6 @@
 	    }
 
 	    klass = 0;
-	    if ((ruby_class == rb_cObject) && rb_autoload_defined(node->nd_cname)) {
-		rb_autoload_load(node->nd_cname);
-	    }
 	    if (rb_const_defined_at(ruby_class, node->nd_cname)) {
 		klass = rb_const_get(ruby_class, node->nd_cname);
 	    }
@@ -3346,9 +3343,6 @@
 		rb_raise(rb_eTypeError, "no outer class/module");
 	    }
 	    module = 0;
-	    if ((ruby_class == rb_cObject) && rb_autoload_defined(node->nd_cname)) {
-		rb_autoload_load(node->nd_cname);
-	    }
 	    if (rb_const_defined_at(ruby_class, node->nd_cname)) {
 		module = rb_const_get(ruby_class, node->nd_cname);
 	    }
@@ -6168,8 +6162,6 @@
     rb_define_virtual_variable("$SAFE", safe_getter, safe_setter);
 }
 
-VALUE rb_f_autoload();
-
 void
 Init_load()
 {
@@ -6183,7 +6175,6 @@
 
     rb_define_global_function("load", rb_f_load, -1);
     rb_define_global_function("require", rb_f_require, 1);
-    rb_define_global_function("autoload", rb_f_autoload, 2);
     rb_global_variable(&ruby_wrapper);
 
     ruby_dln_librefs = rb_ary_new();
Index: inits.c
===================================================================
RCS file: /src/ruby/inits.c,v
retrieving revision 1.6
diff -u -r1.6 inits.c
--- inits.c	2002/04/18 08:46:18	1.6
+++ inits.c	2002/08/29 22:35:21
@@ -13,6 +13,7 @@
 #include "ruby.h"
 
 void Init_Array _((void));
+void Init_autoload _((void));
 void Init_Bignum _((void));
 void Init_Comparable _((void));
 void Init_Dir _((void));
@@ -72,6 +73,7 @@
     Init_signal();
     Init_process();
     Init_load();
+    Init_autoload();
     Init_Proc();
     Init_Math();
     Init_GC();
Index: intern.h
===================================================================
RCS file: /src/ruby/intern.h,v
retrieving revision 1.92
diff -u -r1.92 intern.h
--- intern.h	2002/08/19 05:56:05	1.92
+++ intern.h	2002/08/29 22:35:21
@@ -398,8 +398,6 @@
 void rb_set_class_path _((VALUE, VALUE, const char*));
 VALUE rb_path2class _((const char*));
 void rb_name_class _((VALUE, ID));
-void rb_autoload _((const char*, const char*));
-VALUE rb_f_autoload _((VALUE, VALUE, VALUE));
 void rb_gc_mark_global_tbl _((void));
 VALUE rb_f_trace_var _((int, VALUE*));
 VALUE rb_f_untrace_var _((int, VALUE*));
@@ -423,14 +421,12 @@
 VALUE rb_mod_constants _((VALUE));
 VALUE rb_mod_remove_const _((VALUE, VALUE));
 int rb_const_defined_at _((VALUE, ID));
-int rb_autoload_defined _((ID));
 int rb_const_defined _((VALUE, ID));
 VALUE rb_const_get _((VALUE, ID));
 VALUE rb_const_get_at _((VALUE, ID));
 void rb_const_set _((VALUE, ID, VALUE));
 void rb_const_assign _((VALUE, ID, VALUE));
 VALUE rb_mod_constants _((VALUE));
-void rb_autoload_load _((ID));
 VALUE rb_cvar_defined _((VALUE, ID));
 void rb_cvar_set _((VALUE, ID, VALUE, int));
 VALUE rb_cvar_get _((VALUE, ID));
Index: variable.c
===================================================================
RCS file: /src/ruby/variable.c,v
retrieving revision 1.66
diff -u -r1.66 variable.c
--- variable.c	2002/08/28 14:59:01	1.66
+++ variable.c	2002/08/29 22:35:21
@@ -253,39 +253,6 @@
     rb_iv_set(klass, "__classid__", ID2SYM(id));
 }
 
-static st_table *autoload_tbl = 0;
-
-static void
-rb_autoload_id(id, filename)
-    ID id;
-    const char *filename;
-{
-    rb_secure(4);
-    if (!rb_is_const_id(id)) {
-	rb_name_error(id, "autoload must be constant name");
-    }
-
-    if (!autoload_tbl) {
-	autoload_tbl = st_init_numtable();
-    }
-    st_insert(autoload_tbl, id, strdup(filename));
-}
-
-void
-rb_autoload(klass, filename)
-    const char *klass, *filename;
-{
-    rb_autoload_id(rb_intern(klass), filename);
-}
-
-VALUE
-rb_f_autoload(obj, klass, file)
-    VALUE obj, klass, file;
-{
-    rb_autoload_id(rb_to_id(klass), StringValuePtr(file));
-    return Qnil;
-}
-
 char *
 rb_class2name(klass)
     VALUE klass;
@@ -1070,6 +1037,136 @@
     return Qnil;		/* not reached */
 }
 
+static VALUE autoload_tbl = Qnil;
+#define AUTOLOAD_TARGET			Qundef
+#define IS_AUTOLOAD_TARGET(obj)		((obj) == Qundef)
+#define AUTOLOAD_KEY_NEW(klass,id)	rb_ary_new3(2, klass, ID2SYM(id))
+
+static void
+autoload_add(klass, id, file)
+    VALUE klass;
+    ID id;
+    VALUE file;
+{
+    VALUE key;
+    
+    rb_secure(4);
+    Check_SafeStr(file);
+    if (!rb_is_const_id(id)) {
+	rb_raise(rb_eNameError, "autoload must be constant name",
+		 rb_id2name(id));
+    }
+    
+    key = AUTOLOAD_KEY_NEW(klass, id);
+    rb_hash_aset(autoload_tbl, key, file);
+}
+
+static VALUE
+rb_mod_autoload(mod, sym, file)
+    VALUE mod;
+    VALUE sym;
+    VALUE file;
+{
+    ID id = rb_to_id(sym);
+    
+    if (rb_const_defined_at(mod,id))
+	return Qnil;
+    
+    rb_const_set(mod, id, AUTOLOAD_TARGET);
+    autoload_add(mod, id, file);
+    
+    return Qnil;
+}
+
+static VALUE
+rb_f_autoload(obj, sym, file)
+    VALUE obj;
+    VALUE sym;
+    VALUE file;
+{
+    /* I use ruby_class instead of obj, as same as NODE_CDECL,
+     * assuming autoload is another way of const_set.
+     */
+    return rb_mod_autoload(ruby_class, sym, file);
+}
+
+static void
+autoload_delete(klass, id)
+    VALUE klass;
+    VALUE id;
+{
+    VALUE key = AUTOLOAD_KEY_NEW(klass, id);
+    rb_hash_delete(autoload_tbl, key);
+}
+
+static void
+autoload_load(klass, id)
+    VALUE klass;
+    ID id;
+{
+    VALUE key, file;
+    
+    if (RCLASS(klass)->iv_tbl) {
+	VALUE value;
+	
+	st_delete(ROBJECT(klass)->iv_tbl, &id, &value);
+	if (! IS_AUTOLOAD_TARGET(value))
+	    rb_bug("autoload_laod: removed normal constant: %s::%s",
+		   rb_class2name(klass), rb_id2name(id));
+    }
+    else {
+	rb_bug("autoload_load: constant not found: %s::%s",
+	       rb_class2name(klass), rb_id2name(id));
+    }
+    
+    key = AUTOLOAD_KEY_NEW(klass, id);
+    file = rb_hash_delete(autoload_tbl, key);
+    
+    if (NIL_P(file)) {
+	rb_bug("autoload file not found for %s::%s",
+	       rb_class2name(klass), rb_id2name(id));
+    }
+    
+    if (rb_provided(RSTRING(file)->ptr)) return;
+    
+    FL_UNSET(file, FL_TAINT);
+    rb_f_require(Qnil, file);
+}
+
+static VALUE
+rb_mod_autoload_p(mod, sym)
+    VALUE mod;
+    VALUE sym;
+{
+    ID id = rb_to_id(sym);
+    
+    if (NIL_P(rb_hash_aref(autoload_tbl, AUTOLOAD_KEY_NEW(mod,id))))
+	return Qfalse;
+    
+    return Qtrue;
+}
+
+static VALUE
+rb_f_autoload_p(self, sym)
+    VALUE self;
+    VALUE sym;
+{
+    /* use ruby_class as same as rb_f_autoload. */
+    return rb_mod_autoload_p(ruby_class, sym);
+}
+
+void
+Init_autoload()
+{
+    autoload_tbl = rb_hash_new();
+    rb_global_variable(&autoload_tbl);
+    
+    rb_define_method(rb_cModule, "autoload",  rb_mod_autoload,   2);
+    rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1);
+    rb_define_global_function("autoload",  rb_f_autoload,   2);
+    rb_define_global_function("autoload?", rb_f_autoload_p, 1);
+}
+
 static int
 top_const_get(id, klassp)
     ID id;
@@ -1077,13 +1174,6 @@
 {
     /* pre-defined class */
     if (st_lookup(rb_class_tbl, id, klassp)) return Qtrue;
-
-    /* autoload */
-    if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) {
-	rb_autoload_load(id);
-	*klassp = rb_const_get(rb_cObject, id);
-	return Qtrue;
-    }
     return Qfalse;
 }
 
@@ -1094,7 +1184,12 @@
 {
     VALUE value;
 
+ retry:
     if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, &value)) {
+	if (IS_AUTOLOAD_TARGET(value)) {
+	    autoload_load(klass, id);
+	    goto retry;
+	}
 	return value;
     }
     if (klass == rb_cObject && top_const_get(id, &value)) {
@@ -1106,24 +1201,6 @@
     return Qnil;		/* not reached */
 }
 
-void
-rb_autoload_load(id)
-    ID id;
-{
-    char *modname;
-    VALUE module;
-
-    st_delete(autoload_tbl, &id, &modname);
-    if (rb_provided(modname)) {
-	free(modname);
-	return;
-    }
-    module = rb_str_new2(modname);
-    free(modname);
-    FL_UNSET(module, FL_TAINT);
-    rb_f_require(Qnil, module);
-}
-
 VALUE
 rb_const_get(klass, id)
     VALUE klass;
@@ -1136,6 +1213,10 @@
   retry:
     while (tmp) {
 	if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
+	    if (IS_AUTOLOAD_TARGET(value)) {
+		autoload_load(tmp, id);
+		goto retry;
+	    }
 	    return value;
 	}
 	if (tmp == rb_cObject && top_const_get(id, &value)) return value;
@@ -1174,6 +1255,7 @@
     if (OBJ_FROZEN(mod)) rb_error_frozen("class/module");
 
     if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, &id, &val)) {
+	if (IS_AUTOLOAD_TARGET(val)) autoload_delete(mod, id);
 	return val;
     }
     if (rb_const_defined_at(mod, id)) {
@@ -1199,18 +1281,6 @@
     return ST_CONTINUE;
 }
 
-static int
-autoload_i(key, name, tbl)
-    ID key;
-    const char *name;
-    st_table *tbl;
-{
-    if (!st_lookup(tbl, key, 0)) {
-	st_insert(tbl, key, key);
-    }
-    return ST_CONTINUE;
-}
-
 void*
 rb_mod_const_at(mod, data)
     VALUE mod;
@@ -1225,9 +1295,6 @@
     }
     if ((VALUE)mod == rb_cObject) {
 	st_foreach(rb_class_tbl, sv_i, tbl);
-	if (autoload_tbl) {
-	    st_foreach(autoload_tbl, autoload_i, tbl);
-	}
     }
     return tbl;
 }
@@ -1291,15 +1358,6 @@
 }
 
 int
-rb_autoload_defined(id)
-    ID id;
-{
-    if (autoload_tbl && st_lookup(autoload_tbl, id, 0))
-	return Qtrue;
-    return Qfalse;
-}
-
-int
 rb_const_defined(klass, id)
     VALUE klass;
     ID id;
@@ -1317,7 +1375,7 @@
     }
     if (st_lookup(rb_class_tbl, id, 0))
 	return Qtrue;
-    return rb_autoload_defined(id);
+    return Qfalse;
 }
 
 static void
@@ -1336,9 +1394,13 @@
 	RCLASS(klass)->iv_tbl = st_init_numtable();
     }
     else if (isconst) {
-	if (st_lookup(RCLASS(klass)->iv_tbl, id, 0) ||
-	    (klass == rb_cObject && st_lookup(rb_class_tbl, id, 0))) {
+	VALUE value;
+	
+	if (st_lookup(RCLASS(klass)->iv_tbl, id, &value)) {
+	    if (IS_AUTOLOAD_TARGET(value)) autoload_delete(klass, id);
 	    rb_warn("already initialized %s %s", dest, rb_id2name(id));
+	} else if (klass == rb_cObject && st_lookup(rb_class_tbl, id, 0)) {
+	    rb_warn("already initialized %s %s", dest, rb_id2name(id));
 	}
     }
 
@@ -1372,16 +1434,6 @@
     /* pre-defined class */
     if (st_lookup(rb_class_tbl, id, 0)) {
 	st_delete(rb_class_tbl, id, 0);
-	st_insert(RCLASS(rb_cObject)->iv_tbl, id, val);
-	return;
-    }
-
-    /* autoload */
-    if (autoload_tbl && st_lookup(autoload_tbl, id, 0)) {
-	char *modname;
-
-	st_delete(autoload_tbl, &id, &modname);
-	free(modname);
 	st_insert(RCLASS(rb_cObject)->iv_tbl, id, val);
 	return;
     }

In This Thread

Prev Next