diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 05:02:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 05:02:43 +0000 |
commit | d7bdf5df56f337d8ca1152598ff138703896c54b (patch) | |
tree | 92648c5e6ae75e6fa53cfde23962894408dcc633 | |
parent | 9b5701bc6ff9935c4bdc4961d2de8eb516f40f8c (diff) | |
download | ruby-d7bdf5df56f337d8ca1152598ff138703896c54b.tar.gz |
* variable.c (classname): find regular class name if not set.
[ruby-dev:20496]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | variable.c | 35 |
2 files changed, 20 insertions, 20 deletions
@@ -1,3 +1,8 @@ +Sat Aug 2 14:02:39 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * variable.c (classname): find regular class name if not set. + [ruby-dev:20496] + Sat Aug 2 03:30:25 2003 Yukihiro Matsumoto <matz@ruby-lang.org> * class.c (rb_obj_singleton_methods): should not go up to diff --git a/variable.c b/variable.c index fd7ff22294..d8e115a204 100644 --- a/variable.c +++ b/variable.c @@ -20,7 +20,7 @@ static st_table *rb_global_tbl; st_table *rb_class_tbl; -static ID autoload; +static ID autoload, classpath, tmp_classpath; void Init_var_tables() @@ -28,6 +28,8 @@ Init_var_tables() rb_global_tbl = st_init_numtable(); rb_class_tbl = st_init_numtable(); autoload = rb_intern("__autoload__"); + classpath = rb_intern("__classpath__"); + tmp_classpath = rb_intern("__tmp_classpath__"); } struct fc_result { @@ -49,7 +51,7 @@ fc_path(fc, name) while (fc) { if (fc->track == rb_cObject) break; if (ROBJECT(fc->track)->iv_tbl && - st_lookup(ROBJECT(fc->track)->iv_tbl, rb_intern("__classpath__"), &tmp)) { + st_lookup(ROBJECT(fc->track)->iv_tbl, classpath, &tmp)) { tmp = rb_str_dup(tmp); rb_str_cat2(tmp, "::"); rb_str_append(tmp, path); @@ -131,7 +133,8 @@ find_class_path(klass) if (!ROBJECT(klass)->iv_tbl) { ROBJECT(klass)->iv_tbl = st_init_numtable(); } - st_insert(ROBJECT(klass)->iv_tbl,rb_intern("__classpath__"),arg.path); + st_insert(ROBJECT(klass)->iv_tbl, classpath, arg.path); + st_delete(RCLASS(klass)->iv_tbl, &tmp_classpath, 0); return arg.path; } return Qnil; @@ -142,7 +145,6 @@ classname(klass) VALUE klass; { VALUE path = Qnil; - ID classpath = rb_intern("__classpath__"); klass = rb_class_real(klass); if (!klass) klass = rb_cObject; @@ -151,7 +153,7 @@ classname(klass) ID classid = rb_intern("__classid__"); if (!st_lookup(ROBJECT(klass)->iv_tbl, classid, &path)) { - return Qnil; + return find_class_path(klass); } path = rb_str_new2(rb_id2name(SYM2ID(path))); st_insert(ROBJECT(klass)->iv_tbl, classpath, path); @@ -162,7 +164,7 @@ classname(klass) } return path; } - return Qnil; + return find_class_path(klass); } VALUE @@ -182,19 +184,13 @@ rb_class_path(klass) VALUE path = classname(klass); if (!NIL_P(path)) return path; + if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, + tmp_classpath, &path)) { + return path; + } else { - ID tmppath = rb_intern("__tmp_classpath__"); char *s = "Class"; - path = find_class_path(klass); - if (!NIL_P(path)) { - st_delete(RCLASS(klass)->iv_tbl, (st_data_t*)&tmppath, 0); - return path; - } - if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, tmppath, &path)) { - return path; - } - if (TYPE(klass) == T_MODULE) { if (rb_obj_class(klass) == rb_cModule) { s = "Module"; @@ -206,7 +202,7 @@ rb_class_path(klass) path = rb_str_new(0, 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1); sprintf(RSTRING(path)->ptr, "#<%s:0x%lx>", s, klass); RSTRING(path)->len = strlen(RSTRING(path)->ptr); - rb_iv_set(klass, "__tmp_classpath__", path); + rb_ivar_set(klass, tmp_classpath, path); return path; } @@ -227,7 +223,7 @@ rb_set_class_path(klass, under, name) rb_str_cat2(str, "::"); rb_str_cat2(str, name); } - rb_iv_set(klass, "__classpath__", str); + rb_ivar_set(klass, classpath, str); } VALUE @@ -255,8 +251,7 @@ rb_path2class(path) } if (!rb_const_defined(c, id)) { undefined_class: - rb_raise(rb_eArgError, "undefined class/module %s", rb_id2name(id)); - rb_raise(rb_eArgError, "undefined class/module %s", path); + rb_raise(rb_eArgError, "undefined class/module %.*s", p-path, path); } c = rb_const_get_at(c, id); switch (TYPE(c)) { |