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

ruby-changes:29658

From: nobu <ko1@a...>
Date: Sun, 30 Jun 2013 10:59:54 +0900 (JST)
Subject: [ruby-changes:29658] nobu:r41709 (trunk): win32: UTF-8 spawn

nobu	2013-06-30 10:59:21 +0900 (Sun, 30 Jun 2013)

  New Revision: 41709

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

  Log:
    win32: UTF-8 spawn
    
    * io.c (spawnv, spawn): use UTF-8 spawn family.  [Bug #1771]
    * process.c (proc_exec_sh, proc_spawn_cmd, proc_spawn_sh): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/process.c
    trunk/test/ruby/test_process.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41708)
+++ ChangeLog	(revision 41709)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sun Jun 30 10:59:14 2013  Nobuyoshi Nakada  <nobu@r...>
+Sun Jun 30 10:59:18 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (spawnv, spawn): use UTF-8 spawn family.  [Bug #1771]
+
+	* process.c (proc_exec_sh, proc_spawn_cmd, proc_spawn_sh): ditto.
 
 	* win32/win32.c (translate_char, join_argv, has_redirection): make
 	  codepage aware.
Index: io.c
===================================================================
--- io.c	(revision 41708)
+++ io.c	(revision 41709)
@@ -5547,8 +5547,8 @@ rb_pipe(int *pipes) https://github.com/ruby/ruby/blob/trunk/io.c#L5547
 
 #ifdef _WIN32
 #define HAVE_SPAWNV 1
-#define spawnv(mode, cmd, args) rb_w32_aspawn((mode), (cmd), (args))
-#define spawn(mode, cmd) rb_w32_spawn((mode), (cmd), 0)
+#define spawnv(mode, cmd, args) rb_w32_uaspawn((mode), (cmd), (args))
+#define spawn(mode, cmd) rb_w32_uspawn((mode), (cmd), 0)
 #endif
 
 #if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
Index: process.c
===================================================================
--- process.c	(revision 41708)
+++ process.c	(revision 41709)
@@ -1276,7 +1276,7 @@ proc_exec_sh(const char *str, VALUE envp https://github.com/ruby/ruby/blob/trunk/process.c#L1276
     }
 
 #ifdef _WIN32
-    rb_w32_spawn(P_OVERLAY, (char *)str, 0);
+    rb_w32_uspawn(P_OVERLAY, (char *)str, 0);
     return -1;
 #else
 #if defined(__CYGWIN32__) || defined(__EMX__)
@@ -1354,6 +1354,9 @@ static const rb_data_type_t exec_arg_dat https://github.com/ruby/ruby/blob/trunk/process.c#L1354
     {mark_exec_arg, free_exec_arg, memsize_exec_arg},
 };
 
+#ifdef _WIN32
+# define DEFAULT_PROCESS_ENCODING rb_utf8_encoding()
+#endif
 #ifdef DEFAULT_PROCESS_ENCODING
 # define EXPORT_STR(str) rb_str_export_to_enc((str), DEFAULT_PROCESS_ENCODING)
 # define EXPORT_DUP(str) export_dup(str)
@@ -1380,7 +1383,7 @@ export_dup(VALUE str) https://github.com/ruby/ruby/blob/trunk/process.c#L1383
 
 #if USE_SPAWNV
 #if defined(_WIN32)
-#define proc_spawn_cmd_internal(argv, prog) rb_w32_aspawn(P_NOWAIT, (prog), (argv))
+#define proc_spawn_cmd_internal(argv, prog) rb_w32_uaspawn(P_NOWAIT, (prog), (argv))
 #else
 static rb_pid_t
 proc_spawn_cmd_internal(char **argv, char *prog)
@@ -1419,7 +1422,7 @@ proc_spawn_cmd(char **argv, VALUE prog, https://github.com/ruby/ruby/blob/trunk/process.c#L1422
 	if (eargp->new_pgroup_given && eargp->new_pgroup_flag) {
 	    flags = CREATE_NEW_PROCESS_GROUP;
 	}
-	pid = rb_w32_aspawn_flags(P_NOWAIT, prog ? RSTRING_PTR(prog) : 0, argv, flags);
+	pid = rb_w32_uaspawn_flags(P_NOWAIT, prog ? RSTRING_PTR(prog) : 0, argv, flags);
 #else
 	pid = proc_spawn_cmd_internal(argv, prog ? RSTRING_PTR(prog) : 0);
 #endif
@@ -1428,7 +1431,7 @@ proc_spawn_cmd(char **argv, VALUE prog, https://github.com/ruby/ruby/blob/trunk/process.c#L1431
 }
 
 #if defined(_WIN32)
-#define proc_spawn_sh(str) rb_w32_spawn(P_NOWAIT, (str), 0)
+#define proc_spawn_sh(str) rb_w32_uspawn(P_NOWAIT, (str), 0)
 #else
 static rb_pid_t
 proc_spawn_sh(char *str)
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 41708)
+++ test/ruby/test_process.rb	(revision 41709)
@@ -16,6 +16,9 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L16
   end
 
   def windows?
+    self.class.windows?
+  end
+  def self.windows?
     return /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
   end
 
@@ -1608,6 +1611,28 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1611
     end
   end
 
+  def test_spawn_nonascii
+    bug1771 = '[ruby-core:24309] [Bug #1771]'
 
+    with_tmpchdir do
+      [
+       "\u{7d05 7389}",
+       "zuf\u{00E4}llige_\u{017E}lu\u{0165}ou\u{010D}k\u{00FD}_\u{10D2 10D0 10DB 10D4 10DD 10E0 10D4 10D1}_\u{0440 0430 0437 043B 043E 0433 0430}_\u{548C 65B0 52A0 5761 4EE5 53CA 4E1C}",
+       # "c\u{1EE7}a", # work with a backslash, but not with a slash, for some reason.
+      ].each do |name|
+        msg = "#{bug1771} #{name}"
+        exename = "./#{name}.exe"
+        FileUtils.cp(ENV["COMSPEC"], exename)
+        assert_equal(true, system("#{exename} /c exit"), msg)
+        system("#{exename} /c exit 12")
+        assert_equal(12, $?.exitstatus, msg)
+        _, status = Process.wait2(Process.spawn("#{exename} /c exit 42"))
+        assert_equal(42, status.exitstatus, msg)
+        assert_equal("ok\n", `#{exename} /c echo ok`, msg)
+        assert_equal("ok\n", IO.popen("#{exename} /c echo ok", &:read), msg)
+        assert_equal("ok\n", IO.popen(%W"#{exename} /c echo ok", &:read), msg)
+      end
+    end
+  end if windows?
 
 end

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

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