summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-30 12:00:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-30 12:00:56 +0000
commit0e15934d7fe0244573526f5ff3c6232bb3de2662 (patch)
tree73277a458e007127c05bad2ae7dfcfbf85458b2f /variable.c
parente652ecfac71f0daf752e529dca6a9a0a444e26b3 (diff)
variable.c: fix r36574
* variable.c (find_class_path): no retry when preferred is given. * variable.c (classname): if classid is set try it to find full qualified class path, and then try arbitrary class path. try tmp_classpath at last even if enclosing namespace is anonymous. fix r36574. [ruby-core:42865][Bug #6078] * variable.c (rb_set_class_path_string, rb_set_class_path): set tmp_classpath instead of classpath if the name is not permanent. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/variable.c b/variable.c
index 21798d42c8..b3da1ecf4c 100644
--- a/variable.c
+++ b/variable.c
@@ -115,7 +115,6 @@ find_class_path(VALUE klass, ID preferred)
{
struct fc_result arg;
- find:
arg.preferred = preferred;
arg.name = 0;
arg.path = 0;
@@ -137,10 +136,6 @@ find_class_path(VALUE klass, ID preferred)
st_delete(RCLASS_IV_TBL(klass), &tmp, 0);
return arg.path;
}
- if (preferred) {
- preferred = 0;
- goto find;
- }
return Qnil;
}
@@ -153,12 +148,17 @@ classname(VALUE klass)
if (!klass) klass = rb_cObject;
if (RCLASS_IV_TBL(klass)) {
if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classpath, &n)) {
- if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classid, &n)) {
- return find_class_path(klass, (ID)0);
+ if (st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classid, &n)) {
+ path = find_class_path(klass, SYM2ID(n));
+ }
+ if (NIL_P(path)) {
+ path = find_class_path(klass, (ID)0);
}
- path = find_class_path(klass, SYM2ID(n));
if (NIL_P(path)) {
- path = rb_str_dup(rb_id2str(SYM2ID((VALUE)n)));
+ if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)tmp_classpath, &n)) {
+ return Qnil;
+ }
+ path = rb_str_dup((VALUE)n);
OBJ_FREEZE(path);
return path;
}
@@ -240,6 +240,7 @@ void
rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
{
VALUE str;
+ ID pathid = classpath;
if (under == rb_cObject) {
str = rb_str_new_frozen(name);
@@ -250,28 +251,29 @@ rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
rb_str_cat2(str, "::");
rb_str_append(str, name);
OBJ_FREEZE(str);
- if (!permanent) return;
+ if (!permanent) pathid = tmp_classpath;
}
- rb_ivar_set(klass, classpath, str);
+ rb_ivar_set(klass, pathid, str);
}
void
rb_set_class_path(VALUE klass, VALUE under, const char *name)
{
VALUE str;
- int permanent = 1;
+ ID pathid = classpath;
if (under == rb_cObject) {
str = rb_str_new2(name);
}
else {
+ int permanent;
str = rb_str_dup(rb_tmp_class_path(under, &permanent));
rb_str_cat2(str, "::");
rb_str_cat2(str, name);
+ if (!permanent) pathid = tmp_classpath;
}
OBJ_FREEZE(str);
- if (!permanent) return;
- rb_ivar_set(klass, classpath, str);
+ rb_ivar_set(klass, pathid, str);
}
VALUE