summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-10 08:37:12 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-04-10 08:37:12 +0000
commite74149056bae388e35d4a4cab8cfa38114eb16b1 (patch)
tree2c2f889b16d8583f32bddc6311e596b369fa3346 /variable.c
parentdc08e8a60f3ea931598f7d240c76ad3f09ae3cef (diff)
* variable.c (rb_mod_name): always return empty string for
anonymous class/module. (ruby-bugs-ja PR#424) * config.sub: stop forcing addition of -gnu to -linux. * variable.c (classname): refactoring. * variable.c (rb_class_path): __tmp__classpath__ handling moved from classname(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/variable.c b/variable.c
index 2f35d53116..05d2056b82 100644
--- a/variable.c
+++ b/variable.c
@@ -145,34 +145,23 @@ classname(klass)
klass = rb_class_real(klass);
if (!klass) klass = rb_cObject;
- if (ROBJECT(klass)->iv_tbl &&
- !st_lookup(ROBJECT(klass)->iv_tbl, classpath, &path)) {
- ID classid = rb_intern("__classid__");
+ if (ROBJECT(klass)->iv_tbl) {
+ if (!st_lookup(ROBJECT(klass)->iv_tbl, classpath, &path)) {
+ ID classid = rb_intern("__classid__");
- if (st_lookup(ROBJECT(klass)->iv_tbl, classid, &path)) {
+ if (!st_lookup(ROBJECT(klass)->iv_tbl, classid, &path)) {
+ return Qnil;
+ }
path = rb_str_new2(rb_id2name(SYM2ID(path)));
st_insert(ROBJECT(klass)->iv_tbl, classpath, path);
st_delete(RCLASS(klass)->iv_tbl, &classid, 0);
}
- }
- if (NIL_P(path)) {
- ID tmppath = rb_intern("__tmp_classpath__");
-
- path = find_class_path(klass);
- if (NIL_P(path)) {
- if (!RCLASS(klass)->iv_tbl ||
- !st_lookup(RCLASS(klass)->iv_tbl, tmppath, &path)) {
- return 0;
- }
- }
- else if (RCLASS(klass)->iv_tbl) {
- st_delete(RCLASS(klass)->iv_tbl, &tmppath, 0);
+ if (TYPE(path) != T_STRING) {
+ rb_bug("class path is not set properly");
}
return path;
}
- if (TYPE(path) != T_STRING)
- rb_bug("class path is not set properly");
- return path;
+ return Qnil;
}
VALUE
@@ -181,8 +170,8 @@ rb_mod_name(mod)
{
VALUE path = classname(mod);
- if (path) return rb_str_dup(path);
- return rb_str_dup(rb_class_path(mod));
+ if (!NIL_P(path)) return rb_str_dup(path);
+ return rb_str_new(0,0);
}
VALUE
@@ -191,11 +180,20 @@ rb_class_path(klass)
{
VALUE path = classname(klass);
- if (path) return path;
+ if (!NIL_P(path)) return path;
else {
- VALUE str;
+ ID tmppath = rb_intern("__tmp_classpath__");
char *s = "Class";
+ path = find_class_path(klass);
+ if (!NIL_P(path)) {
+ st_delete(RCLASS(klass)->iv_tbl, &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";
@@ -204,12 +202,12 @@ rb_class_path(klass)
s = rb_class2name(RBASIC(klass)->klass);
}
}
- str = rb_str_new(0, 2 + strlen(s) + 3 + 2 * SIZEOF_LONG + 1);
- sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", s, klass);
- RSTRING(str)->len = strlen(RSTRING(str)->ptr);
- rb_iv_set(klass, "__tmp_classpath__", str);
+ 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);
- return str;
+ return path;
}
}