Skip to content

Commit

Permalink
fix calls to -[NSString fileSystemRepresentation] to catch potential …
Browse files Browse the repository at this point in the history
…exceptions

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5222 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Feb 9, 2011
1 parent d2cae1e commit 55b12f3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions objc.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -127,7 +139,7 @@
return Qnil;
}
}
return rb_str_new2([home_dir fileSystemRepresentation]);
return rb_str_new2(fileSystemPath(home_dir));
}

static bool
Expand Down Expand Up @@ -176,7 +188,7 @@
}
}

return rb_str_new2([res fileSystemRepresentation]);
return rb_str_new2(fileSystemPath(res));
}

VALUE
Expand Down Expand Up @@ -310,7 +322,7 @@
success:

if (cstr == NULL) {
cstr = [path fileSystemRepresentation];
cstr = fileSystemPath(path);
}

bundle = [NSBundle bundleWithPath:path];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55b12f3

Please sign in to comment.