From 33ea2646b98adb49ae2e1781753bf22d33729ac0 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 29 Nov 2014 07:53:17 +0000 Subject: win32.c: use UTF-8 for argv * ruby.c (ruby_set_argv): convert argv from UTF-8. * win32/win32.c (rb_w32_sysinit, cmdglob, w32_cmdvector): convert wide char command line to UTF-8 argv, and glob in UTF-8 so that metacharacters would match multibyte characters. [ruby-dev:48752] [Bug #10555] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index b2f485076d..f73be51297 100644 --- a/ruby.c +++ b/ruby.c @@ -311,6 +311,7 @@ ruby_incpush_expand(const char *path) ruby_push_include(path, expand_include_path); } +#undef UTF8_PATH #if defined _WIN32 || defined __CYGWIN__ static HMODULE libruby; @@ -327,6 +328,12 @@ rb_libruby_handle(void) { return libruby; } + +# define UTF8_PATH 1 +#endif + +#ifndef UTF8_PATH +# define UTF8_PATH 0 #endif void ruby_init_loadpath_safe(int safe_level); @@ -1794,6 +1801,19 @@ set_arg0(VALUE val, ID id) rb_progname = rb_str_new_frozen(proc_setproctitle(rb_mProcess, val)); } +static inline VALUE +external_str_new_cstr(const char *p) +{ +#if UTF8_PATH + VALUE str = rb_utf8_str_new_cstr(p); + return rb_str_conv_enc_opts(str, NULL, rb_default_external_encoding(), + ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE, + Qnil); +#else + return rb_external_str_new_cstr(p); +#endif +} + /*! Sets the current script name to this value. * * This is similar to $0 = name in Ruby level but also affects @@ -1910,7 +1930,7 @@ ruby_set_argv(int argc, char **argv) #endif rb_ary_clear(av); for (i = 0; i < argc; i++) { - VALUE arg = rb_external_str_new_cstr(argv[i]); + VALUE arg = external_str_new_cstr(argv[i]); OBJ_FREEZE(arg); rb_ary_push(av, arg); -- cgit v1.2.3