1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-08 12:06:26 +00:00

[build] Support --clang when building dart sdk on Windows.

It relies on flutter copy of clang distribution, same one that is used to build flutter/engine.

It addressed several deprecated warnings from clang compiler for functions like strdup, unlink, etc.

It allows few warnings still since they are triggered in third_party sources.

Change-Id: Ieb13792c011438d46dbbc0fa030e1b5e4ea14315
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142704
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Alexander Aprelev 2020-06-25 03:36:41 +00:00 committed by commit-bot@chromium.org
parent 8eb0b79ac1
commit d33e51df3c
59 changed files with 283 additions and 152 deletions

10
DEPS
View File

@ -190,6 +190,16 @@ deps = {
Var("chromium_git") + "/chromium/llvm-project/cfe/tools/clang-format.git" +
"@" + Var("clang_format_scripts_rev"),
Var("dart_root") + "/third_party/llvm-build/Release+Asserts": {
"packages": [
{
"package": "flutter/clang/win-amd64",
"version": "git_revision:5ec206df8534d2dd8cb9217c3180e5ddba587393"
}
],
"condition": "download_windows_deps",
"dep_type": "cipd",
},
Var("dart_root") + "/benchmarks-internal": {
"url": Var("dart_internal_git") + "/benchmarks-internal.git" +
"@" + Var("benchmarks_internal_rev"),

View File

@ -364,7 +364,11 @@ set_defaults("component") {
if (is_win) {
# On windows we use the same toolchain for host and target by default.
host_toolchain = "//build/toolchain/win:$current_cpu"
if (is_clang) {
host_toolchain = "//build/toolchain/win:clang_$current_cpu"
} else {
host_toolchain = "//build/toolchain/win:$current_cpu"
}
set_default_toolchain("$host_toolchain")
} else if (is_android) {
if (host_os == "linux") {

View File

@ -514,19 +514,32 @@ if (is_win) {
default_warning_flags += [ "/WX" ] # Treat warnings as errors.
}
default_warning_flags += [
# Permanent.
"/wd4091", # typedef warning from dbghelp.h
"/wd4722", # destructor never returns
if (is_clang) {
default_warning_flags += [
"-Wno-deprecated-declarations", # crashpad
"-Wno-ignored-pragma-optimize", # icu, double-conversion
"-Wno-implicit-int-float-conversion", # icu
"-Wno-macro-redefined",
"-Wno-microsoft-cast",
"-Wno-microsoft-unqualified-friend",
"-Wno-unknown-argument", # icu
"-Wno-unused-value", # crashpad
]
} else {
default_warning_flags += [
# Permanent.
"/wd4091", # typedef warning from dbghelp.h
"/wd4722", # destructor never returns
# Investigate.
"/wd4312", # int to pointer of greater size conversion.
"/wd4838", # Narrowing conversion required.
"/wd4172", # Returning address of local.
"/wd4005", # Redefinition of macros for PRId64 etc.
"/wd4311", # Pointer truncation from PVOID to DWORD.
"/wd4477", # Format string requires wchar_t*
]
# Investigate.
"/wd4312", # int to pointer of greater size conversion.
"/wd4838", # Narrowing conversion required.
"/wd4172", # Returning address of local.
"/wd4005", # Redefinition of macros for PRId64 etc.
"/wd4311", # Pointer truncation from PVOID to DWORD.
"/wd4477", # Format string requires wchar_t*
]
}
} else {
# Common GCC warning setup.
default_warning_flags += [

View File

@ -72,7 +72,11 @@ template("msvc_toolchain") {
# TODO(brettw) enable this when GN support in the binary has been rolled.
#precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
flags = ""
if (invoker.current_cpu == "x86") {
flags = "-m32"
}
command = "ninja -t msvc -e $env -- $cl $flags /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
depsformat = "msvc"
description = "CC {{output}}"
outputs = [
@ -89,7 +93,11 @@ template("msvc_toolchain") {
# The PDB name needs to be different between C and C++ compiled files.
pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
flags = ""
if (invoker.current_cpu == "x86") {
flags = "-m32"
}
command = "ninja -t msvc -e $env -- $cl $flags /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
depsformat = "msvc"
description = "CXX {{output}}"
outputs = [

View File

@ -71,7 +71,7 @@ Dart_Isolate CreateKernelServiceIsolate(const IsolateCreationData& data,
Dart_EnterScope();
Dart_Handle result = Dart_LoadScriptFromKernel(buffer, buffer_size);
if (Dart_IsError(result)) {
*error = strdup(Dart_GetError(result));
*error = Utils::StrDup(Dart_GetError(result));
Dart_ExitScope();
Dart_ShutdownIsolate();
return nullptr;
@ -89,7 +89,7 @@ Dart_Isolate CreateVmServiceIsolate(const IsolateCreationData& data,
const uint8_t* isolate_instr,
char** error) {
if (data.flags == nullptr) {
*error = strdup("Expected non-null flags");
*error = Utils::StrDup("Expected non-null flags");
return nullptr;
}
data.flags->load_vmservice_library = true;
@ -108,7 +108,7 @@ Dart_Isolate CreateVmServiceIsolate(const IsolateCreationData& data,
config.write_service_info_filename,
/*trace_loading=*/false, config.deterministic,
/*enable_service_port_fallback=*/false)) {
*error = strdup(bin::VmService::GetErrorMessage());
*error = Utils::StrDup(bin::VmService::GetErrorMessage());
return nullptr;
}
@ -124,7 +124,7 @@ Dart_Isolate CreateVmServiceIsolateFromKernel(
intptr_t kernel_buffer_size,
char** error) {
if (data.flags == nullptr) {
*error = strdup("Expected non-null flags");
*error = Utils::StrDup("Expected non-null flags");
return nullptr;
}
data.flags->load_vmservice_library = true;
@ -143,7 +143,7 @@ Dart_Isolate CreateVmServiceIsolateFromKernel(
config.write_service_info_filename,
/*trace_loading=*/false, config.deterministic,
/*enable_service_port_fallback=*/false)) {
*error = strdup(bin::VmService::GetErrorMessage());
*error = Utils::StrDup(bin::VmService::GetErrorMessage());
return nullptr;
}

View File

@ -242,7 +242,7 @@ const char* DartUtils::RemoveScheme(const char* url) {
char* DartUtils::DirName(const char* url) {
const char* slash = strrchr(url, File::PathSeparator()[0]);
if (slash == NULL) {
return strdup(url);
return Utils::StrDup(url);
} else {
return Utils::StrNDup(url, slash - url + 1);
}

View File

@ -439,7 +439,7 @@ static bool TryReadKernelListBuffer(const char* script_uri,
StringPointer resolved_filename(
File::IsAbsolutePath(filename)
? strdup(filename)
? Utils::StrDup(filename)
: Utils::SCreate("%s%s", kernel_list_dirname, filename));
if (!TryReadFile(resolved_filename.c_str(), &this_buffer,
&this_kernel_size)) {

View File

@ -11,6 +11,7 @@
#include "include/dart_native_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "platform/utils.h"
namespace dart {
namespace bin {
@ -31,7 +32,7 @@ class DFE {
if (frontend_filename_ != nullptr) {
free(frontend_filename_);
}
frontend_filename_ = strdup(name);
frontend_filename_ = Utils::StrDup(name);
set_use_dfe();
}
void set_use_dfe(bool value = true) { use_dfe_ = value; }

View File

@ -260,7 +260,7 @@ void Directory::SetSystemTemp(const char* path) {
system_temp_path_override_ = NULL;
}
if (path != NULL) {
system_temp_path_override_ = strdup(path);
system_temp_path_override_ = Utils::StrDup(path);
}
}

View File

@ -98,7 +98,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
name = File::LinkTarget(namespc, GetFileNameFromPath(name), target,
kTargetSize);
if (name == nullptr) {
return Utils::CreateCStringUniquePtr(strdup(""));
return Utils::CreateCStringUniquePtr(Utils::StrDup(""));
}
} while (File::GetType(namespc, name, false) == File::kIsLink);
target_size = strlen(name);
@ -117,7 +117,8 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
result = GetDirectoryFromPath(target, nullptr);
}
namespc->Release();
return Utils::CreateCStringUniquePtr(result == nullptr ? strdup("") : result);
return Utils::CreateCStringUniquePtr(result == nullptr ? Utils::StrDup("")
: result);
}
} // namespace bin

View File

@ -65,7 +65,7 @@ void* Extensions::MakePathAndResolve(const char* dir, const char* name) {
// loaded from the standard location.
void* Extensions::ResolveAbsPathExtension(const char* extension_path) {
const char* last_slash = strrchr(extension_path, PathSeparator()) + 1;
char* name = strdup(last_slash);
char* name = Utils::StrDup(last_slash);
char* dir = Utils::StrNDup(extension_path, last_slash - extension_path);
void* library_handle = MakePathAndResolve(dir, name);
free(dir);

View File

@ -29,7 +29,8 @@ void* Extensions::LoadExtensionLibrary(const char* library_file) {
void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) {
SetLastError(0);
return GetProcAddress(reinterpret_cast<HMODULE>(lib_handle), symbol);
return reinterpret_cast<void*>(
GetProcAddress(reinterpret_cast<HMODULE>(lib_handle), symbol));
}
void Extensions::UnloadLibrary(void* lib_handle) {

View File

@ -11,6 +11,7 @@
#include <fcntl.h> // NOLINT
#include <io.h> // NOLINT
#include <Shlwapi.h> // NOLINT
#undef StrDup // defined in Shlwapi.h as StrDupW
#include <stdio.h> // NOLINT
#include <string.h> // NOLINT
#include <sys/stat.h> // NOLINT
@ -55,9 +56,9 @@ void File::Close() {
int fd = _open("NUL", _O_WRONLY);
ASSERT(fd >= 0);
_dup2(fd, closing_fd);
close(fd);
Utils::Close(fd);
} else {
int err = close(closing_fd);
int err = Utils::Close(closing_fd);
if (err != 0) {
Syslog::PrintErr("%s\n", strerror(errno));
}
@ -141,7 +142,7 @@ void MappedMemory::Unmap() {
int64_t File::Read(void* buffer, int64_t num_bytes) {
ASSERT(handle_->fd() >= 0);
return read(handle_->fd(), buffer, num_bytes);
return Utils::Read(handle_->fd(), buffer, num_bytes);
}
int64_t File::Write(const void* buffer, int64_t num_bytes) {
@ -311,7 +312,7 @@ Utils::CStringUniquePtr File::UriToPath(const char* uri) {
Utf8ToWideScope uri_w(uri_decoder.decoded());
if (!UrlIsFileUrlW(uri_w.wide())) {
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
return Utils::CreateCStringUniquePtr(Utils::StrDup(uri_decoder.decoded()));
}
wchar_t filename_w[MAX_PATH];
DWORD filename_len = MAX_PATH;
@ -382,7 +383,7 @@ bool File::Create(Namespace* namespc, const char* name) {
if (fd < 0) {
return false;
}
return (close(fd) == 0);
return (Utils::Close(fd) == 0);
}
// This structure is needed for creating and reading Junctions.

View File

@ -13,14 +13,14 @@ IsolateGroupData::IsolateGroupData(const char* url,
const char* packages_file,
AppSnapshot* app_snapshot,
bool isolate_run_app_snapshot)
: script_url((url != NULL) ? strdup(url) : NULL),
: script_url((url != NULL) ? Utils::StrDup(url) : NULL),
app_snapshot_(app_snapshot),
resolved_packages_config_(NULL),
kernel_buffer_(NULL),
kernel_buffer_size_(0),
isolate_run_app_snapshot_(isolate_run_app_snapshot) {
if (packages_file != NULL) {
packages_file_ = strdup(packages_file);
packages_file_ = Utils::StrDup(packages_file);
}
}
@ -40,7 +40,7 @@ IsolateData::IsolateData(IsolateGroupData* isolate_group_data)
loader_(nullptr),
packages_file_(nullptr) {
if (isolate_group_data->packages_file_ != nullptr) {
packages_file_ = strdup(isolate_group_data->packages_file_);
packages_file_ = Utils::StrDup(isolate_group_data->packages_file_);
}
}

View File

@ -11,6 +11,7 @@
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "platform/utils.h"
namespace dart {
@ -83,7 +84,7 @@ class IsolateGroupData {
free(resolved_packages_config_);
resolved_packages_config_ = NULL;
}
resolved_packages_config_ = strdup(packages_config);
resolved_packages_config_ = Utils::StrDup(packages_config);
}
bool RunFromAppSnapshot() const {
@ -125,7 +126,7 @@ class IsolateData {
free(packages_file_);
packages_file_ = nullptr;
}
packages_file_ = strdup(packages_file);
packages_file_ = Utils::StrDup(packages_file);
}
// While loading a loader is associated with the isolate.

View File

@ -80,7 +80,7 @@ Dart_Handle Loader::LoadImportExtension(const char* url_string,
if (strncmp(lib_uri_str, "file://", 7) == 0) {
lib_path = DartUtils::DirName(lib_uri_str + 7);
} else {
lib_path = strdup(lib_uri_str);
lib_path = Utils::StrDup(lib_uri_str);
}
const char* path = DartUtils::RemoveScheme(url_string);
@ -126,7 +126,7 @@ Dart_Handle Loader::ReloadNativeExtensions() {
if (strncmp(lib_uri, "file://", 7) == 0) {
lib_path = DartUtils::DirName(DartUtils::RemoveScheme(lib_uri));
} else {
lib_path = strdup(lib_uri);
lib_path = Utils::StrDup(lib_uri);
}
result = Extensions::LoadExtension(lib_path, extension_path, importer);

View File

@ -99,7 +99,7 @@ static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) {
}
#define SAVE_ERROR_AND_EXIT(result) \
*error = strdup(Dart_GetError(result)); \
*error = Utils::StrDup(Dart_GetError(result)); \
if (Dart_IsCompilationError(result)) { \
*exit_code = kCompilationErrorExitCode; \
} else if (Dart_IsApiError(result)) { \
@ -278,7 +278,7 @@ static bool OnIsolateInitialize(void** child_callback_data, char** error) {
return *error == nullptr;
failed:
*error = strdup(Dart_GetError(result));
*error = Utils::StrDup(Dart_GetError(result));
Dart_ExitScope();
return false;
}
@ -368,7 +368,7 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
&resolved_script_uri);
CHECK_RESULT(result);
ASSERT(app_script_uri == NULL);
app_script_uri = strdup(resolved_script_uri);
app_script_uri = Utils::StrDup(resolved_script_uri);
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} else {
@ -559,7 +559,7 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
Options::vm_service_dev_mode(), Options::vm_service_auth_disabled(),
Options::vm_write_service_info_filename(), Options::trace_loading(),
Options::deterministic(), Options::enable_service_port_fallback())) {
*error = strdup(VmService::GetErrorMessage());
*error = Utils::StrDup(VmService::GetErrorMessage());
return NULL;
}
if (Options::compile_all()) {

View File

@ -392,7 +392,8 @@ bool Options::ProcessEnableExperimentOption(const char* arg,
return false;
}
vm_options->AddArgument(arg);
Utils::CStringUniquePtr tmp = Utils::CreateCStringUniquePtr(strdup(value));
Utils::CStringUniquePtr tmp = Utils::CreateCStringUniquePtr(
Utils::StrDup(value));
char* save_ptr; // Needed for strtok_r.
char* token = strtok_r(const_cast<char*>(tmp.get()), ",", &save_ptr);
while (token != NULL) {
@ -526,7 +527,7 @@ int Options::ParseArguments(int argc,
script_or_cmd_index = i;
if (Options::disable_dart_dev() ||
(is_potential_file_path && !enable_vm_service_)) {
*script_name = strdup(argv[i]);
*script_name = Utils::StrDup(argv[i]);
run_script = true;
i++;
} else {

View File

@ -81,7 +81,7 @@ bool OptionProcessor::ProcessEnvironmentOption(
name = reinterpret_cast<char*>(malloc(name_len + 1));
strncpy(name, arg, name_len);
name[name_len] = '\0';
value = strdup(equals_pos + 1);
value = Utils::StrDup(equals_pos + 1);
SimpleHashMap::Entry* entry =
(*environment)
->Lookup(GetHashmapKeyFromString(name),

View File

@ -7,6 +7,7 @@
#include "bin/builtin.h"
#include "platform/globals.h"
#include "platform/utils.h"
namespace dart {
namespace bin {
@ -82,7 +83,7 @@ class Platform {
// Try to resolve the executable path using platform specific APIs.
const char* resolved_name = Platform::ResolveExecutablePath();
if (resolved_name != NULL) {
resolved_executable_name_ = strdup(resolved_name);
resolved_executable_name_ = Utils::StrDup(resolved_name);
}
}
return resolved_executable_name_;

View File

@ -94,7 +94,7 @@ static void PrintUsage() {
#define CHECK_RESULT(result) \
if (Dart_IsError(result)) { \
*error = strdup(Dart_GetError(result)); \
*error = Utils::StrDup(Dart_GetError(result)); \
Dart_ExitScope(); \
Dart_ShutdownIsolate(); \
return nullptr; \
@ -150,7 +150,7 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
/*write_service_info_filename*/ "",
/*trace_loading=*/false, /*deterministic=*/true,
/*enable_service_port_fallback=*/false)) {
*error = strdup(bin::VmService::GetErrorMessage());
*error = Utils::StrDup(bin::VmService::GetErrorMessage());
return nullptr;
}
result = Dart_SetEnvironmentCallback(bin::DartUtils::EnvironmentCallback);
@ -176,8 +176,8 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
const bool is_kernel_isolate =
strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0;
if (!is_kernel_isolate) {
*error =
strdup("Spawning of only Kernel isolate is supported in run_vm_tests.");
*error = Utils::StrDup(
"Spawning of only Kernel isolate is supported in run_vm_tests.");
return nullptr;
}
Dart_Isolate isolate = nullptr;
@ -337,7 +337,7 @@ static int Main(int argc, const char** argv) {
PrintUsage();
return 1;
}
kernel_snapshot = strdup(delim + 1);
kernel_snapshot = Utils::StrDup(delim + 1);
start_kernel_isolate = true;
ShiftArgs(&argc, argv);
}

View File

@ -494,7 +494,7 @@ void SSLFilter::Connect(const char* hostname,
// Sets the hostname in the certificate-checking object, so it is checked
// against the certificate presented by the server.
X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_);
hostname_ = strdup(hostname);
hostname_ = Utils::StrDup(hostname);
X509_VERIFY_PARAM_set_flags(
certificate_checking_parameters,
X509_V_FLAG_PARTIAL_CHAIN | X509_V_FLAG_TRUSTED_FIRST);

View File

@ -289,10 +289,10 @@ bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket,
// If the socket is abstract, which has a path starting with a null byte,
// unlink() is not necessary because the file doesn't exist.
if (os_socket->address.un.sun_path[0] != '\0') {
unlink(os_socket->address.un.sun_path);
Utils::Unlink(os_socket->address.un.sun_path);
}
#else
unlink(os_socket->address.un.sun_path);
Utils::Unlink(os_socket->address.un.sun_path);
#endif // defined(HOST_OS_LINUX) || defined(HOST_OS_ANDROID)
// Remove os_socket from unix_domain_sockets_ list.
OSSocket* prev = nullptr;

View File

@ -65,7 +65,15 @@ bool SocketBase::FormatNumericAddress(const RawAddr& addr,
socklen_t salen = SocketAddress::GetAddrLength(addr);
DWORD l = len;
RawAddr& raw = const_cast<RawAddr&>(addr);
return WSAAddressToStringA(&raw.addr, salen, NULL, address, &l) != 0;
wchar_t* waddress = reinterpret_cast<wchar_t*>(
Dart_ScopeAllocate((salen + 1) * sizeof(wchar_t)));
intptr_t result = WSAAddressToStringW(&raw.addr, salen, NULL, waddress, &l);
if (result != 0) {
return true;
}
WideToUtf8Scope wide_name(waddress);
strncpy(address, wide_name.utf8(), l);
return false;
}
intptr_t SocketBase::Available(intptr_t fd) {

View File

@ -10,6 +10,7 @@
#include "include/dart_api.h"
#include "platform/globals.h"
#include "platform/utils.h"
namespace dart {
namespace bin {
@ -43,7 +44,7 @@ class OSError {
if (message == NULL) {
message_ = NULL;
} else {
message_ = strdup(message);
message_ = Utils::StrDup(message);
}
}

View File

@ -13,6 +13,7 @@
#include "bin/thread.h"
#include "bin/utils.h"
#include "platform/text_buffer.h"
#include "platform/utils.h"
namespace dart {
namespace bin {
@ -24,7 +25,7 @@ namespace bin {
#define SHUTDOWN_ON_ERROR(handle) \
if (Dart_IsError(handle)) { \
error_msg_ = strdup(Dart_GetError(handle)); \
error_msg_ = Utils::StrDup(Dart_GetError(handle)); \
Dart_ExitScope(); \
Dart_ShutdownIsolate(); \
return false; \

View File

@ -105,7 +105,8 @@ static void* ResolveSymbol(void* handle, const char* symbol) {
return pointer;
#elif defined(HOST_OS_WINDOWS)
SetLastError(0);
void* pointer = GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol);
void* pointer = reinterpret_cast<void*>(
GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol));
if (pointer == nullptr) {
const int error = GetLastError();
const String& msg = String::Handle(

View File

@ -414,8 +414,13 @@ class Utils {
// Not all platforms support strndup.
static char* StrNDup(const char* s, intptr_t n);
static char* StrDup(const char* s);
static intptr_t StrNLen(const char* s, intptr_t n);
static int Close(int fildes);
static size_t Read(int filedes, void* buf, size_t nbyte);
static int Unlink(const char* path);
// Print formatted output info a buffer.
//
// Does not write more than size characters (including the trailing '\0').

View File

@ -13,6 +13,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
return strndup(s, n);
}
char* Utils::StrDup(const char* s) {
return strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
return strnlen(s, n);
}
@ -33,6 +37,16 @@ int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
return retval;
}
int Utils::Close(int fildes) {
return close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return unlink(path);
}
} // namespace dart
#endif // defined(HOST_OS_ANDROID)

View File

@ -17,6 +17,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
return strndup(s, n);
}
char* Utils::StrDup(const char* s) {
return strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
return strnlen(s, n);
}
@ -37,6 +41,16 @@ int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
return retval;
}
int Utils::Close(int fildes) {
return close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return unlink(path);
}
sys::ComponentContext* ComponentContext() {
static std::unique_ptr<sys::ComponentContext> context =
sys::ComponentContext::CreateAndServeOutgoingDirectory();

View File

@ -13,6 +13,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
return strndup(s, n);
}
char* Utils::StrDup(const char* s) {
return strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
return strnlen(s, n);
}
@ -34,6 +38,16 @@ int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
return retval;
}
int Utils::Close(int fildes) {
return close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return unlink(path);
}
} // namespace dart
#endif // defined(HOST_OS_LINUX)

View File

@ -35,6 +35,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
#endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ...
}
char* Utils::StrDup(const char* s) {
return strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
// strnlen has only been added to Mac OS X in 10.7. We are supplying
// our own copy here if needed.
@ -67,6 +71,16 @@ int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
return retval;
}
int Utils::Close(int fildes) {
return close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return unlink(path);
}
namespace internal {
// Returns the running system's Darwin major version. Don't call this, it's

View File

@ -5,6 +5,7 @@
#include "platform/globals.h"
#if defined(HOST_OS_WINDOWS)
#include <io.h> // NOLINT
#include "platform/utils.h"
namespace dart {
@ -25,6 +26,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
return reinterpret_cast<char*>(memmove(result, s, len));
}
char* Utils::StrDup(const char* s) {
return _strdup(s);
}
intptr_t Utils::StrNLen(const char* s, intptr_t n) {
return strnlen(s, n);
}
@ -71,6 +76,16 @@ int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
return written;
}
int Utils::Close(int fildes) {
return _close(fildes);
}
size_t Utils::Read(int filedes, void* buf, size_t nbyte) {
return _read(filedes, buf, nbyte);
}
int Utils::Unlink(const char* path) {
return _unlink(path);
}
} // namespace dart
#endif // defined(HOST_OS_WINDOWS)

View File

@ -13,6 +13,7 @@
#include "platform/assert.h"
#include "platform/globals.h"
#include "platform/utils.h"
#include "vm/clustered_snapshot.h"
#include "vm/dart_api_impl.h"
@ -63,7 +64,7 @@ BENCHMARK(CorelibCompileAll) {
// which is depended on by run_vm_tests.
static char* ComputeKernelServicePath(const char* arg) {
char buffer[2048];
char* kernel_service_path = strdup(File::GetCanonicalPath(NULL, arg));
char* kernel_service_path = Utils::StrDup(File::GetCanonicalPath(NULL, arg));
EXPECT(kernel_service_path != NULL);
const char* compiler_path = "%s%sgen%skernel_service.dill";
const char* path_separator = File::PathSeparator();
@ -82,14 +83,14 @@ static char* ComputeKernelServicePath(const char* arg) {
if (ptr == NULL) {
return NULL;
}
return strdup(buffer);
return Utils::StrDup(buffer);
}
// This file is created by the target //runtime/bin:gen_kernel_bytecode_dill
// which is depended on by run_vm_tests.
static char* ComputeGenKernelKernelPath(const char* arg) {
char buffer[2048];
char* gen_kernel_path = strdup(File::GetCanonicalPath(NULL, arg));
char* gen_kernel_path = Utils::StrDup(File::GetCanonicalPath(NULL, arg));
EXPECT(gen_kernel_path != NULL);
const char* compiler_path = "%s%sgen_kernel_bytecode.dill";
const char* path_separator = File::PathSeparator();
@ -108,7 +109,7 @@ static char* ComputeGenKernelKernelPath(const char* arg) {
if (ptr == NULL) {
return NULL;
}
return strdup(buffer);
return Utils::StrDup(buffer);
}
static int64_t GenKernelKernelBenchmark(const char* name,

View File

@ -6134,7 +6134,7 @@ char* SnapshotHeaderReader::ReadFeatures(const char** features,
}
char* SnapshotHeaderReader::BuildError(const char* message) {
return strdup(message);
return Utils::StrDup(message);
}
ApiErrorPtr FullSnapshotReader::ConvertToApiError(char* message) {

View File

@ -779,7 +779,7 @@ void Assembler::negatepd(XmmRegister dst) {
static const struct ALIGN16 {
uint64_t a;
uint64_t b;
} double_negate_constant = {0x8000000000000000LL, 0x8000000000000000LL};
} double_negate_constant = {0x8000000000000000LLU, 0x8000000000000000LLU};
xorpd(dst,
Address::Absolute(reinterpret_cast<uword>(&double_negate_constant)));
}
@ -2075,7 +2075,7 @@ void Assembler::DoubleNegate(XmmRegister d) {
static const struct ALIGN16 {
uint64_t a;
uint64_t b;
} double_negate_constant = {0x8000000000000000LL, 0x8000000000000000LL};
} double_negate_constant = {0x8000000000000000LLU, 0x8000000000000000LLU};
xorpd(d, Address::Absolute(reinterpret_cast<uword>(&double_negate_constant)));
}

View File

@ -81,11 +81,11 @@ void CpuId::Cleanup() {
}
const char* CpuId::id_string() {
return strdup(id_string_);
return Utils::StrDup(id_string_);
}
const char* CpuId::brand_string() {
return strdup(brand_string_);
return Utils::StrDup(brand_string_);
}
const char* CpuId::field(CpuInfoIndices idx) {
@ -115,7 +115,7 @@ const char* CpuId::field(CpuInfoIndices idx) {
}
// Remove last space before returning string.
if (p != buffer) *(p - 1) = '\0';
return strdup(buffer);
return Utils::StrDup(buffer);
}
default: {
UNREACHABLE();

View File

@ -6,6 +6,7 @@
#define RUNTIME_VM_CPUINFO_H_
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/allocation.h"
namespace dart {
@ -56,7 +57,7 @@ class CpuInfo : public AllStatic {
if (HasField(FieldName(kCpuInfoHardware))) {
return ExtractField(kCpuInfoHardware);
} else {
return strdup("Unknown");
return Utils::StrDup("Unknown");
}
}

View File

@ -245,7 +245,7 @@ static void native_echo(Dart_NativeArguments args) {
if (saved_echo != nullptr) {
free(saved_echo);
}
saved_echo = strdup(c_str);
saved_echo = Utils::StrDup(c_str);
OS::PrintErr("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str);
Dart_ExitScope();
}
@ -262,7 +262,7 @@ static void CustomIsolateImpl_start(Dart_NativeArguments args) {
EXPECT(Dart_IsString(param));
const char* isolate_main = NULL;
EXPECT_VALID(Dart_StringToCString(param, &isolate_main));
isolate_main = strdup(isolate_main);
isolate_main = Utils::StrDup(isolate_main);
// Save current isolate.
Dart_Isolate saved_isolate = Dart_CurrentIsolate();

View File

@ -161,11 +161,11 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
CheckOffsets();
// TODO(iposva): Fix race condition here.
if (vm_isolate_ != NULL || !Flags::Initialized()) {
return strdup("VM already initialized or flags not initialized.");
return Utils::StrDup("VM already initialized or flags not initialized.");
}
if (FLAG_causal_async_stacks && FLAG_lazy_async_stacks) {
return strdup(
return Utils::StrDup(
"To use --lazy-async-stacks, please disable --causal-async-stacks!");
}
@ -173,7 +173,7 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
if (vm_isolate_snapshot != nullptr) {
snapshot = Snapshot::SetupFromBuffer(vm_isolate_snapshot);
if (snapshot == nullptr) {
return strdup("Invalid vm isolate snapshot seen");
return Utils::StrDup("Invalid vm isolate snapshot seen");
}
}
@ -282,15 +282,16 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
if (Snapshot::IncludesCode(vm_snapshot_kind_)) {
if (vm_snapshot_kind_ == Snapshot::kFullAOT) {
#if !defined(DART_PRECOMPILED_RUNTIME)
return strdup("JIT runtime cannot run a precompiled snapshot");
return Utils::StrDup("JIT runtime cannot run a precompiled snapshot");
#endif
}
if (instructions_snapshot == NULL) {
return strdup("Missing instructions snapshot");
return Utils::StrDup("Missing instructions snapshot");
}
} else if (Snapshot::IsFull(vm_snapshot_kind_)) {
#if defined(DART_PRECOMPILED_RUNTIME)
return strdup("Precompiled runtime requires a precompiled snapshot");
return Utils::StrDup(
"Precompiled runtime requires a precompiled snapshot");
#else
StubCode::Init();
Object::FinishInit(vm_isolate_);
@ -303,13 +304,13 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
MallocHooks::Init();
#endif
} else {
return strdup("Invalid vm isolate snapshot seen");
return Utils::StrDup("Invalid vm isolate snapshot seen");
}
FullSnapshotReader reader(snapshot, instructions_snapshot, T);
const Error& error = Error::Handle(reader.ReadVMSnapshot());
if (!error.IsNull()) {
// Must copy before leaving the zone.
return strdup(error.ToErrorCString());
return Utils::StrDup(error.ToErrorCString());
}
ReversePcLookupCache::BuildAndAttachToIsolateGroup(vm_isolate_->group());
@ -337,7 +338,8 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
}
} else {
#if defined(DART_PRECOMPILED_RUNTIME)
return strdup("Precompiled runtime requires a precompiled snapshot");
return Utils::StrDup(
"Precompiled runtime requires a precompiled snapshot");
#else
vm_snapshot_kind_ = Snapshot::kNone;
StubCode::Init();
@ -358,7 +360,7 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
// Dart VM requires at least SSE2.
if (!TargetCPUFeatures::sse2_supported()) {
return strdup("SSE2 is required.");
return Utils::StrDup("SSE2 is required.");
}
#endif
{
@ -469,7 +471,7 @@ void Dart::WaitForIsolateShutdown() {
char* Dart::Cleanup() {
ASSERT(Isolate::Current() == NULL);
if (vm_isolate_ == NULL) {
return strdup("VM already terminated.");
return Utils::StrDup("VM already terminated.");
}
if (FLAG_trace_shutdown) {

View File

@ -1047,13 +1047,13 @@ DART_EXPORT const char* Dart_VersionString() {
DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) {
if (params == NULL) {
return strdup(
return Utils::StrDup(
"Dart_Initialize: "
"Dart_InitializeParams is null.");
}
if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) {
return strdup(
return Utils::StrDup(
"Dart_Initialize: "
"Invalid Dart_InitializeParams version.");
}
@ -1139,7 +1139,7 @@ static Dart_Isolate CreateIsolate(IsolateGroup* group,
Isolate* I = Dart::CreateIsolate(name, source->flags, group);
if (I == NULL) {
if (error != NULL) {
*error = strdup("Isolate creation failed");
*error = Utils::StrDup("Isolate creation failed");
}
return reinterpret_cast<Dart_Isolate>(NULL);
}
@ -1166,7 +1166,7 @@ static Dart_Isolate CreateIsolate(IsolateGroup* group,
#endif // defined(DEBUG) && !defined(DART_PRECOMPILED_RUNTIME).
success = true;
} else if (error != NULL) {
*error = strdup(error_obj.ToErrorCString());
*error = Utils::StrDup(error_obj.ToErrorCString());
}
// We exit the API scope entered above.
T->ExitApiScope();
@ -1615,7 +1615,7 @@ DART_EXPORT bool Dart_WriteProfileToTimeline(Dart_Port main_port,
#else
if (!FLAG_profiler) {
if (error != NULL) {
*error = strdup("The profiler is not running.");
*error = Utils::StrDup("The profiler is not running.");
}
return false;
}
@ -1898,7 +1898,7 @@ DART_EXPORT char* Dart_IsolateMakeRunnable(Dart_Isolate isolate) {
error = iso->MakeRunnable();
}
if (error != NULL) {
return strdup(error);
return Utils::StrDup(error);
}
return NULL;
}
@ -5986,7 +5986,7 @@ Dart_CompileToKernel(const char* script_uri,
Dart_KernelCompilationResult result = {};
#if defined(DART_PRECOMPILED_RUNTIME)
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Dart_CompileToKernel is unsupported.");
result.error = Utils::StrDup("Dart_CompileToKernel is unsupported.");
#else
result = KernelIsolate::CompileToKernel(script_uri, platform_kernel,
platform_kernel_size, 0, NULL,
@ -6009,7 +6009,7 @@ DART_EXPORT Dart_KernelCompilationResult Dart_KernelListDependencies() {
Dart_KernelCompilationResult result = {};
#if defined(DART_PRECOMPILED_RUNTIME)
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Dart_KernelListDependencies is unsupported.");
result.error = Utils::StrDup("Dart_KernelListDependencies is unsupported.");
#else
result = KernelIsolate::ListDependencies();
#endif
@ -6092,28 +6092,28 @@ DART_EXPORT char* Dart_SetServiceStreamCallbacks(
#else
if (listen_callback != NULL) {
if (Service::stream_listen_callback() != NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetServiceStreamCallbacks "
"permits only one listen callback to be registered, please "
"remove the existing callback and then add this callback");
}
} else {
if (Service::stream_listen_callback() == NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetServiceStreamCallbacks "
"expects 'listen_callback' to be present in the callback set.");
}
}
if (cancel_callback != NULL) {
if (Service::stream_cancel_callback() != NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetServiceStreamCallbacks "
"permits only one cancel callback to be registered, please "
"remove the existing callback and then add this callback");
}
} else {
if (Service::stream_cancel_callback() == NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetServiceStreamCallbacks "
"expects 'cancel_callback' to be present in the callback set.");
}
@ -6162,14 +6162,14 @@ DART_EXPORT char* Dart_SetFileModifiedCallback(
#if !defined(DART_PRECOMPILED_RUNTIME)
if (file_modified_callback != NULL) {
if (IsolateGroupReloadContext::file_modified_callback() != NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetFileModifiedCallback permits only one callback to be"
" registered, please remove the existing callback and then add"
" this callback");
}
} else {
if (IsolateGroupReloadContext::file_modified_callback() == NULL) {
return strdup(
return Utils::StrDup(
"Dart_SetFileModifiedCallback expects 'file_modified_callback' to"
" be set before it is cleared.");
}

View File

@ -6917,7 +6917,8 @@ static void UnreachableFinalizer(void* isolate_callback_data,
}
TEST_CASE(DartAPI_PostCObject_DoesNotRunFinalizerOnFailure) {
char* my_str = strdup("Ownership of this memory remains with the caller");
char* my_str =
Utils::StrDup("Ownership of this memory remains with the caller");
Dart_CObject message;
message.type = Dart_CObject_kExternalTypedData;

View File

@ -291,7 +291,7 @@ bool Flags::SetFlagFromString(Flag* flag, const char* argument) {
break;
}
case Flag::kString: {
*flag->charp_ptr_ = argument == NULL ? NULL : strdup(argument);
*flag->charp_ptr_ = argument == NULL ? NULL : Utils::StrDup(argument);
break;
}
case Flag::kInteger: {
@ -423,7 +423,7 @@ int Flags::CompareFlagNames(const void* left, const void* right) {
char* Flags::ProcessCommandLineFlags(int number_of_vm_flags,
const char** vm_flags) {
if (initialized_) {
return strdup("Flags already set");
return Utils::StrDup("Flags already set");
}
qsort(flags_, num_flags_, sizeof flags_[0], CompareFlagNames);

View File

@ -649,7 +649,7 @@ class MergeIsolatesHeapsHandler : public MessageHandler {
if (response_obj.IsString()) {
String& response = String::Handle();
response ^= response_obj.raw();
msg_.reset(strdup(response.ToCString()));
msg_.reset(Utils::StrDup(response.ToCString()));
} else {
ASSERT(response_obj.IsArray());
Array& response_array = Array::Handle();
@ -657,7 +657,7 @@ class MergeIsolatesHeapsHandler : public MessageHandler {
ASSERT(response_array.Length() == 1);
ExternalTypedData& response = ExternalTypedData::Handle();
response ^= response_array.At(0);
msg_.reset(strdup(reinterpret_cast<char*>(response.DataAddr(0))));
msg_.reset(Utils::StrDup(reinterpret_cast<char*>(response.DataAddr(0))));
}
return kOK;

View File

@ -1508,11 +1508,11 @@ void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) {
embedder_entry_points_ = new Dart_QualifiedFunctionName[count + 1];
for (intptr_t i = 0; i < count; i++) {
embedder_entry_points_[i].library_uri =
strdup(api_flags.entry_points[i].library_uri);
Utils::StrDup(api_flags.entry_points[i].library_uri);
embedder_entry_points_[i].class_name =
strdup(api_flags.entry_points[i].class_name);
Utils::StrDup(api_flags.entry_points[i].class_name);
embedder_entry_points_[i].function_name =
strdup(api_flags.entry_points[i].function_name);
Utils::StrDup(api_flags.entry_points[i].function_name);
}
memset(&embedder_entry_points_[count], 0,
sizeof(Dart_QualifiedFunctionName));
@ -1830,7 +1830,7 @@ void Isolate::ScheduleInterrupts(uword interrupt_bits) {
void Isolate::set_name(const char* name) {
free(name_);
name_ = strdup(name);
name_ = Utils::StrDup(name);
}
int64_t IsolateGroup::UptimeMicros() const {
@ -1884,7 +1884,7 @@ void Isolate::BuildName(const char* name_prefix) {
if (name_prefix == nullptr) {
name_ = OS::SCreate(nullptr, "isolate-%" Pd64 "", main_port());
} else {
name_ = strdup(name_prefix);
name_ = Utils::StrDup(name_prefix);
}
}

View File

@ -192,7 +192,7 @@ class IsolateGroupSource {
intptr_t kernel_buffer_size,
Dart_IsolateFlags flags)
: script_uri(script_uri),
name(strdup(name)),
name(Utils::StrDup(name)),
snapshot_data(snapshot_data),
snapshot_instructions(snapshot_instructions),
kernel_buffer(kernel_buffer),

View File

@ -409,10 +409,10 @@ MallocGrowableArray<char*>* KernelIsolate::experimental_flags_ =
void KernelIsolate::AddExperimentalFlag(const char* value) {
char* save_ptr; // Needed for strtok_r.
char* temp = strdup(value);
char* temp = Utils::StrDup(value);
char* token = strtok_r(temp, ",", &save_ptr);
while (token != NULL) {
experimental_flags_->Add(strdup(token));
experimental_flags_->Add(Utils::StrDup(token));
token = strtok_r(NULL, ",", &save_ptr);
}
free(temp);
@ -928,7 +928,7 @@ class KernelCompilationRequest : public ValueObject {
}
// This is an error.
ASSERT(response[1]->type == Dart_CObject_kString);
result_.error = strdup(response[1]->value.as_string);
result_.error = Utils::StrDup(response[1]->value.as_string);
}
ml.Notify();
}
@ -1007,7 +1007,7 @@ Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
if (!Start()) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while starting Kernel isolate task");
result.error = Utils::StrDup("Error while starting Kernel isolate task");
return result;
}
@ -1017,7 +1017,7 @@ Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return result;
}
@ -1036,7 +1036,7 @@ bool KernelIsolate::DetectNullSafety(const char* script_uri,
if (!Start()) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while starting Kernel isolate task");
result.error = Utils::StrDup("Error while starting Kernel isolate task");
return false;
}
// Wait for Kernel isolate to finish initialization.
@ -1044,7 +1044,7 @@ bool KernelIsolate::DetectNullSafety(const char* script_uri,
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return false;
}
KernelCompilationRequest request;
@ -1060,7 +1060,7 @@ Dart_KernelCompilationResult KernelIsolate::ListDependencies() {
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return result;
}
@ -1077,7 +1077,7 @@ Dart_KernelCompilationResult KernelIsolate::AcceptCompilation() {
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return result;
}
@ -1098,7 +1098,7 @@ Dart_KernelCompilationResult KernelIsolate::CompileExpressionToKernel(
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return result;
}
@ -1119,7 +1119,7 @@ Dart_KernelCompilationResult KernelIsolate::UpdateInMemorySources(
if (kernel_port == ILLEGAL_PORT) {
Dart_KernelCompilationResult result = {};
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Error while initializing Kernel isolate");
result.error = Utils::StrDup("Error while initializing Kernel isolate");
return result;
}

View File

@ -9,7 +9,7 @@
namespace dart {
static uint8_t* AllocMsg(const char* str) {
return reinterpret_cast<uint8_t*>(strdup(str));
return reinterpret_cast<uint8_t*>(Utils::StrDup(str));
}
TEST_CASE(MessageQueue_BasicOperations) {

View File

@ -7,6 +7,7 @@
#include "include/dart_native_api.h"
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/dart_api_impl.h"
#include "vm/dart_api_message.h"
#include "vm/dart_api_state.h"
@ -141,7 +142,7 @@ DART_EXPORT bool Dart_InvokeVMServiceMethod(uint8_t* request_json,
::Dart_NewNativePort("service-rpc", &Utils::HandleResponse, false);
if (port == ILLEGAL_PORT) {
if (error != nullptr) {
*error = strdup("Was unable to create native port.");
*error = ::dart::Utils::StrDup("Was unable to create native port.");
}
return false;
}
@ -179,7 +180,7 @@ DART_EXPORT bool Dart_InvokeVMServiceMethod(uint8_t* request_json,
}
#else // !defined(PRODUCT)
if (error != nullptr) {
*error = strdup("VM Service is not supoorted in PRODUCT mode.");
*error = Utils::StrDup("VM Service is not supported in PRODUCT mode.");
}
return false;
#endif // !defined(PRODUCT)

View File

@ -4,6 +4,8 @@
#include "vm/native_message_handler.h"
#include <memory>
#include "vm/dart_api_message.h"
#include "vm/isolate.h"
#include "vm/message.h"
@ -13,7 +15,7 @@ namespace dart {
NativeMessageHandler::NativeMessageHandler(const char* name,
Dart_NativeMessageHandler func)
: name_(strdup(name)), func_(func) {}
: name_(Utils::StrDup(name)), func_(func) {}
NativeMessageHandler::~NativeMessageHandler() {
free(name_);

View File

@ -75,7 +75,7 @@ char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) {
if (start != NULL) {
*start = pc - displacement;
}
return strdup(pSymbol->Name);
return Utils::StrDup(pSymbol->Name);
}
void NativeSymbolResolver::FreeSymbolName(char* name) {

View File

@ -8,6 +8,7 @@
#include "platform/atomic.h"
#include "platform/globals.h"
#include "platform/safe_stack.h"
#include "platform/utils.h"
#include "vm/allocation.h"
#include "vm/globals.h"
@ -113,7 +114,7 @@ class OSThread : public BaseThread {
ASSERT(OSThread::Current() == this);
ASSERT(name_ == NULL);
ASSERT(name != NULL);
name_ = strdup(name);
name_ = Utils::StrDup(name);
}
Mutex* timeline_block_lock() const { return &timeline_block_lock_; }

View File

@ -134,7 +134,7 @@ TEST_CASE(PortMap_PostMessage) {
intptr_t message_len = strlen(message) + 1;
EXPECT(PortMap::PostMessage(
Message::New(port, reinterpret_cast<uint8_t*>(strdup(message)),
Message::New(port, reinterpret_cast<uint8_t*>(Utils::StrDup(message)),
message_len, nullptr, Message::kNormalPriority)));
// Check that the message notify callback was called.
@ -178,7 +178,7 @@ TEST_CASE(PortMap_PostMessageClosedPort) {
intptr_t message_len = strlen(message) + 1;
EXPECT(!PortMap::PostMessage(
Message::New(port, reinterpret_cast<uint8_t*>(strdup(message)),
Message::New(port, reinterpret_cast<uint8_t*>(Utils::StrDup(message)),
message_len, nullptr, Message::kNormalPriority)));
}

View File

@ -768,8 +768,9 @@ void IRRegExpMacroAssembler::CheckNotAtStart(intptr_t cp_offset,
auto neg_len_def =
Bind(InstanceCall(InstanceCallDescriptor::FromToken(Token::kNEGATE),
PushLocal(string_param_length_)));
auto offset_def =
Bind(Add(PushLocal(current_position_), Bind(Int64Constant(cp_offset))));
auto current_pos_def = PushLocal(current_position_);
auto cp_offset_def = Bind(Int64Constant(cp_offset));
auto offset_def = Bind(Add(current_pos_def, cp_offset_def));
BranchOrBacktrack(Comparison(kNE, neg_len_def, offset_def), on_not_at_start);
}

View File

@ -1201,7 +1201,7 @@ class EmbedderServiceHandler {
explicit EmbedderServiceHandler(const char* name)
: name_(NULL), callback_(NULL), user_data_(NULL), next_(NULL) {
ASSERT(name != NULL);
name_ = strdup(name);
name_ = Utils::StrDup(name);
}
~EmbedderServiceHandler() { free(name_); }
@ -4653,7 +4653,7 @@ static const MethodParameter* set_vm_name_params[] = {
static bool SetVMName(Thread* thread, JSONStream* js) {
const char* name_param = js->LookupParam("name");
free(vm_name);
vm_name = strdup(name_param);
vm_name = Utils::StrDup(name_param);
if (Service::vm_stream.enabled()) {
ServiceEvent event(NULL, ServiceEvent::kVMUpdate);
Service::HandleEvent(&event);

View File

@ -110,7 +110,7 @@ void ServiceIsolate::SetServerAddress(const char* address) {
if (address == NULL) {
return;
}
server_address_ = strdup(address);
server_address_ = Utils::StrDup(address);
}
bool ServiceIsolate::NameEquals(const char* name) {
@ -192,10 +192,10 @@ bool ServiceIsolate::SendServiceRpc(uint8_t* request_json,
"Service isolate failed to start up: %s.",
startup_failure_reason_);
} else {
*error = strdup("No service isolate port was found.");
*error = Utils::StrDup("No service isolate port was found.");
}
} else {
*error = strdup("Was unable to post message to service isolate.");
*error = Utils::StrDup("Was unable to post message to service isolate.");
}
}
@ -488,7 +488,7 @@ void ServiceIsolate::Run() {
create_group_callback_ = Isolate::CreateGroupCallback();
if (create_group_callback_ == NULL) {
ServiceIsolate::InitializingFailed(
strdup("The 'create_group' callback was not provided"));
Utils::StrDup("The 'create_group' callback was not provided"));
return;
}
bool task_started = Dart::thread_pool()->Run<RunServiceTask>();

View File

@ -55,7 +55,7 @@ class ServiceTestMessageHandler : public MessageHandler {
if (response_obj.IsString()) {
String& response = String::Handle();
response ^= response_obj.raw();
_msg = strdup(response.ToCString());
_msg = Utils::StrDup(response.ToCString());
} else {
ASSERT(response_obj.IsArray());
Array& response_array = Array::Handle();
@ -63,7 +63,7 @@ class ServiceTestMessageHandler : public MessageHandler {
ASSERT(response_array.Length() == 1);
ExternalTypedData& response = ExternalTypedData::Handle();
response ^= response_array.At(0);
_msg = strdup(reinterpret_cast<char*>(response.DataAddr(0)));
_msg = Utils::StrDup(reinterpret_cast<char*>(response.DataAddr(0)));
}
return kOK;
@ -567,7 +567,7 @@ static bool alpha_callback(const char* name,
intptr_t num_options,
void* user_data,
const char** result) {
*result = strdup("alpha");
*result = Utils::StrDup("alpha");
return true;
}
@ -577,7 +577,7 @@ static bool beta_callback(const char* name,
intptr_t num_options,
void* user_data,
const char** result) {
*result = strdup("beta");
*result = Utils::StrDup("beta");
return false;
}

View File

@ -166,10 +166,10 @@ static MallocGrowableArray<char*>* GetEnabledByDefaultTimelineStreams() {
}
char* save_ptr; // Needed for strtok_r.
// strtok modifies arg 1 so we make a copy of it.
char* streams = strdup(FLAG_timeline_streams);
char* streams = Utils::StrDup(FLAG_timeline_streams);
char* token = strtok_r(streams, ",", &save_ptr);
while (token != NULL) {
result->Add(strdup(token));
result->Add(Utils::StrDup(token));
token = strtok_r(NULL, ",", &save_ptr);
}
free(streams);
@ -347,7 +347,7 @@ void TimelineEventArguments::SetArgument(intptr_t i,
void TimelineEventArguments::CopyArgument(intptr_t i,
const char* name,
const char* argument) {
SetArgument(i, name, strdup(argument));
SetArgument(i, name, Utils::StrDup(argument));
}
void TimelineEventArguments::FormatArgument(intptr_t i,

View File

@ -119,12 +119,6 @@ def ParseStringMap(key, string_map):
return l[1]
return None
def DontUseClang(args, target_os, host_cpu, target_cpu):
# We don't have clang on Windows.
return target_os == 'win'
def UseSysroot(args, gn_args):
# Don't try to use a Linux sysroot if we aren't on Linux.
if gn_args['target_os'] != 'linux' and HOST_OS != 'linux':
@ -209,9 +203,7 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer):
gn_args['exclude_kernel_service'] = args.exclude_kernel_service
dont_use_clang = DontUseClang(args, gn_args['target_os'],
gn_args['host_cpu'], gn_args['target_cpu'])
gn_args['is_clang'] = args.clang and not dont_use_clang
gn_args['is_clang'] = args.clang
enable_code_coverage = args.code_coverage and gn_args['is_clang']
gn_args['dart_vm_code_coverage'] = enable_code_coverage