process.c: default process encoding

* process.c (EXPORT_STR, EXPORT_DUP): convert to default process
  encoding if defined.
* process.c (check_exec_env_i): convert environment variables too.
* process.c (rb_exec_fillarg): convert program path and arguments too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-30 01:57:18 +00:00
Родитель 3e9c0bfaeb
Коммит 69bbcbe4c1
2 изменённых файлов: 38 добавлений и 5 удалений

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

@ -1,3 +1,12 @@
Sun Jun 30 10:57:13 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (EXPORT_STR, EXPORT_DUP): convert to default process
encoding if defined.
* process.c (check_exec_env_i): convert environment variables too.
* process.c (rb_exec_fillarg): convert program path and arguments too.
Sun Jun 30 01:57:08 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.

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

@ -1354,6 +1354,21 @@ static const rb_data_type_t exec_arg_data_type = {
{mark_exec_arg, free_exec_arg, memsize_exec_arg},
};
#ifdef DEFAULT_PROCESS_ENCODING
# define EXPORT_STR(str) rb_str_export_to_enc((str), DEFAULT_PROCESS_ENCODING)
# define EXPORT_DUP(str) export_dup(str)
static VALUE
export_dup(VALUE str)
{
VALUE newstr = EXPORT_STR(str);
if (newstr == str) newstr = rb_str_dup(str);
return newstr;
}
#else
# define EXPORT_STR(str) (str)
# define EXPORT_DUP(str) rb_str_dup(str)
#endif
#if !defined(HAVE_FORK) && defined(HAVE_SPAWNV)
# define USE_SPAWNV 1
#else
@ -1560,7 +1575,7 @@ check_exec_redirect(VALUE key, VALUE val, struct rb_execarg *eargp)
flags = rb_to_int(flags);
perm = rb_ary_entry(val, 2);
perm = NIL_P(perm) ? INT2FIX(0644) : rb_to_int(perm);
param = hide_obj(rb_ary_new3(3, hide_obj(rb_str_dup(path)),
param = hide_obj(rb_ary_new3(3, hide_obj(EXPORT_DUP(path)),
flags, perm));
eargp->fd_open = check_exec_redirect1(eargp->fd_open, key, param);
}
@ -1576,7 +1591,7 @@ check_exec_redirect(VALUE key, VALUE val, struct rb_execarg *eargp)
else
flags = INT2NUM(O_RDONLY);
perm = INT2FIX(0644);
param = hide_obj(rb_ary_new3(3, hide_obj(rb_str_dup(path)),
param = hide_obj(rb_ary_new3(3, hide_obj(EXPORT_DUP(path)),
flags, perm));
eargp->fd_open = check_exec_redirect1(eargp->fd_open, key, param);
break;
@ -1682,7 +1697,7 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
}
FilePathValue(val);
eargp->chdir_given = 1;
eargp->chdir_dir = hide_obj(rb_str_dup(val));
eargp->chdir_dir = hide_obj(EXPORT_DUP(val));
}
else if (id == rb_intern("umask")) {
mode_t cmask = NUM2MODET(val);
@ -1912,6 +1927,9 @@ check_exec_env_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
if (!NIL_P(val))
StringValueCStr(val);
key = EXPORT_STR(key);
if (!NIL_P(val)) val = EXPORT_STR(val);
rb_ary_push(env, hide_obj(rb_assoc_new(key, val)));
return ST_CONTINUE;
@ -2023,6 +2041,7 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
eargp->env_modification = env;
}
prog = EXPORT_STR(prog);
eargp->use_shell = argc == 0;
if (eargp->use_shell)
eargp->invoke.sh.shell_script = prog;
@ -2155,8 +2174,13 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
argv_buf = rb_str_buf_new(0);
hide_obj(argv_buf);
for (i = 0; i < argc; i++) {
rb_str_buf_cat2(argv_buf, StringValueCStr(argv[i]));
rb_str_buf_cat(argv_buf, "", 1); /* append '\0' */
VALUE arg = argv[i];
const char *s = StringValueCStr(arg);
arg = EXPORT_STR(arg);
#ifdef DEFAULT_PROCESS_ENCODING
s = RSTRING_PTR(arg);
#endif
rb_str_buf_cat(argv_buf, s, RSTRING_LEN(arg) + 1); /* include '\0' */
}
eargp->invoke.cmd.argv_buf = argv_buf;
}