Revision: 3626 http://trac.macosforge.org/projects/ruby/changeset/3626 Author: lsansonetti@apple.com Date: 2010-02-25 16:29:31 -0800 (Thu, 25 Feb 2010) Log Message: ----------- make sure File.join and File.expand_path return RubyStrings (for now) Modified Paths: -------------- MacRuby/branches/icu/file.c MacRuby/branches/icu/objc.m Modified: MacRuby/branches/icu/file.c =================================================================== --- MacRuby/branches/icu/file.c 2010-02-25 23:58:38 UTC (rev 3625) +++ MacRuby/branches/icu/file.c 2010-02-26 00:29:31 UTC (rev 3626) @@ -2575,13 +2575,11 @@ static VALUE rb_file_join(VALUE ary, VALUE sep) { - CFMutableStringRef res = CFStringCreateMutable(NULL, 0); - CFStringRef sep_cf = (CFStringRef)sep; + VALUE res = rb_str_new(NULL, 0); const long count = RARRAY_LEN(ary); if (count > 0) { - long i; - for (i = 0; i < count; i++) { + for (long i = 0; i < count; i++) { VALUE tmp = RARRAY_AT(ary, i); switch (TYPE(tmp)) { case T_STRING: @@ -2595,9 +2593,9 @@ FilePathStringValue(tmp); } - CFStringRef tmp_cf = (CFStringRef)tmp; - - if (i > 0) { + if (i > 0 && !NIL_P(sep)) { +#if 0 +// TODO: we should probably mimic what 1.9 does here instead of this if (CFStringHasSuffix(res, sep_cf)) { if (CFStringHasPrefix(tmp_cf, sep_cf)) { // Remove trailing slash from res if tmp starts with a @@ -2609,14 +2607,15 @@ else if (!CFStringHasPrefix(tmp_cf, sep_cf)) { CFStringAppend(res, sep_cf); } +#endif + rb_str_concat(res, sep); } - CFStringAppend(res, tmp_cf); + rb_str_concat(res, tmp); } } - CFMakeCollectable(res); - return (VALUE)res; + return res; } /* Modified: MacRuby/branches/icu/objc.m =================================================================== --- MacRuby/branches/icu/objc.m 2010-02-25 23:58:38 UTC (rev 3625) +++ MacRuby/branches/icu/objc.m 2010-02-26 00:29:31 UTC (rev 3626) @@ -197,32 +197,35 @@ NSString *res = (NSString *)FilePathValue(fname); if ([res isAbsolutePath]) { - NSString *tmp = [res stringByResolvingSymlinksInPath]; - // Make sure we don't have an invalid user path. - if ([res hasPrefix:@"~"] && [tmp isEqualTo:res]) { - NSString *user = [[[res pathComponents] objectAtIndex:0] substringFromIndex:1]; - rb_raise(rb_eArgError, "user %s doesn't exist", [user UTF8String]); - } - res = tmp; + NSString *tmp = [res stringByResolvingSymlinksInPath]; + // Make sure we don't have an invalid user path. + if ([res hasPrefix:@"~"] && [tmp isEqualTo:res]) { + NSString *user = [[[res pathComponents] objectAtIndex:0] + substringFromIndex:1]; + rb_raise(rb_eArgError, "user %s doesn't exist", [user UTF8String]); + } + res = tmp; } else { - NSString *dir = dname != Qnil ? - (NSString *)FilePathValue(dname) : [[NSFileManager defaultManager] currentDirectoryPath]; + NSString *dir = dname != Qnil + ? (NSString *)FilePathValue(dname) + : [[NSFileManager defaultManager] currentDirectoryPath]; - if (![dir isAbsolutePath]) { - dir = (NSString *)rb_file_expand_path((VALUE)dir, Qnil); - } + if (![dir isAbsolutePath]) { + dir = (NSString *)rb_file_expand_path((VALUE)dir, Qnil); + } - // stringByStandardizingPath does not expand "/." to "/". - if ([res isEqualTo:@"."] && [dir isEqualTo:@"/"]) { - res = @"/"; - } - else { - res = [[dir stringByAppendingPathComponent:res] stringByStandardizingPath]; - } + // stringByStandardizingPath does not expand "/." to "/". + if ([res isEqualTo:@"."] && [dir isEqualTo:@"/"]) { + res = @"/"; + } + else { + res = [[dir stringByAppendingPathComponent:res] + stringByStandardizingPath]; + } } - return (VALUE)[res mutableCopy]; + return rb_str_new2([res fileSystemRepresentation]); } static VALUE
participants (1)
-
source_changes@macosforge.org