diff --git a/DEPS b/DEPS index bc0ed5ea61a..70afd4c7228 100644 --- a/DEPS +++ b/DEPS @@ -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"), diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index e83f6140417..10a97c71be9 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -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") { diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index ee47c357d29..2db2871fdb2 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -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 += [ diff --git a/build/toolchain/win/BUILD.gn b/build/toolchain/win/BUILD.gn index a053de1eb15..16518a614f3 100644 --- a/build/toolchain/win/BUILD.gn +++ b/build/toolchain/win/BUILD.gn @@ -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 = [ diff --git a/runtime/bin/dart_embedder_api_impl.cc b/runtime/bin/dart_embedder_api_impl.cc index fd2c0e68752..ab0cbe09051 100644 --- a/runtime/bin/dart_embedder_api_impl.cc +++ b/runtime/bin/dart_embedder_api_impl.cc @@ -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; } diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index f1eeeb2a946..972a07b70cd 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -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); } diff --git a/runtime/bin/dfe.cc b/runtime/bin/dfe.cc index 45b625d9ac6..58718b7cf67 100644 --- a/runtime/bin/dfe.cc +++ b/runtime/bin/dfe.cc @@ -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)) { diff --git a/runtime/bin/dfe.h b/runtime/bin/dfe.h index 8bcaeafc5f7..c75b6ea9e54 100644 --- a/runtime/bin/dfe.h +++ b/runtime/bin/dfe.h @@ -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; } diff --git a/runtime/bin/directory.cc b/runtime/bin/directory.cc index cb6f8829054..4a5629e83d8 100644 --- a/runtime/bin/directory.cc +++ b/runtime/bin/directory.cc @@ -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); } } diff --git a/runtime/bin/exe_utils.cc b/runtime/bin/exe_utils.cc index 9950ae6fa0e..22f79864c3c 100644 --- a/runtime/bin/exe_utils.cc +++ b/runtime/bin/exe_utils.cc @@ -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 diff --git a/runtime/bin/extensions.cc b/runtime/bin/extensions.cc index b4ba1e700f0..b33896ca048 100644 --- a/runtime/bin/extensions.cc +++ b/runtime/bin/extensions.cc @@ -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); diff --git a/runtime/bin/extensions_win.cc b/runtime/bin/extensions_win.cc index d9fecd5ad22..23b4349cd3b 100644 --- a/runtime/bin/extensions_win.cc +++ b/runtime/bin/extensions_win.cc @@ -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(lib_handle), symbol); + return reinterpret_cast( + GetProcAddress(reinterpret_cast(lib_handle), symbol)); } void Extensions::UnloadLibrary(void* lib_handle) { diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc index 5ce4ae73765..58a9542eeae 100644 --- a/runtime/bin/file_win.cc +++ b/runtime/bin/file_win.cc @@ -11,6 +11,7 @@ #include // NOLINT #include // NOLINT #include // NOLINT +#undef StrDup // defined in Shlwapi.h as StrDupW #include // NOLINT #include // NOLINT #include // 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. diff --git a/runtime/bin/isolate_data.cc b/runtime/bin/isolate_data.cc index 154797507aa..1d62d32e118 100644 --- a/runtime/bin/isolate_data.cc +++ b/runtime/bin/isolate_data.cc @@ -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_); } } diff --git a/runtime/bin/isolate_data.h b/runtime/bin/isolate_data.h index 6dae87a3842..6daf547e67a 100644 --- a/runtime/bin/isolate_data.h +++ b/runtime/bin/isolate_data.h @@ -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. diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc index 6868012ca87..02002b39ea9 100644 --- a/runtime/bin/loader.cc +++ b/runtime/bin/loader.cc @@ -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); diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc index 00364a9bb44..d241e6931d7 100644 --- a/runtime/bin/main.cc +++ b/runtime/bin/main.cc @@ -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()) { diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index 1be5c6d6f70..93523930956 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -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(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 { diff --git a/runtime/bin/options.cc b/runtime/bin/options.cc index 573bd639867..1eed113d060 100644 --- a/runtime/bin/options.cc +++ b/runtime/bin/options.cc @@ -81,7 +81,7 @@ bool OptionProcessor::ProcessEnvironmentOption( name = reinterpret_cast(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), diff --git a/runtime/bin/platform.h b/runtime/bin/platform.h index 50b9a10b016..f7ac32c7c69 100644 --- a/runtime/bin/platform.h +++ b/runtime/bin/platform.h @@ -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_; diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc index c7b4df64f88..c2883596dd2 100644 --- a/runtime/bin/run_vm_tests.cc +++ b/runtime/bin/run_vm_tests.cc @@ -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); } diff --git a/runtime/bin/secure_socket_filter.cc b/runtime/bin/secure_socket_filter.cc index a713441fc55..cff4c4dd175 100644 --- a/runtime/bin/secure_socket_filter.cc +++ b/runtime/bin/secure_socket_filter.cc @@ -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); diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc index a733d906294..ac3814f190e 100644 --- a/runtime/bin/socket.cc +++ b/runtime/bin/socket.cc @@ -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; diff --git a/runtime/bin/socket_base_win.cc b/runtime/bin/socket_base_win.cc index f3a27562c6b..d762ad9d33d 100644 --- a/runtime/bin/socket_base_win.cc +++ b/runtime/bin/socket_base_win.cc @@ -65,7 +65,15 @@ bool SocketBase::FormatNumericAddress(const RawAddr& addr, socklen_t salen = SocketAddress::GetAddrLength(addr); DWORD l = len; RawAddr& raw = const_cast(addr); - return WSAAddressToStringA(&raw.addr, salen, NULL, address, &l) != 0; + wchar_t* waddress = reinterpret_cast( + 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) { diff --git a/runtime/bin/utils.h b/runtime/bin/utils.h index a5ec66bf041..5f5a1cca320 100644 --- a/runtime/bin/utils.h +++ b/runtime/bin/utils.h @@ -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); } } diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc index a3f4b002b88..0a1896a21c0 100644 --- a/runtime/bin/vmservice_impl.cc +++ b/runtime/bin/vmservice_impl.cc @@ -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; \ diff --git a/runtime/lib/ffi_dynamic_library.cc b/runtime/lib/ffi_dynamic_library.cc index e923b6ab8ae..ac11bd9d44c 100644 --- a/runtime/lib/ffi_dynamic_library.cc +++ b/runtime/lib/ffi_dynamic_library.cc @@ -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(handle), symbol); + void* pointer = reinterpret_cast( + GetProcAddress(reinterpret_cast(handle), symbol)); if (pointer == nullptr) { const int error = GetLastError(); const String& msg = String::Handle( diff --git a/runtime/platform/utils.h b/runtime/platform/utils.h index d69f2ee84bc..57bb31ae060 100644 --- a/runtime/platform/utils.h +++ b/runtime/platform/utils.h @@ -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'). diff --git a/runtime/platform/utils_android.cc b/runtime/platform/utils_android.cc index 21c2e026a0a..72618eb9ad1 100644 --- a/runtime/platform/utils_android.cc +++ b/runtime/platform/utils_android.cc @@ -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) diff --git a/runtime/platform/utils_fuchsia.cc b/runtime/platform/utils_fuchsia.cc index 22d280015b2..cfa17e6e555 100644 --- a/runtime/platform/utils_fuchsia.cc +++ b/runtime/platform/utils_fuchsia.cc @@ -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 context = sys::ComponentContext::CreateAndServeOutgoingDirectory(); diff --git a/runtime/platform/utils_linux.cc b/runtime/platform/utils_linux.cc index 4c3d617dcb9..c430bcac374 100644 --- a/runtime/platform/utils_linux.cc +++ b/runtime/platform/utils_linux.cc @@ -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) diff --git a/runtime/platform/utils_macos.cc b/runtime/platform/utils_macos.cc index 0c4762c8045..f0ccf53f994 100644 --- a/runtime/platform/utils_macos.cc +++ b/runtime/platform/utils_macos.cc @@ -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 diff --git a/runtime/platform/utils_win.cc b/runtime/platform/utils_win.cc index 84f277cb9cd..6cfe4e041c8 100644 --- a/runtime/platform/utils_win.cc +++ b/runtime/platform/utils_win.cc @@ -5,6 +5,7 @@ #include "platform/globals.h" #if defined(HOST_OS_WINDOWS) +#include // NOLINT #include "platform/utils.h" namespace dart { @@ -25,6 +26,10 @@ char* Utils::StrNDup(const char* s, intptr_t n) { return reinterpret_cast(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) diff --git a/runtime/vm/benchmark_test.cc b/runtime/vm/benchmark_test.cc index 31f68965370..633a3f2cbd1 100644 --- a/runtime/vm/benchmark_test.cc +++ b/runtime/vm/benchmark_test.cc @@ -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, diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index 4bd04c85ce3..c6261152e41 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -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) { diff --git a/runtime/vm/compiler/assembler/assembler_ia32.cc b/runtime/vm/compiler/assembler/assembler_ia32.cc index 798c2edf389..07af2efdea6 100644 --- a/runtime/vm/compiler/assembler/assembler_ia32.cc +++ b/runtime/vm/compiler/assembler/assembler_ia32.cc @@ -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(&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(&double_negate_constant))); } diff --git a/runtime/vm/cpuid.cc b/runtime/vm/cpuid.cc index ce6b13f2fb3..dddd15a9f13 100644 --- a/runtime/vm/cpuid.cc +++ b/runtime/vm/cpuid.cc @@ -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(); diff --git a/runtime/vm/cpuinfo.h b/runtime/vm/cpuinfo.h index 9257bb2c41b..bd900ffeec4 100644 --- a/runtime/vm/cpuinfo.h +++ b/runtime/vm/cpuinfo.h @@ -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"); } } diff --git a/runtime/vm/custom_isolate_test.cc b/runtime/vm/custom_isolate_test.cc index a9c024de640..21fbaec95f8 100644 --- a/runtime/vm/custom_isolate_test.cc +++ b/runtime/vm/custom_isolate_test.cc @@ -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(); diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index 31f297378ad..c7f2b50b5c0 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -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) { diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index 78930305403..f82a6badc06 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -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(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."); } diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index e329d2cf9d1..e20139fb39c 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -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; diff --git a/runtime/vm/flags.cc b/runtime/vm/flags.cc index 508a9ee1ec7..ee2708f525f 100644 --- a/runtime/vm/flags.cc +++ b/runtime/vm/flags.cc @@ -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); diff --git a/runtime/vm/heap/heap_test.cc b/runtime/vm/heap/heap_test.cc index 30bd4d4b6ad..cd2c0e86433 100644 --- a/runtime/vm/heap/heap_test.cc +++ b/runtime/vm/heap/heap_test.cc @@ -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(response.DataAddr(0)))); + msg_.reset(Utils::StrDup(reinterpret_cast(response.DataAddr(0)))); } return kOK; diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index a1e906e0ed7..eaa3b25d06a 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -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); } } diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h index d59d6fb6b2b..7eae97d0850 100644 --- a/runtime/vm/isolate.h +++ b/runtime/vm/isolate.h @@ -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), diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index 947d4688d0d..ae0b54a29a8 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -409,10 +409,10 @@ MallocGrowableArray* 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; } diff --git a/runtime/vm/message_test.cc b/runtime/vm/message_test.cc index f58082015b5..2c11a28119d 100644 --- a/runtime/vm/message_test.cc +++ b/runtime/vm/message_test.cc @@ -9,7 +9,7 @@ namespace dart { static uint8_t* AllocMsg(const char* str) { - return reinterpret_cast(strdup(str)); + return reinterpret_cast(Utils::StrDup(str)); } TEST_CASE(MessageQueue_BasicOperations) { diff --git a/runtime/vm/native_api_impl.cc b/runtime/vm/native_api_impl.cc index 75d9cd69da1..388d6cb98d2 100644 --- a/runtime/vm/native_api_impl.cc +++ b/runtime/vm/native_api_impl.cc @@ -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) diff --git a/runtime/vm/native_message_handler.cc b/runtime/vm/native_message_handler.cc index 009111c7543..65d97fd1bf8 100644 --- a/runtime/vm/native_message_handler.cc +++ b/runtime/vm/native_message_handler.cc @@ -4,6 +4,8 @@ #include "vm/native_message_handler.h" +#include + #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_); diff --git a/runtime/vm/native_symbol_win.cc b/runtime/vm/native_symbol_win.cc index a4f2f45fc89..0f2c0ce6984 100644 --- a/runtime/vm/native_symbol_win.cc +++ b/runtime/vm/native_symbol_win.cc @@ -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) { diff --git a/runtime/vm/os_thread.h b/runtime/vm/os_thread.h index c35d68f23d8..675836c13fd 100644 --- a/runtime/vm/os_thread.h +++ b/runtime/vm/os_thread.h @@ -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_; } diff --git a/runtime/vm/port_test.cc b/runtime/vm/port_test.cc index 2681b3a1809..2fb63d75af1 100644 --- a/runtime/vm/port_test.cc +++ b/runtime/vm/port_test.cc @@ -134,7 +134,7 @@ TEST_CASE(PortMap_PostMessage) { intptr_t message_len = strlen(message) + 1; EXPECT(PortMap::PostMessage( - Message::New(port, reinterpret_cast(strdup(message)), + Message::New(port, reinterpret_cast(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(strdup(message)), + Message::New(port, reinterpret_cast(Utils::StrDup(message)), message_len, nullptr, Message::kNormalPriority))); } diff --git a/runtime/vm/regexp_assembler_ir.cc b/runtime/vm/regexp_assembler_ir.cc index 116ff0c7e09..82347751caf 100644 --- a/runtime/vm/regexp_assembler_ir.cc +++ b/runtime/vm/regexp_assembler_ir.cc @@ -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); } diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index 0144fd8c784..9178c00de25 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -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); diff --git a/runtime/vm/service_isolate.cc b/runtime/vm/service_isolate.cc index 5b2aadfe9aa..f787fb3fd04 100644 --- a/runtime/vm/service_isolate.cc +++ b/runtime/vm/service_isolate.cc @@ -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(); diff --git a/runtime/vm/service_test.cc b/runtime/vm/service_test.cc index 152765e7920..9bec5e3d06f 100644 --- a/runtime/vm/service_test.cc +++ b/runtime/vm/service_test.cc @@ -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(response.DataAddr(0))); + _msg = Utils::StrDup(reinterpret_cast(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; } diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc index 94b0cf35c8c..5253189dad4 100644 --- a/runtime/vm/timeline.cc +++ b/runtime/vm/timeline.cc @@ -166,10 +166,10 @@ static MallocGrowableArray* 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, diff --git a/tools/gn.py b/tools/gn.py index 9607231c12d..830c8b3c64b 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -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