[macruby-changes] [5222] MacRuby/trunk/objc.m

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 8 18:28:44 PST 2011


Revision: 5222
          http://trac.macosforge.org/projects/ruby/changeset/5222
Author:   lsansonetti at apple.com
Date:     2011-02-08 18:28:44 -0800 (Tue, 08 Feb 2011)
Log Message:
-----------
fix calls to -[NSString fileSystemRepresentation] to catch potential exceptions

Modified Paths:
--------------
    MacRuby/trunk/objc.m

Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m	2011-02-07 22:05:12 UTC (rev 5221)
+++ MacRuby/trunk/objc.m	2011-02-09 02:28:44 UTC (rev 5222)
@@ -107,6 +107,18 @@
     return false;
 }
 
+static const char *
+fileSystemPath(NSString *str)
+{
+    @try {
+	return [str fileSystemRepresentation];
+    }
+    @catch (id exc) {
+	// Sometimes, -fileSystemRepresentation can fail.
+    }
+    return [str UTF8String];
+}
+
 VALUE
 rb_home_dir(VALUE user_name)
 {
@@ -127,7 +139,7 @@
 	    return Qnil;
 	}
     }
-    return rb_str_new2([home_dir fileSystemRepresentation]);
+    return rb_str_new2(fileSystemPath(home_dir));
 }
 
 static bool
@@ -176,7 +188,7 @@
 	}
     }
 
-    return rb_str_new2([res fileSystemRepresentation]);
+    return rb_str_new2(fileSystemPath(res));
 }
 
 VALUE
@@ -310,7 +322,7 @@
 success:
 
     if (cstr == NULL) {
-	cstr = [path fileSystemRepresentation];
+	cstr = fileSystemPath(path);
     }
 
     bundle = [NSBundle bundleWithPath:path];
@@ -674,7 +686,7 @@
     for (NSBundle *b in [NSBundle allFrameworks]) {
 	if ([b isLoaded]) {
 	    NSString *path = [b bundlePath];
-	    rb_objc_search_and_load_bridge_support([path fileSystemRepresentation]);	
+	    rb_objc_search_and_load_bridge_support(fileSystemPath(path));
 	}
     }
 #endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110208/aa925cf7/attachment.html>


More information about the macruby-changes mailing list