Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b8b5ae7

Browse files
committed
Generate Windows debug messages with Unicode strings
Switch to the wide character debugging API to allow debug messages to contain Unicode characters.
1 parent 9227689 commit b8b5ae7

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

libfoundation/src/foundation-debug.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,25 @@ void __MCAssert(const char *p_file, uint32_t p_line, const char *p_message)
3636
_CrtDbgReport(_CRT_ASSERT, p_file, p_line, NULL, "%s", p_message);
3737
}
3838

39+
static void MCLogV(const char *p_file,
40+
uint32_t p_line,
41+
const char *p_format,
42+
va_list p_format_args)
43+
{
44+
MCAutoStringRef t_message, t_string;
45+
MCAutoStringRefAsWString t_wstring;
46+
/* UNCHECKED */ MCStringFormatV(&t_message, p_format, p_format_args);
47+
/* UNCHECKED */ MCStringFormat(&t_string, "[%u] %@\n",
48+
GetCurrentProcessId(), *t_message);
49+
/* UNCHECKED */ t_wstring.Lock(*t_string);
50+
_CrtDbgReportW(_CRT_WARN, p_file, p_line, NULL, *t_wstring);
51+
}
52+
3953
void __MCLog(const char *p_file, uint32_t p_line, const char *p_format, ...)
4054
{
41-
MCAutoStringRef t_string;
42-
43-
va_list t_args;
4455
va_start(t_args, p_format);
45-
MCStringFormatV(&t_string, p_format, t_args);
56+
MCLogV(p_file, p_line, p_format, t_args);
4657
va_end(t_args);
47-
48-
char *t_cstring;
49-
if (MCStringConvertToCString(*t_string, t_cstring))
50-
{
51-
_CrtDbgReport(_CRT_WARN, p_file, p_line, NULL, "[%u] %s\n", GetCurrentProcessId(), t_cstring);
52-
MCMemoryDeallocate(t_cstring);
53-
}
5458
}
5559

5660
void __MCLogWithTrace(const char *p_file, uint32_t p_line, const char *p_format, ...)
@@ -77,20 +81,10 @@ void __MCLogWithTrace(const char *p_file, uint32_t p_line, const char *p_format,
7781
s_sym_setoptions(SYMOPT_LOAD_LINES);
7882
}
7983
}
80-
81-
MCAutoStringRef t_string;
82-
83-
va_list t_args;
84-
va_start(t_args, p_format);
85-
MCStringFormatV(&t_string, p_format, t_args);
86-
va_end(t_args);
87-
88-
char *t_cstring;
89-
if (MCStringConvertToCString(*t_string, t_cstring))
90-
{
91-
_CrtDbgReport(_CRT_WARN, p_file, p_line, NULL, "[%u] %s\n", GetCurrentProcessId(), t_cstring);
92-
MCMemoryDeallocate(t_cstring);
93-
}
84+
85+
va_start(t_args, p_format);
86+
MCLogV(p_file, p_line, p_format, t_args);
87+
va_end(t_args);
9488

9589
if (s_sym_from_addr != nil)
9690
{

0 commit comments

Comments
 (0)