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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-30 01:59:21 +00:00
Родитель 8d2ce0fb1f
Коммит 637d668bca
4 изменённых файлов: 39 добавлений и 7 удалений

Просмотреть файл

@ -1,4 +1,8 @@
Sun Jun 30 10:59:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sun Jun 30 10:59:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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.

4
io.c
Просмотреть файл

@ -5547,8 +5547,8 @@ rb_pipe(int *pipes)
#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)

Просмотреть файл

@ -1276,7 +1276,7 @@ proc_exec_sh(const char *str, VALUE envp_str)
}
#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_data_type = {
{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)
#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, struct rb_execarg *eargp)
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, struct rb_execarg *eargp)
}
#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)

Просмотреть файл

@ -16,6 +16,9 @@ class TestProcess < Test::Unit::TestCase
end
def windows?
self.class.windows?
end
def self.windows?
return /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
end
@ -1608,6 +1611,28 @@ EOS
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