Merge branch 'fix/always-use-windows-unicode-apis' into 'master'

gwin32: Always use unicode APIs

See merge request GNOME/glib!1848
This commit is contained in:
Sebastian Dröge
2021-01-06 08:26:18 +00:00
8 changed files with 85 additions and 57 deletions

View File

@@ -66,6 +66,7 @@
#include "gtypes.h"
#include "gmain.h"
#include "gprintfint.h"
#include "gunicode.h"
#include "gutils.h"
#ifndef G_OS_WIN32
@@ -206,9 +207,20 @@ g_on_error_query (const gchar *prg_name)
/* MessageBox is allowed on UWP apps only when building against
* the debug CRT, which will set -D_DEBUG */
#if defined(_DEBUG) || !defined(G_WINAPI_ONLY_APP)
MessageBox (NULL, "g_on_error_query called, program terminating",
(prg_name && *prg_name) ? prg_name : NULL,
MB_OK|MB_ICONERROR);
{
WCHAR *caption = NULL;
if (prg_name && *prg_name)
{
caption = g_utf8_to_utf16 (prg_name, -1, NULL, NULL, NULL);
}
MessageBoxW (NULL, L"g_on_error_query called, program terminating",
caption,
MB_OK|MB_ICONERROR);
g_free (caption);
}
#else
printf ("g_on_error_query called, program '%s' terminating\n",
(prg_name && *prg_name) ? prg_name : "(null)");

View File

@@ -1395,10 +1395,14 @@ g_logv (const gchar *log_domain,
#if defined(G_OS_WIN32) && (defined(_DEBUG) || !defined(G_WINAPI_ONLY_APP))
if (win32_keep_fatal_message)
{
gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
WCHAR *wide_msg;
MessageBox (NULL, locale_msg, NULL,
MB_ICONERROR|MB_SETFOREGROUND);
wide_msg = g_utf8_to_utf16 (fatal_msg_buf, -1, NULL, NULL, NULL);
MessageBoxW (NULL, wide_msg, NULL,
MB_ICONERROR | MB_SETFOREGROUND);
g_free (wide_msg);
}
#endif
@@ -2789,12 +2793,13 @@ handled:
#if defined(G_OS_WIN32) && (defined(_DEBUG) || !defined(G_WINAPI_ONLY_APP))
if (!g_test_initialized ())
{
gchar *locale_msg = NULL;
WCHAR *wide_msg;
locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
MessageBox (NULL, locale_msg, NULL,
MB_ICONERROR | MB_SETFOREGROUND);
g_free (locale_msg);
wide_msg = g_utf8_to_utf16 (fatal_msg_buf, -1, NULL, NULL, NULL);
MessageBoxW (NULL, wide_msg, NULL, MB_ICONERROR | MB_SETFOREGROUND);
g_free (wide_msg);
}
#endif /* !G_OS_WIN32 */

View File

@@ -1964,7 +1964,7 @@ load_user_special_dirs (void)
wchar_t *wcp;
p_SHGetKnownFolderPath = (t_SHGetKnownFolderPath) GetProcAddress (GetModuleHandle ("shell32.dll"),
p_SHGetKnownFolderPath = (t_SHGetKnownFolderPath) GetProcAddress (GetModuleHandleW (L"shell32.dll"),
"SHGetKnownFolderPath");
g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = get_special_folder (CSIDL_DESKTOPDIRECTORY);
@@ -2295,26 +2295,14 @@ get_module_for_address (gconstpointer address)
{
/* Holds the g_utils_global lock */
static gboolean beenhere = FALSE;
typedef BOOL (WINAPI *t_GetModuleHandleExA) (DWORD, LPCTSTR, HMODULE *);
static t_GetModuleHandleExA p_GetModuleHandleExA = NULL;
HMODULE hmodule = NULL;
if (!address)
return NULL;
if (!beenhere)
{
p_GetModuleHandleExA =
(t_GetModuleHandleExA) GetProcAddress (GetModuleHandle ("kernel32.dll"),
"GetModuleHandleExA");
beenhere = TRUE;
}
if (p_GetModuleHandleExA == NULL ||
!(*p_GetModuleHandleExA) (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
address, &hmodule))
if (!GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
address, &hmodule))
{
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery (address, &mbi, sizeof (mbi));

View File

@@ -107,12 +107,15 @@ g_win32_ftruncate (gint fd,
gchar *
g_win32_getlocale (void)
{
gchar *result;
LCID lcid;
LANGID langid;
const gchar *ev;
gint primary, sub;
char iso639[10];
char iso3166[10];
WCHAR iso639[10];
gchar *iso639_utf8;
WCHAR iso3166[10];
gchar *iso3166_utf8;
const gchar *script = NULL;
/* Let the user override the system settings through environment
@@ -127,8 +130,8 @@ g_win32_getlocale (void)
lcid = GetThreadLocale ();
if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) ||
!GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166)))
if (!GetLocaleInfoW (lcid, LOCALE_SISO639LANGNAME, iso639, sizeof (iso639)) ||
!GetLocaleInfoW (lcid, LOCALE_SISO3166CTRYNAME, iso3166, sizeof (iso3166)))
return g_strdup ("C");
/* Strip off the sorting rules, keep only the language part. */
@@ -173,7 +176,16 @@ g_win32_getlocale (void)
}
break;
}
return g_strconcat (iso639, "_", iso3166, script, NULL);
iso639_utf8 = g_utf16_to_utf8 (iso639, -1, NULL, NULL, NULL);
iso3166_utf8 = g_utf16_to_utf8 (iso3166, -1, NULL, NULL, NULL);
result = g_strconcat (iso639_utf8, "_", iso3166_utf8, script, NULL);
g_free (iso3166_utf8);
g_free (iso639_utf8);
return result;
}
/**
@@ -1062,10 +1074,11 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
{
EXCEPTION_RECORD *er;
char debugger[MAX_PATH + 1];
WCHAR *debugger_utf16;
const char *debugger_env = NULL;
const char *catch_list;
gboolean catch = FALSE;
STARTUPINFO si;
STARTUPINFOW si;
PROCESS_INFORMATION pi;
HANDLE event;
SECURITY_ATTRIBUTES sa;
@@ -1165,11 +1178,13 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
CloseHandle (event);
return EXCEPTION_CONTINUE_SEARCH;
}
debugger[MAX_PATH] = '\0';
debugger_utf16 = g_utf8_to_utf16 (debugger, -1, NULL, NULL, NULL);
/* Run the debugger */
debugger[MAX_PATH] = '\0';
if (0 != CreateProcessA (NULL,
debugger,
if (0 != CreateProcessW (NULL,
debugger_utf16,
NULL,
NULL,
TRUE,
@@ -1190,6 +1205,8 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
WaitForSingleObject (event, 60000);
}
g_free (debugger_utf16);
CloseHandle (event);
/* Now the debugger is present, and we can try