summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorSteve Hay <steve.m.hay@googlemail.com>2012-09-11 08:32:41 +0100
committerSteve Hay <steve.m.hay@googlemail.com>2012-09-11 08:32:41 +0100
commit00a0ae2877906b27fbce91f4f1393386dc1b821e (patch)
treed7ec6da86d9385f51aa48b4d7ad7e634572786a3 /win32
parente2cd629f7b7fdfe72919c58094aab5dd5d7b2b78 (diff)
downloadperl-00a0ae2877906b27fbce91f4f1393386dc1b821e.tar.gz
ANSIfy output from invalid parameter handler, and write it to stderr
The function, file and expression are very unlikely to contain anything requiring UTF-16 output, and the output is less likely to interfere with anything when written to stderr rather than stdout. Note that the function doesn't currently do anything without hacking the makefiles because we don't currently build with _DEBUG and the debug CRT. I haven't changed that yet (other than locally) because there is actually some output from it which causes a couple of tests to fail.
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 9e11231398..4f292b2a4d 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -136,6 +136,7 @@ static void remove_dead_process(long child);
static int terminate_process(DWORD pid, HANDLE process_handle, int sig);
static int my_kill(int pid, int sig);
static void out_of_memory(void);
+static char* wstr_to_str(const wchar_t* wstr);
static long filetime_to_clock(PFILETIME ft);
static BOOL filetime_from_time(PFILETIME ft, time_t t);
static char* create_command_line(char *cname, STRLEN clen,
@@ -171,9 +172,18 @@ my_invalid_parameter_handler(const wchar_t* expression,
uintptr_t pReserved)
{
# ifdef _DEBUG
- wprintf(L"Invalid parameter detected in function %s."
- L" File: %s Line: %d\n", function, file, line);
- wprintf(L"Expression: %s\n", expression);
+ char* ansi_expression;
+ char* ansi_function;
+ char* ansi_file;
+ ansi_expression = wstr_to_str(expression);
+ ansi_function = wstr_to_str(function);
+ ansi_file = wstr_to_str(file);
+ fprintf(stderr, "Invalid parameter detected in function %s. "
+ "File: %s, line: %d\n", ansi_function, ansi_file, line);
+ fprintf(stderr, "Expression: %s\n", ansi_expression);
+ free(ansi_expression);
+ free(ansi_function);
+ free(ansi_file);
# endif
}
#endif
@@ -1651,6 +1661,24 @@ out_of_memory(void)
exit(1);
}
+/* Converts a wide character (UTF-16) string to the Windows ANSI code page,
+ * potentially using the system's default replacement character for any
+ * unrepresentable characters. The caller must free() the returned string. */
+static char*
+wstr_to_str(const wchar_t* wstr)
+{
+ BOOL used_default = FALSE;
+ size_t wlen = wcslen(wstr) + 1;
+ int len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstr, wlen,
+ NULL, 0, NULL, NULL);
+ char* str = malloc(len);
+ if (!str)
+ out_of_memory();
+ WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstr, wlen,
+ str, len, NULL, &used_default);
+ return str;
+}
+
/* The win32_ansipath() function takes a Unicode filename and converts it
* into the current Windows codepage. If some characters cannot be mapped,
* then it will convert the short name instead.