Skip to content

Commit

Permalink
file.c: normalize Form C
Browse files Browse the repository at this point in the history
* file.c (rb_str_normalize_ospath): normalize to Normalization Form C
  using CFString.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Aug 9, 2013
1 parent f9cbf0e commit c04f402
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Fri Aug 9 12:06:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>

* file.c (rb_str_normalize_ospath): normalize to Normalization Form C
using CFString.

Fri Aug 9 10:53:57 2013 Kazuki Tsujimoto <kazuki@callcc.net>

* time.c (get_timeval, get_new_timeval): use rb_obj_class()
Expand Down
2 changes: 2 additions & 0 deletions configure.in
Expand Up @@ -3061,6 +3061,8 @@ AS_CASE("$enable_shared", [yes], [
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "' $(XLDFLAGS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).dylib'
LIBRUBY_ALIASES='lib$(RUBY_BASE_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
RUBY_APPEND_OPTION(XLDFLAGS, [-framework CoreFoundation])
RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework CoreFoundation])
],
[interix*], [
LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
Expand Down
28 changes: 22 additions & 6 deletions file.c
Expand Up @@ -19,6 +19,9 @@
#include <sys/cygwin.h>
#include <wchar.h>
#endif
#ifdef __APPLE__
#include <CoreFoundation/CFString.h>
#endif

#include "ruby/ruby.h"
#include "ruby/io.h"
Expand Down Expand Up @@ -244,12 +247,25 @@ rb_str_encode_ospath(VALUE path)
VALUE
rb_str_normalize_ospath(const char *ptr, long len)
{
rb_encoding *utf8mac = rb_enc_from_index(ENCINDEX_UTF8_MAC);
if (utf8mac) {
return rb_str_conv_enc(rb_tainted_str_new(ptr, len),
utf8mac, rb_utf8_encoding());
}
return Qnil;
VALUE str;
CFIndex buflen = 0;
CFRange all;
CFStringRef s = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
(const UInt8 *)ptr, len,
kCFStringEncodingUTF8, FALSE,
kCFAllocatorNull);
CFMutableStringRef m = CFStringCreateMutableCopy(kCFAllocatorDefault, len, s);

CFStringNormalize(m, kCFStringNormalizationFormC);
all = CFRangeMake(0, CFStringGetLength(m));
CFStringGetBytes(m, all, kCFStringEncodingUTF8, '?', FALSE, NULL, 0, &buflen);
str = rb_enc_str_new(0, buflen, rb_utf8_encoding());
CFStringGetBytes(m, all, kCFStringEncodingUTF8, '?', FALSE, (UInt8 *)RSTRING_PTR(str),
buflen, &buflen);
rb_str_set_len(str, buflen);
CFRelease(m);
CFRelease(s);
return str;
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_process.rb
Expand Up @@ -237,6 +237,8 @@ def test_execopts_rlimit
MANDATORY_ENVS << 'LD_PRELOAD'
when /mswin|mingw/
MANDATORY_ENVS.concat(%w[HOME USER TMPDIR])
when /darwin/
MANDATORY_ENVS.concat(ENV.keys.grep(/\A__CF_/))
end
if e = RbConfig::CONFIG['LIBPATHENV']
MANDATORY_ENVS << e
Expand Down

0 comments on commit c04f402

Please sign in to comment.