ruby-changes:37584
From: naruse <ko1@a...>
Date: Fri, 20 Feb 2015 17:39:24 +0900 (JST)
Subject: [ruby-changes:37584] naruse:r49665 (ruby_2_2): merge revision(s) 49528:
naruse 2015-02-20 17:39:10 +0900 (Fri, 20 Feb 2015) New Revision: 49665 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49665 Log: merge revision(s) 49528: dir.c: preserve encoding * dir.c (sys_enc_warning_in): preserve encoding of path name in warning messages. Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/dir.c branches/ruby_2_2/test/ruby/test_dir_m17n.rb branches/ruby_2_2/version.h Index: ruby_2_2/dir.c =================================================================== --- ruby_2_2/dir.c (revision 49664) +++ ruby_2_2/dir.c (revision 49665) @@ -1081,16 +1081,45 @@ dir_s_rmdir(VALUE obj, VALUE dir) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1081 return INT2FIX(0); } +struct warning_args { +#ifdef RUBY_FUNCTION_NAME_STRING + const char *func; +#endif + const char *mesg; + rb_encoding *enc; +}; + +#ifndef RUBY_FUNCTION_NAME_STRING +#define sys_enc_warning_in(func, mesg, enc) sys_enc_warning(mesg, enc) +#endif + static VALUE sys_warning_1(VALUE mesg) { - rb_sys_warning("%s", (const char *)mesg); + const struct warning_args *arg = (struct warning_args *)mesg; +#ifdef RUBY_FUNCTION_NAME_STRING + rb_sys_enc_warning(arg->enc, "%s: %s", arg->func, arg->mesg); +#else + rb_sys_enc_warning(arg->enc, "%s", arg->mesg); +#endif return Qnil; } +static void +sys_enc_warning_in(const char *func, const char *mesg, rb_encoding *enc) +{ + struct warning_args arg; +#ifdef RUBY_FUNCTION_NAME_STRING + arg.func = func; +#endif + arg.mesg = mesg; + arg.enc = enc; + rb_protect(sys_warning_1, (VALUE)&arg, 0); +} + #define GLOB_VERBOSE (1U << (sizeof(int) * CHAR_BIT - 1)) -#define sys_warning(val) \ - (void)((flags & GLOB_VERBOSE) && rb_protect(sys_warning_1, (VALUE)(val), 0)) +#define sys_warning(val, enc) \ + ((flags & GLOB_VERBOSE) ? sys_enc_warning_in(RUBY_FUNCTION_NAME_STRING, (val), (enc)) :(void)0) #define GLOB_ALLOC(type) ((type *)malloc(sizeof(type))) #define GLOB_ALLOC_N(type, n) ((type *)malloc(sizeof(type) * (n))) @@ -1112,23 +1141,22 @@ sys_warning_1(VALUE mesg) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1141 /* System call with warning */ static int -do_stat(const char *path, struct stat *pst, int flags) - +do_stat(const char *path, struct stat *pst, int flags, rb_encoding *enc) { int ret = STAT(path, pst); if (ret < 0 && !to_be_ignored(errno)) - sys_warning(path); + sys_warning(path, enc); return ret; } #if defined HAVE_LSTAT || defined lstat static int -do_lstat(const char *path, struct stat *pst, int flags) +do_lstat(const char *path, struct stat *pst, int flags, rb_encoding *enc) { int ret = lstat(path, pst); if (ret < 0 && !to_be_ignored(errno)) - sys_warning(path); + sys_warning(path, enc); return ret; } @@ -1152,7 +1180,7 @@ do_opendir(const char *path, int flags, https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1180 #endif dirp = opendir(path); if (dirp == NULL && !to_be_ignored(errno)) - sys_warning(path); + sys_warning(path, enc); #ifdef _WIN32 if (tmp) rb_str_resize(tmp, 0); /* GC guard */ #endif @@ -1551,7 +1579,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1579 pathlen = strlen(path); if (*path) { if (match_all && exist == UNKNOWN) { - if (do_lstat(path, &st, flags) == 0) { + if (do_lstat(path, &st, flags, enc) == 0) { exist = YES; isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO; } @@ -1561,7 +1589,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1589 } } if (match_dir && isdir == UNKNOWN) { - if (do_stat(path, &st, flags) == 0) { + if (do_stat(path, &st, flags, enc) == 0) { exist = YES; isdir = S_ISDIR(st.st_mode) ? YES : NO; } @@ -1663,7 +1691,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/ruby_2_2/dir.c#L1691 if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) { /* RECURSIVE never match dot files unless FNM_DOTMATCH is set */ #ifndef _WIN32 - if (do_lstat(buf, &st, flags) == 0) + if (do_lstat(buf, &st, flags, enc) == 0) new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO; else new_isdir = NO; Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 49664) +++ ruby_2_2/version.h (revision 49665) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.0" #define RUBY_RELEASE_DATE "2015-02-20" -#define RUBY_PATCHLEVEL 66 +#define RUBY_PATCHLEVEL 67 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_2/test/ruby/test_dir_m17n.rb =================================================================== --- ruby_2_2/test/ruby/test_dir_m17n.rb (revision 49664) +++ ruby_2_2/test/ruby/test_dir_m17n.rb (revision 49665) @@ -303,6 +303,50 @@ class TestDir_M17N < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_dir_m17n.rb#L303 } end + def with_enc_path + with_tmpdir do |d| + names = %W"\u{391 392 393 394 395} \u{3042 3044 3046 3048 304a}" + names.each do |dir| + Dir.mkdir(dir) rescue next + begin + yield(dir) + ensure + File.chmod(0700, dir) + end + end + end + end + + def test_glob_warning_opendir + with_enc_path do |dir| + open("#{dir}/x", "w") {} + File.chmod(0300, dir) + assert_warning(/#{dir}/) do + Dir.glob("#{dir}/*") + end + end + end + + def test_glob_warning_match_all + with_enc_path do |dir| + open("#{dir}/x", "w") {} + File.chmod(0000, dir) + assert_warning(/#{dir}/) do + Dir.glob("#{dir}/x") + end + end + end + + def test_glob_warning_match_dir + with_enc_path do |dir| + Dir.mkdir("#{dir}/x") + File.chmod(0000, dir) + assert_warning(/#{dir}/) do + Dir.glob("#{dir}/x/") + end + end + end + def test_entries_compose bug7267 = '[ruby-core:48745] [Bug #7267]' Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49528 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/