1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

RUBY_DEBUG codepage option [ci skip]

* debug.c (set_debug_option): add "codepage" option to force
  locale charmap on Windows.

* localeinit.c (locale_charmap): use the codepage by debug env if
  given.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-03-31 00:35:02 +00:00
parent 4c70f04786
commit 5c9cd965be
2 changed files with 34 additions and 6 deletions

27
debug.c
View file

@ -106,12 +106,16 @@ ruby_debug_breakpoint(void)
/* */
}
#if defined _WIN32
# if RUBY_MSVCRT_VERSION >= 80
extern int ruby_w32_rtc_error;
# endif
UINT ruby_w32_codepage;
#endif
static void
set_debug_option(const char *str, int len, void *arg)
{
#if defined _WIN32 && RUBY_MSVCRT_VERSION >= 80
extern int ruby_w32_rtc_error;
#endif
#define SET_WHEN(name, var, val) do { \
if (len == sizeof(name) - 1 && \
strncmp(str, (name), len) == 0) { \
@ -119,10 +123,25 @@ set_debug_option(const char *str, int len, void *arg)
return; \
} \
} while (0)
#define NAME_MATCH_VALUE(name) \
((size_t)len > sizeof(name) && \
strncmp(str, (name), sizeof(name)-1) == 0 && \
str[sizeof(name)-1] == '=' && \
(str += sizeof(name), len -= sizeof(name), 1))
SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr, Qtrue);
SET_WHEN("core", ruby_enable_coredump, 1);
#if defined _WIN32 && RUBY_MSVCRT_VERSION >= 80
#if defined _WIN32
# if RUBY_MSVCRT_VERSION >= 80
SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
# endif
if (NAME_MATCH_VALUE("codepage")) {
int ov;
size_t retlen;
ruby_w32_codepage =
ruby_scan_digits(str, len, 10, &retlen, &ov);
return;
}
#endif
fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
}

View file

@ -23,6 +23,12 @@
#define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
#endif
#if defined _WIN32 && defined RUBY_DEBUG_ENV
extern UINT ruby_w32_codepage;
#else
enum {ruby_w32_codepage = 0};
#endif
#ifndef NO_LOCALE_CHARMAP
# if defined _WIN32 || defined __CYGWIN__ || defined HAVE_LANGINFO_H
# define NO_LOCALE_CHARMAP 0
@ -43,7 +49,8 @@ locale_charmap(VALUE (*conv)(const char *))
codeset = nl_langinfo_codeset();
# endif
if (!codeset) {
UINT codepage = GetConsoleCP();
UINT codepage = ruby_w32_codepage;
if (!codepage) codepage = GetConsoleCP();
if (!codepage) codepage = GetACP();
CP_FORMAT(cp, codepage);
codeset = cp;
@ -119,7 +126,9 @@ Init_enc_set_filesystem_encoding(void)
idx = ENCINDEX_US_ASCII;
#elif defined _WIN32
char cp[SIZEOF_CP_NAME];
CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP());
const UINT codepage = ruby_w32_codepage ? ruby_w32_codepage :
AreFileApisANSI() ? GetACP() : GetOEMCP();
CP_FORMAT(cp, codepage);
idx = rb_enc_find_index(cp);
if (idx < 0) idx = ENCINDEX_ASCII;
#elif defined __CYGWIN__