summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-29 07:53:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-29 07:53:17 +0000
commit33ea2646b98adb49ae2e1781753bf22d33729ac0 (patch)
tree5cdaf18f6980ec1fbe5f794bf01976395b07edb5 /ruby.c
parent544d28c300b5a8084693968cb88b75443def8ab2 (diff)
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
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/ruby.c b/ruby.c
index b2f4850..f73be51 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 <code>$0 = name</code> 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);