Complete the transition to unicode APIs on Windows.

Define _UNICODE and UNICODE so that we do not add accidental
dependencies on non-unicode APIs.

Anton, this could have an influence on Dartium builds as well?

R=sgjesse@google.com,antonm@google.com
BUG=

Review URL: https://codereview.chromium.org//11567010

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16104 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ager@google.com 2012-12-13 12:43:01 +00:00
parent b6b4c929d3
commit 2a3c575b79
4 changed files with 60 additions and 51 deletions

View file

@ -3,12 +3,15 @@
// BSD-style license that can be found in the LICENSE file.
#include "bin/extensions.h"
#include "bin/utils.h"
void* Extensions::LoadExtensionLibrary(const char* library_path,
const char* extension_name) {
const char* strings[] = { library_path, "/", extension_name, ".dll", NULL };
char* library_file = Concatenate(strings);
void* lib_handle = LoadLibrary(library_file);
wchar_t* unicode_library_file = StringUtils::Utf8ToWide(library_file);
void* lib_handle = LoadLibraryW(unicode_library_file);
delete(unicode_library_file);
free(library_file);
return lib_handle;
}

View file

@ -202,7 +202,7 @@ enum NamedPipeType {
// NOTE: If this function returns false the handles might have been allocated
// and the caller should make sure to close them in case of an error.
static bool CreateProcessPipe(HANDLE handles[2],
char* pipe_name,
wchar_t* pipe_name,
NamedPipeType type) {
// Security attributes describing an inheritable handle.
SECURITY_ATTRIBUTES inherit_handle;
@ -212,14 +212,14 @@ static bool CreateProcessPipe(HANDLE handles[2],
if (type == kInheritRead) {
handles[kWriteHandle] =
CreateNamedPipe(pipe_name,
PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_WAIT,
1, // Number of pipes
1024, // Out buffer size
1024, // In buffer size
0, // Timeout in ms
NULL);
CreateNamedPipeW(pipe_name,
PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_WAIT,
1, // Number of pipes
1024, // Out buffer size
1024, // In buffer size
0, // Timeout in ms
NULL);
if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
@ -227,13 +227,13 @@ static bool CreateProcessPipe(HANDLE handles[2],
}
handles[kReadHandle] =
CreateFile(pipe_name,
GENERIC_READ,
0,
&inherit_handle,
OPEN_EXISTING,
FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
NULL);
CreateFileW(pipe_name,
GENERIC_READ,
0,
&inherit_handle,
OPEN_EXISTING,
FILE_READ_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
NULL);
if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
Log::PrintErr("CreateFile failed %d\n", GetLastError());
return false;
@ -241,14 +241,14 @@ static bool CreateProcessPipe(HANDLE handles[2],
} else {
ASSERT(type == kInheritWrite || type == kInheritNone);
handles[kReadHandle] =
CreateNamedPipe(pipe_name,
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_WAIT,
1, // Number of pipes
1024, // Out buffer size
1024, // In buffer size
0, // Timeout in ms
NULL);
CreateNamedPipeW(pipe_name,
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_WAIT,
1, // Number of pipes
1024, // Out buffer size
1024, // In buffer size
0, // Timeout in ms
NULL);
if (handles[kReadHandle] == INVALID_HANDLE_VALUE) {
Log::PrintErr("CreateNamedPipe failed %d\n", GetLastError());
@ -256,13 +256,13 @@ static bool CreateProcessPipe(HANDLE handles[2],
}
handles[kWriteHandle] =
CreateFile(pipe_name,
GENERIC_WRITE,
0,
(type == kInheritWrite) ? &inherit_handle : NULL,
OPEN_EXISTING,
FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
NULL);
CreateFileW(pipe_name,
GENERIC_WRITE,
0,
(type == kInheritWrite) ? &inherit_handle : NULL,
OPEN_EXISTING,
FILE_WRITE_ATTRIBUTES | FILE_FLAG_OVERLAPPED,
NULL);
if (handles[kWriteHandle] == INVALID_HANDLE_VALUE) {
Log::PrintErr("CreateFile failed %d\n", GetLastError());
return false;
@ -337,7 +337,8 @@ int Process::Start(const char* path,
HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
// Generate unique pipe names for the four named pipes needed.
char pipe_names[4][80];
static const int kMaxPipeNameSize = 80;
wchar_t pipe_names[4][kMaxPipeNameSize];
UUID uuid;
RPC_STATUS status = UuidCreateSequential(&uuid);
if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
@ -345,20 +346,20 @@ int Process::Start(const char* path,
Log::PrintErr("UuidCreateSequential failed %d\n", status);
return status;
}
RPC_CSTR uuid_string;
status = UuidToString(&uuid, &uuid_string);
RPC_WSTR uuid_string;
status = UuidToStringW(&uuid, &uuid_string);
if (status != RPC_S_OK) {
SetOsErrorMessage(os_error_message);
Log::PrintErr("UuidToString failed %d\n", status);
return status;
}
for (int i = 0; i < 4; i++) {
static const char* prefix = "\\\\.\\Pipe\\dart";
snprintf(pipe_names[i],
sizeof(pipe_names[i]),
"%s_%s_%d", prefix, uuid_string, i + 1);
static const wchar_t* prefix = L"\\\\.\\Pipe\\dart";
_snwprintf(pipe_names[i],
kMaxPipeNameSize,
L"%s_%s_%d", prefix, uuid_string, i + 1);
}
status = RpcStringFree(&uuid_string);
status = RpcStringFreeW(&uuid_string);
if (status != RPC_S_OK) {
SetOsErrorMessage(os_error_message);
Log::PrintErr("RpcStringFree failed %d\n", status);

View file

@ -66,12 +66,14 @@ bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
// Clear the port before calling WSAAddressToString as WSAAddressToString
// includes the port in the formatted string.
socket_address.sin_port = 0;
wchar_t* unicode_host = StringUtils::Utf8ToWide(host);
DWORD len = INET_ADDRSTRLEN;
int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&socket_address),
sizeof(socket_address),
NULL,
host,
&len);
int err = WSAAddressToStringW(reinterpret_cast<LPSOCKADDR>(&socket_address),
sizeof(socket_address),
NULL,
unicode_host,
&len);
free(unicode_host);
if (err != 0) {
Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError());
return false;
@ -195,12 +197,14 @@ const char* Socket::LookupIPv4Address(char* host, OSError** os_error) {
// Clear the port before calling WSAAddressToString as WSAAddressToString
// includes the port in the formatted string.
wchar_t* unicode_buffer = StringUtils::Utf8ToWide(buffer);
DWORD len = INET_ADDRSTRLEN;
int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(sockaddr),
sizeof(sockaddr_in),
NULL,
buffer,
&len);
int err = WSAAddressToStringW(reinterpret_cast<LPSOCKADDR>(sockaddr),
sizeof(sockaddr_in),
NULL,
unicode_buffer,
&len);
free(unicode_buffer);
if (err != 0) {
free(buffer);
return NULL;

View file

@ -20,7 +20,8 @@
#define NOSERVICE
#define NOSOUND
#define NOMCX
#define _UNICODE
#define UNICODE
#include <windows.h>
#include <winsock2.h>
#include <Rpc.h>