ruby-changes:29649
From: nobu <ko1@a...>
Date: Sun, 30 Jun 2013 10:57:38 +0900 (JST)
Subject: [ruby-changes:29649] nobu:r41701 (trunk): process.c: default process encoding
nobu 2013-06-30 10:57:18 +0900 (Sun, 30 Jun 2013) New Revision: 41701 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41701 Log: 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. Modified files: trunk/ChangeLog trunk/process.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41700) +++ ChangeLog (revision 41701) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jun 30 10:57:13 2013 Nobuyoshi Nakada <nobu@r...> + + * 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@f...> * bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang. Index: process.c =================================================================== --- process.c (revision 41700) +++ process.c (revision 41701) @@ -1354,6 +1354,21 @@ 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 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 https://github.com/ruby/ruby/blob/trunk/process.c#L1575 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 https://github.com/ruby/ruby/blob/trunk/process.c#L1591 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, VAL https://github.com/ruby/ruby/blob/trunk/process.c#L1697 } 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_da https://github.com/ruby/ruby/blob/trunk/process.c#L1927 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, VA https://github.com/ruby/ruby/blob/trunk/process.c#L2041 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, VA https://github.com/ruby/ruby/blob/trunk/process.c#L2174 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/