ruby-changes:35224
From: nobu <ko1@a...>
Date: Thu, 28 Aug 2014 15:18:37 +0900 (JST)
Subject: [ruby-changes:35224] nobu:r47306 (trunk): io.c: preserve encodings
nobu 2014-08-28 15:18:30 +0900 (Thu, 28 Aug 2014) New Revision: 47306 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47306 Log: io.c: preserve encodings * io.c (argf_next_argv): preserve encodings in warning messages. Modified files: trunk/io.c trunk/test/ruby/test_argf.rb Index: io.c =================================================================== --- io.c (revision 47305) +++ io.c (revision 47306) @@ -7878,7 +7878,7 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7878 if (ARGF.next_p == 1) { retry: if (RARRAY_LEN(ARGF.argv) > 0) { - ARGF.filename = rb_ary_shift(ARGF.argv); + ARGF.filename = rb_str_encode_ospath(rb_ary_shift(ARGF.argv)); fn = StringValueCStr(ARGF.filename); if (strlen(fn) == 1 && fn[0] == '-') { ARGF.current_file = rb_stdin; @@ -7904,21 +7904,22 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7904 } fstat(fr, &st); if (*ARGF.inplace) { - str = rb_str_new2(fn); + str = rb_str_dup(ARGF.filename); rb_str_cat2(str, ARGF.inplace); + /* TODO: encoding of ARGF.inplace */ #ifdef NO_SAFE_RENAME (void)close(fr); (void)unlink(RSTRING_PTR(str)); if (rename(fn, RSTRING_PTR(str)) < 0) { - rb_warn("Can't rename %s to %s: %s, skipping file", - fn, RSTRING_PTR(str), strerror(errno)); + rb_warn("Can't rename %"PRIsVALUE" to %"PRIsVALUE": %s, skipping file", + ARGF.filename, str, strerror(errno)); goto retry; } fr = rb_sysopen(str, O_RDONLY, 0); #else if (rename(fn, RSTRING_PTR(str)) < 0) { - rb_warn("Can't rename %s to %s: %s, skipping file", - fn, RSTRING_PTR(str), strerror(errno)); + rb_warn("Can't rename %"PRIsVALUE" to %"PRIsVALUE": %s, skipping file", + ARGF.filename, str, strerror(errno)); close(fr); goto retry; } @@ -7929,8 +7930,8 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7930 rb_fatal("Can't do inplace edit without backup"); #else if (unlink(fn) < 0) { - rb_warn("Can't remove %s: %s, skipping file", - fn, strerror(errno)); + rb_warn("Can't remove %"PRIsVALUE": %s, skipping file", + ARGF.filename, strerror(errno)); close(fr); goto retry; } @@ -7953,8 +7954,8 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L7954 #endif if (err && getuid() == 0 && st2.st_uid == 0) { const char *wkfn = RSTRING_PTR(ARGF.filename); - rb_warn("Can't set owner/group of %s to same as %s: %s, skipping file", - wkfn, fn, strerror(errno)); + rb_warn("Can't set owner/group of %"PRIsVALUE" to same as %"PRIsVALUE": %s, skipping file", + ARGF.filename, str, strerror(errno)); (void)close(fr); (void)close(fw); (void)unlink(wkfn); Index: test/ruby/test_argf.rb =================================================================== --- test/ruby/test_argf.rb (revision 47305) +++ test/ruby/test_argf.rb (revision 47306) @@ -212,6 +212,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L212 assert_equal([], r) assert_equal("foo\nbar\nbaz\n", File.read(t.path)) end + + base = "argf-\u{30c6 30b9 30c8}" + name = "#{@tmpdir}/#{base}" + File.write(name, "foo") + argf = ARGF.class.new(name) + argf.inplace_mode = '/\\:' + assert_warning(/#{base}/) {argf.gets} end def test_inplace_no_backup -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/