[前][次][番号順一覧][スレッド一覧]

ruby-changes:22761

From: naruse <ko1@a...>
Date: Sat, 25 Feb 2012 17:10:35 +0900 (JST)
Subject: [ruby-changes:22761] naruse:r34810 (ruby_1_9_3): merge revision(s) 34795:

naruse	2012-02-25 17:10:23 +0900 (Sat, 25 Feb 2012)

  New Revision: 34810

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34810

  Log:
    merge revision(s) 34795:
    
    * dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path.
      [Bug #6072]

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/dir.c
    branches/ruby_1_9_3/io.c
    branches/ruby_1_9_3/test/ruby/test_dir_m17n.rb
    branches/ruby_1_9_3/test/ruby/test_io_m17n.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 34809)
+++ ruby_1_9_3/ChangeLog	(revision 34810)
@@ -1,3 +1,8 @@
+Sat Feb 25 17:09:53 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path.
+	  [Bug #6072]
+
 Sat Feb 25 16:39:13 2012  NARUSE, Yui  <naruse@r...>
 
 	* complex.c (nucomp_marshal_load): raise error on invalid data.
Index: ruby_1_9_3/io.c
===================================================================
--- ruby_1_9_3/io.c	(revision 34809)
+++ ruby_1_9_3/io.c	(revision 34810)
@@ -1618,31 +1618,29 @@
 rb_io_inspect(VALUE obj)
 {
     rb_io_t *fptr;
-    const char *cname;
-    char fd_desc[4+sizeof(int)*3];
-    const char *path;
-    const char *st = "";
+    VALUE result;
+    static const char closed[] = " (closed)";
 
     fptr = RFILE(rb_io_taint_check(obj))->fptr;
     if (!fptr) return rb_any_to_s(obj);
-    cname = rb_obj_classname(obj);
+    result = rb_str_new_cstr("#<");
+    rb_str_append(result, rb_class_name(CLASS_OF(obj)));
+    rb_str_cat2(result, ":");
     if (NIL_P(fptr->pathv)) {
         if (fptr->fd < 0) {
-            path = "";
-            st = "(closed)";
+	    rb_str_cat(result, closed+1, strlen(closed)-1);
         }
         else {
-            snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
-            path = fd_desc;
+	    rb_str_catf(result, "fd %d", fptr->fd);
         }
     }
     else {
-        path = RSTRING_PTR(fptr->pathv);
+	rb_str_append(result, fptr->pathv);
         if (fptr->fd < 0) {
-            st = " (closed)";
+	    rb_str_cat(result, closed, strlen(closed));
         }
     }
-    return rb_sprintf("#<%s:%s%s>", cname, path, st);
+    return rb_str_cat2(result, ">");
 }
 
 /*
Index: ruby_1_9_3/dir.c
===================================================================
--- ruby_1_9_3/dir.c	(revision 34809)
+++ ruby_1_9_3/dir.c	(revision 34810)
@@ -486,8 +486,12 @@
 
     TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dirp);
     if (!NIL_P(dirp->path)) {
-	const char *c = rb_obj_classname(dir);
-	return rb_sprintf("#<%s:%s>", c, RSTRING_PTR(dirp->path));
+	VALUE str = rb_str_new_cstr("#<");
+	rb_str_append(str, rb_class_name(CLASS_OF(dir)));
+	rb_str_cat2(str, ":");
+	rb_str_append(str, dirp->path);
+	rb_str_cat2(str, ">");
+	return str;
     }
     return rb_funcall(dir, rb_intern("to_s"), 0, 0);
 }
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 34809)
+++ ruby_1_9_3/version.h	(revision 34810)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 144
+#define RUBY_PATCHLEVEL 145
 
 #define RUBY_RELEASE_DATE "2012-02-25"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/ruby/test_io_m17n.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_io_m17n.rb	(revision 34809)
+++ ruby_1_9_3/test/ruby/test_io_m17n.rb	(revision 34810)
@@ -2325,4 +2325,15 @@
       end
     }
   end if /mswin|mingw/ =~ RUBY_PLATFORM
+
+  def test_inspect_nonascii
+    bug6072 = '[ruby-dev:45280]'
+    paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
+    encs = with_tmpdir {
+      paths.map {|path|
+        open(path, "wb") {|f| f.inspect.encoding}
+      }
+    }
+    assert_equal(paths.map(&:encoding), encs, bug6072)
+  end
 end
Index: ruby_1_9_3/test/ruby/test_dir_m17n.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_dir_m17n.rb	(revision 34809)
+++ ruby_1_9_3/test/ruby/test_dir_m17n.rb	(revision 34810)
@@ -213,5 +213,16 @@
       EOS
     }
   end
+
+  def test_inspect_nonascii
+    bug6072 = '[ruby-dev:45280]'
+    paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
+    encs = with_tmpdir {
+      paths.map {|path|
+        Dir.mkdir(path)
+        Dir.open(path) {|d| d.inspect.encoding}
+      }
+    }
+    assert_equal(paths.map(&:encoding), encs, bug6072)
+  end
 end
-

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]