diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c index a777b7943..c69e9c66f 100644 --- a/gio/gdbusprivate.c +++ b/gio/gdbusprivate.c @@ -2026,10 +2026,10 @@ _g_dbus_compute_complete_signature (GDBusArgInfo **args) #ifdef G_OS_WIN32 -#define DBUS_DAEMON_ADDRESS_INFO "DBusDaemonAddressInfo" -#define DBUS_DAEMON_MUTEX "DBusDaemonMutex" -#define UNIQUE_DBUS_INIT_MUTEX "UniqueDBusInitMutex" -#define DBUS_AUTOLAUNCH_MUTEX "DBusAutolaunchMutex" +#define DBUS_DAEMON_ADDRESS_INFO L"DBusDaemonAddressInfo" +#define DBUS_DAEMON_MUTEX L"DBusDaemonMutex" +#define UNIQUE_DBUS_INIT_MUTEX L"UniqueDBusInitMutex" +#define DBUS_AUTOLAUNCH_MUTEX L"DBusAutolaunchMutex" static void release_mutex (HANDLE mutex) @@ -2039,12 +2039,12 @@ release_mutex (HANDLE mutex) } static HANDLE -acquire_mutex (const char *mutexname) +acquire_mutex (const wchar_t *mutexname) { HANDLE mutex; DWORD res; - mutex = CreateMutexA (NULL, FALSE, mutexname); + mutex = CreateMutex (NULL, FALSE, mutexname); if (!mutex) return 0; @@ -2063,12 +2063,12 @@ acquire_mutex (const char *mutexname) } static gboolean -is_mutex_owned (const char *mutexname) +is_mutex_owned (const wchar_t *mutexname) { HANDLE mutex; gboolean res = FALSE; - mutex = CreateMutexA (NULL, FALSE, mutexname); + mutex = CreateMutex (NULL, FALSE, mutexname); if (WaitForSingleObject (mutex, 10) == WAIT_TIMEOUT) res = TRUE; else @@ -2079,7 +2079,7 @@ is_mutex_owned (const char *mutexname) } static char * -read_shm (const char *shm_name) +read_shm (const wchar_t *shm_name) { HANDLE shared_mem; char *shared_data; @@ -2090,7 +2090,7 @@ read_shm (const char *shm_name) for (i = 0; i < 20; i++) { - shared_mem = OpenFileMappingA (FILE_MAP_READ, FALSE, shm_name); + shared_mem = OpenFileMapping (FILE_MAP_READ, FALSE, shm_name); if (shared_mem != 0) break; Sleep (100); @@ -2120,13 +2120,13 @@ read_shm (const char *shm_name) } static HANDLE -set_shm (const char *shm_name, const char *value) +set_shm (const wchar_t *shm_name, const char *value) { HANDLE shared_mem; char *shared_data; - shared_mem = CreateFileMappingA (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, - 0, strlen (value) + 1, shm_name); + shared_mem = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, + 0, strlen (value) + 1, shm_name); if (shared_mem == 0) return 0; @@ -2152,7 +2152,7 @@ publish_session_bus (const char *address) init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX); - published_daemon_mutex = CreateMutexA (NULL, FALSE, DBUS_DAEMON_MUTEX); + published_daemon_mutex = CreateMutex (NULL, FALSE, DBUS_DAEMON_MUTEX); if (WaitForSingleObject (published_daemon_mutex, 10 ) != WAIT_OBJECT_0) { release_mutex (init_mutex); @@ -2395,11 +2395,11 @@ gchar * _g_dbus_get_machine_id (GError **error) { #ifdef G_OS_WIN32 - HW_PROFILE_INFOA info; - char *src, *dest, *res; + HW_PROFILE_INFO info; + char *guid, *src, *dest, *res; int i; - if (!GetCurrentHwProfileA (&info)) + if (!GetCurrentHwProfile (&info)) { char *message = g_win32_error_message (GetLastError ()); g_set_error (error, @@ -2410,8 +2410,11 @@ _g_dbus_get_machine_id (GError **error) return NULL; } - /* Form: {12340001-4980-1920-6788-123456789012} */ - src = &info.szHwProfileGuid[0]; + if (!(guid = g_utf16_to_utf8 (info.szHwProfileGuid, -1, NULL, NULL, NULL))) + return NULL; + + /* Guid is of the form: {12340001-4980-1920-6788-123456789012} */ + src = guid; res = g_malloc (32+1); dest = res; @@ -2433,6 +2436,8 @@ _g_dbus_get_machine_id (GError **error) *dest++ = *src++; *dest = 0; + g_free (guid); + return res; #else gchar *ret = NULL; diff --git a/gio/giomodule.c b/gio/giomodule.c index 17fabe640..22522accc 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -1175,10 +1175,10 @@ void * _g_io_win32_get_module (void) { if (!gio_dll) - GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | - GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - (const char *) _g_io_win32_get_module, - &gio_dll); + GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCWSTR) _g_io_win32_get_module, + &gio_dll); return gio_dll; } diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c index c7a567549..58336c0c1 100644 --- a/gio/gthreadedresolver.c +++ b/gio/gthreadedresolver.c @@ -1104,7 +1104,7 @@ g_resolver_records_from_res_query (const gchar *rrname, #elif defined(G_OS_WIN32) static GVariant * -parse_dns_srv (DNS_RECORD *rec) +parse_dns_srv (DNS_RECORDA *rec) { return g_variant_new ("(qqqs)", (guint16)rec->Data.SRV.wPriority, @@ -1114,7 +1114,7 @@ parse_dns_srv (DNS_RECORD *rec) } static GVariant * -parse_dns_soa (DNS_RECORD *rec) +parse_dns_soa (DNS_RECORDA *rec) { return g_variant_new ("(ssuuuuu)", rec->Data.SOA.pNamePrimaryServer, @@ -1127,13 +1127,13 @@ parse_dns_soa (DNS_RECORD *rec) } static GVariant * -parse_dns_ns (DNS_RECORD *rec) +parse_dns_ns (DNS_RECORDA *rec) { return g_variant_new ("(s)", rec->Data.NS.pNameHost); } static GVariant * -parse_dns_mx (DNS_RECORD *rec) +parse_dns_mx (DNS_RECORDA *rec) { return g_variant_new ("(qs)", (guint16)rec->Data.MX.wPreference, @@ -1141,7 +1141,7 @@ parse_dns_mx (DNS_RECORD *rec) } static GVariant * -parse_dns_txt (DNS_RECORD *rec) +parse_dns_txt (DNS_RECORDA *rec) { GVariant *record; GPtrArray *array; @@ -1179,10 +1179,10 @@ static GList * g_resolver_records_from_DnsQuery (const gchar *rrname, WORD dnstype, DNS_STATUS status, - DNS_RECORD *results, + DNS_RECORDA *results, GError **error) { - DNS_RECORD *rec; + DNS_RECORDA *rec; gpointer record; GList *records; @@ -1342,11 +1342,18 @@ do_lookup_records (const gchar *rrname, #else DNS_STATUS status; - DNS_RECORD *results = NULL; + DNS_RECORDA *results = NULL; WORD dnstype; + /* Work around differences in Windows SDK and mingw-w64 headers */ +#ifdef _MSC_VER + typedef DNS_RECORDW * PDNS_RECORD_UTF8_; +#else + typedef DNS_RECORDA * PDNS_RECORD_UTF8_; +#endif + dnstype = g_resolver_record_type_to_dnstype (record_type); - status = DnsQuery_A (rrname, dnstype, DNS_QUERY_STANDARD, NULL, &results, NULL); + status = DnsQuery_UTF8 (rrname, dnstype, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD_UTF8_*)&results, NULL); records = g_resolver_records_from_DnsQuery (rrname, dnstype, status, results, error); if (results != NULL) DnsRecordListFree (results, DnsFreeRecordList); diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index 49e76ca9a..9e35239f8 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -4034,9 +4034,9 @@ gio_win32_appinfo_init (gboolean do_wait) /* Trigger initial tree build. Fake data pointer. */ g_thread_pool_push (gio_win32_appinfo_threadpool, (gpointer) keys_updated, NULL); /* Increment the DLL refcount */ - GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, - (const char *) gio_win32_appinfo_init, - &gio_dll_extra); + GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, + (LPCWSTR) gio_win32_appinfo_init, + &gio_dll_extra); /* gio DLL cannot be unloaded now */ g_once_init_leave (&initialized, TRUE); diff --git a/gio/gwin32sid.c b/gio/gwin32sid.c index 5bab4057a..ddc888bdc 100644 --- a/gio/gwin32sid.c +++ b/gio/gwin32sid.c @@ -192,20 +192,20 @@ _g_win32_process_get_access_token_sid (DWORD process_id, gchar * _g_win32_sid_to_string (SID *sid, GError **error) { - gchar *tmp, *ret; + wchar_t *tmp = NULL; + char *ret; g_return_val_if_fail (sid != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (!ConvertSidToStringSidA (sid, &tmp)) + if (!ConvertSidToStringSid (sid, &tmp)) { g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (GetLastError ()), "Failed to ConvertSidToString"); - return NULL; } - ret = g_strdup (tmp); + ret = g_utf16_to_utf8 (tmp, -1, NULL, NULL, NULL); LocalFree (tmp); return ret; } diff --git a/gio/tests/socket.c b/gio/tests/socket.c index c1c1bcf41..223f9b464 100644 --- a/gio/tests/socket.c +++ b/gio/tests/socket.c @@ -2201,6 +2201,7 @@ _g_win32_socketpair (gint domain, SOCKET client = INVALID_SOCKET; SOCKET server = INVALID_SOCKET; gchar *path = NULL; + wchar_t *path_utf16 = NULL; int tmpfd, rv = -1; u_long arg, br; @@ -2230,7 +2231,11 @@ _g_win32_socketpair (gint domain, if (listener == INVALID_SOCKET) goto out; - if (DeleteFile (path) == 0) + path_utf16 = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL); + if (!path_utf16) + goto out; + + if (DeleteFile (path_utf16) == 0) { if (GetLastError () != ERROR_FILE_NOT_FOUND) goto out; @@ -2285,7 +2290,10 @@ _g_win32_socketpair (gint domain, if (server != INVALID_SOCKET) closesocket (server); - DeleteFile (path); + if (path_utf16) + DeleteFile (path_utf16); + + g_free (path_utf16); g_free (path); return rv; } diff --git a/gio/tests/win32-streams.c b/gio/tests/win32-streams.c index aea660dfc..222498a6e 100644 --- a/gio/tests/win32-streams.c +++ b/gio/tests/win32-streams.c @@ -340,17 +340,21 @@ test_pipe_io_overlap (void) PipeIOOverlapReader rs, rc; HANDLE server, client; gchar name[256]; + wchar_t *name_utf16; g_snprintf (name, sizeof (name), "\\\\.\\pipe\\gtest-io-overlap-%u", (guint) GetCurrentProcessId ()); - server = CreateNamedPipe (name, + name_utf16 = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL); + g_assert_nonnull (name_utf16); + + server = CreateNamedPipe (name_utf16, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_READMODE_BYTE | PIPE_WAIT, 1, 0, 0, 0, NULL); g_assert (server != INVALID_HANDLE_VALUE); - client = CreateFile (name, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); + client = CreateFile (name_utf16, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); g_assert (client != INVALID_HANDLE_VALUE); out_server = g_win32_output_stream_new (server, TRUE); @@ -372,6 +376,8 @@ test_pipe_io_overlap (void) g_object_unref (rc.in); g_object_unref (out_server); g_object_unref (out_client); + + g_free (name_utf16); } static gpointer @@ -419,18 +425,22 @@ test_pipe_io_concurrent (void) PipeIOOverlapReader rc1, rc2; HANDLE server, client; gchar name[256], c; + wchar_t *name_utf16; g_snprintf (name, sizeof (name), "\\\\.\\pipe\\gtest-io-concurrent-%u", (guint) GetCurrentProcessId ()); - server = CreateNamedPipe (name, + name_utf16 = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL); + g_assert_nonnull (name_utf16); + + server = CreateNamedPipe (name_utf16, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_READMODE_BYTE | PIPE_WAIT, 1, 0, 0, 0, NULL); g_assert (server != INVALID_HANDLE_VALUE); g_assert (_pipe (writer_pipe, 10, _O_BINARY) == 0); - client = CreateFile (name, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + client = CreateFile (name_utf16, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); g_assert (client != INVALID_HANDLE_VALUE); rc1.in = g_win32_input_stream_new (client, TRUE); @@ -467,6 +477,8 @@ test_pipe_io_concurrent (void) close (writer_pipe[0]); close (writer_pipe[1]); + + g_free (name_utf16); } static void @@ -491,17 +503,21 @@ test_pipe_io_cancel (void) GOutputStream *out; HANDLE in_handle, out_handle; gchar name[256]; + wchar_t *name_utf16; g_snprintf (name, sizeof (name), "\\\\.\\pipe\\gtest-io-cancel-%u", (guint) GetCurrentProcessId ()); - in_handle = CreateNamedPipe (name, + name_utf16 = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL); + g_assert_nonnull (name_utf16); + + in_handle = CreateNamedPipe (name_utf16, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_READMODE_BYTE | PIPE_WAIT, 1, 0, 0, 0, NULL); g_assert (in_handle != INVALID_HANDLE_VALUE); - out_handle = CreateFile (name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + out_handle = CreateFile (name_utf16, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); g_assert (out_handle != INVALID_HANDLE_VALUE); in = g_win32_input_stream_new (in_handle, TRUE); @@ -521,6 +537,8 @@ test_pipe_io_cancel (void) g_object_unref (reader_cancel); g_object_unref (in); g_object_unref (out); + + g_free (name_utf16); } int diff --git a/glib/tests/io-channel-basic.c b/glib/tests/io-channel-basic.c index c1a46cd07..695df6dad 100644 --- a/glib/tests/io-channel-basic.c +++ b/glib/tests/io-channel-basic.c @@ -270,12 +270,12 @@ spawn_process (int children_nb) wcl.hCursor = NULL; wcl.hbrBackground = NULL; wcl.lpszMenuName = NULL; - wcl.lpszClassName = "io-channel-basic"; + wcl.lpszClassName = L"io-channel-basic"; klass = RegisterClass (&wcl); g_assert_cmpint (klass, !=, 0); - hwnd = CreateWindow (MAKEINTATOM(klass), "io-channel-basic", 0, 0, 0, 10, 10, + hwnd = CreateWindow (MAKEINTATOM (klass), L"io-channel-basic", 0, 0, 0, 10, 10, NULL, NULL, wcl.hInstance, NULL); g_assert_nonnull (hwnd); diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index a138e61e3..b9da90552 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -63,6 +63,7 @@ get_a_child (gint ttl) STARTUPINFO si; PROCESS_INFORMATION pi; gchar *cmdline; + wchar_t *cmdline_utf16; memset (&si, 0, sizeof (si)); si.cb = sizeof (&si); @@ -70,11 +71,15 @@ get_a_child (gint ttl) cmdline = g_strdup_printf ("%s %d", sleep_prog_path, ttl); - if (!CreateProcess (NULL, cmdline, NULL, NULL, + cmdline_utf16 = g_utf8_to_utf16 (cmdline, -1, NULL, NULL, NULL); + g_assert_nonnull (cmdline_utf16); + + if (!CreateProcess (NULL, cmdline_utf16, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) g_error ("CreateProcess failed: %s", g_win32_error_message (GetLastError ())); + g_free (cmdline_utf16); g_free (cmdline); CloseHandle (pi.hThread); diff --git a/meson.build b/meson.build index fa6a9d8e1..6084471f8 100644 --- a/meson.build +++ b/meson.build @@ -213,6 +213,10 @@ if host_system == 'qnx' add_project_arguments('-D_QNX_SOURCE', language: 'c') endif +if host_system == 'windows' + add_project_arguments(['-DUNICODE', '-D_UNICODE'], language: 'c') +endif + # Disable strict aliasing; # see https://bugzilla.gnome.org/show_bug.cgi?id=791622 if cc.has_argument('-fno-strict-aliasing')