[vm] Hoist CStringUniquePtr out of Utils, add CAllocUniquePtr` to simplify code
Hoist `CStringUniquePtr` out of the `Utils` class as there
is no reason it has to be nested inside a class - it just makes
code more verbose.
This simplifies code of the form
std::unique_ptr<T, decltype(std::free)> a = { nullptr, std::free };
to
CAllocUniquePtr<T> a;
TEST=ci
Change-Id: Ice42c1b16dfa5b20b321c13fbe5b28b3918581cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368425
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
committed by
Commit Queue
parent
a8dcef9173
commit
698bf0846b
@@ -79,8 +79,7 @@ bool DartDevIsolate::ShouldParseCommand(const char* script_uri) {
|
||||
(strncmp(script_uri, "google3://", 10) != 0)));
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(
|
||||
const char* filename) {
|
||||
CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(const char* filename) {
|
||||
// |dir_prefix| includes the last path separator.
|
||||
auto dir_prefix = EXEUtils::GetDirectoryPrefixFromExeName();
|
||||
|
||||
@@ -88,7 +87,7 @@ Utils::CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(
|
||||
char* snapshot_path =
|
||||
Utils::SCreate("%ssnapshots/%s", dir_prefix.get(), filename);
|
||||
if (File::Exists(nullptr, snapshot_path)) {
|
||||
return Utils::CreateCStringUniquePtr(snapshot_path);
|
||||
return CStringUniquePtr(snapshot_path);
|
||||
}
|
||||
free(snapshot_path);
|
||||
|
||||
@@ -96,13 +95,13 @@ Utils::CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(
|
||||
// directories. Try to use a snapshot from a previously built SDK.
|
||||
snapshot_path = Utils::SCreate("%s%s", dir_prefix.get(), filename);
|
||||
if (File::Exists(nullptr, snapshot_path)) {
|
||||
return Utils::CreateCStringUniquePtr(snapshot_path);
|
||||
return CStringUniquePtr(snapshot_path);
|
||||
}
|
||||
free(snapshot_path);
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr DartDevIsolate::TryResolveDartDevSnapshotPath() {
|
||||
CStringUniquePtr DartDevIsolate::TryResolveDartDevSnapshotPath() {
|
||||
return TryResolveArtifactPath("dartdev.dart.snapshot");
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class DartDevIsolate {
|
||||
static bool should_run_dart_dev() { return should_run_dart_dev_; }
|
||||
|
||||
// Attempts to find the path of the DartDev snapshot.
|
||||
static Utils::CStringUniquePtr TryResolveDartDevSnapshotPath();
|
||||
static CStringUniquePtr TryResolveDartDevSnapshotPath();
|
||||
|
||||
// Starts a DartDev instance in a new isolate and runs it to completion.
|
||||
//
|
||||
@@ -93,7 +93,7 @@ class DartDevIsolate {
|
||||
};
|
||||
|
||||
private:
|
||||
static Utils::CStringUniquePtr TryResolveArtifactPath(const char* filename);
|
||||
static CStringUniquePtr TryResolveArtifactPath(const char* filename);
|
||||
|
||||
static DartDevRunner runner_;
|
||||
static bool should_run_dart_dev_;
|
||||
|
||||
+2
-2
@@ -178,13 +178,13 @@ class KernelBlob {
|
||||
public:
|
||||
// Takes ownership over [uri] and [buffer].
|
||||
KernelBlob(char* uri, uint8_t* buffer, intptr_t size)
|
||||
: uri_(uri, std::free), buffer_(buffer, std::free), size_(size) {}
|
||||
: uri_(uri), buffer_(buffer, std::free), size_(size) {}
|
||||
|
||||
std::shared_ptr<uint8_t> buffer() { return buffer_; }
|
||||
intptr_t size() const { return size_; }
|
||||
|
||||
private:
|
||||
Utils::CStringUniquePtr uri_;
|
||||
CStringUniquePtr uri_;
|
||||
std::shared_ptr<uint8_t> buffer_;
|
||||
const intptr_t size_;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ static const char* GetFileNameFromPath(const char* path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
|
||||
CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
|
||||
const char* name = nullptr;
|
||||
const int kTargetSize = PATH_MAX;
|
||||
char target[kTargetSize];
|
||||
@@ -87,8 +87,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
|
||||
// cwd is currently wherever we launched from, so set the cwd to the
|
||||
// directory of the symlink while we try and resolve it. If we don't
|
||||
// do this, we won't be able to properly resolve relative paths.
|
||||
auto initial_dir_path =
|
||||
Utils::CreateCStringUniquePtr(Directory::CurrentNoScope());
|
||||
CStringUniquePtr initial_dir_path(Directory::CurrentNoScope());
|
||||
// We might run into symlinks of symlinks, so make sure we follow the
|
||||
// links all the way. See https://github.com/dart-lang/sdk/issues/41057 for
|
||||
// an example where this happens with brew on MacOS.
|
||||
@@ -98,7 +97,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
|
||||
name = File::LinkTarget(namespc, GetFileNameFromPath(name), target,
|
||||
kTargetSize);
|
||||
if (name == nullptr) {
|
||||
return Utils::CreateCStringUniquePtr(Utils::StrDup(""));
|
||||
return CStringUniquePtr(Utils::StrDup(""));
|
||||
}
|
||||
} while (File::GetType(namespc, name, false) == File::kIsLink);
|
||||
target_size = strlen(name);
|
||||
@@ -117,8 +116,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
|
||||
result = GetDirectoryFromPath(target, nullptr);
|
||||
}
|
||||
namespc->Release();
|
||||
return Utils::CreateCStringUniquePtr(result == nullptr ? Utils::StrDup("")
|
||||
: result);
|
||||
return CStringUniquePtr(result == nullptr ? Utils::StrDup("") : result);
|
||||
}
|
||||
|
||||
#if !defined(DART_HOST_OS_WINDOWS)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace bin {
|
||||
class EXEUtils {
|
||||
public:
|
||||
// Returns the path to the directory the current executable resides in.
|
||||
static Utils::CStringUniquePtr GetDirectoryPrefixFromExeName();
|
||||
static CStringUniquePtr GetDirectoryPrefixFromExeName();
|
||||
|
||||
#if !defined(DART_HOST_OS_WINDOWS)
|
||||
// Loads a compact symbolization table from "$exepath.sym" that is used by the
|
||||
|
||||
+1
-1
@@ -230,7 +230,7 @@ class File : public ReferenceCounted<File> {
|
||||
static File* OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode);
|
||||
|
||||
// Attempts to convert the given [uri] to a file path.
|
||||
static Utils::CStringUniquePtr UriToPath(const char* uri);
|
||||
static CStringUniquePtr UriToPath(const char* uri);
|
||||
|
||||
// Create a file object for the specified stdio file descriptor
|
||||
// (stdin, stout or stderr).
|
||||
|
||||
@@ -253,15 +253,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
|
||||
return OpenFD(fd);
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
const char* path =
|
||||
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
|
||||
UriDecoder uri_decoder(path);
|
||||
if (uri_decoder.decoded() == nullptr) {
|
||||
errno = EINVAL;
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
return CStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
}
|
||||
|
||||
File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
|
||||
|
||||
@@ -265,15 +265,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
|
||||
return OpenFD(fd);
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
const char* path =
|
||||
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
|
||||
UriDecoder uri_decoder(path);
|
||||
if (uri_decoder.decoded() == nullptr) {
|
||||
errno = EINVAL;
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
return CStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
}
|
||||
|
||||
File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
|
||||
|
||||
@@ -296,15 +296,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
|
||||
return new File(new FileHandle(fd));
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
const char* path =
|
||||
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
|
||||
UriDecoder uri_decoder(path);
|
||||
if (uri_decoder.decoded() == nullptr) {
|
||||
errno = EINVAL;
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
return CStringUniquePtr(strdup(uri_decoder.decoded()));
|
||||
}
|
||||
|
||||
File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
|
||||
|
||||
@@ -447,23 +447,23 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
|
||||
return file;
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
CStringUniquePtr File::UriToPath(const char* uri) {
|
||||
UriDecoder uri_decoder(uri);
|
||||
if (uri_decoder.decoded() == nullptr) {
|
||||
SetLastError(ERROR_INVALID_NAME);
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
|
||||
const auto uri_w = Utf8ToWideChar(uri_decoder.decoded());
|
||||
if (!UrlIsFileUrlW(uri_w.get())) {
|
||||
return Utils::CreateCStringUniquePtr(Utils::StrDup(uri_decoder.decoded()));
|
||||
return CStringUniquePtr(Utils::StrDup(uri_decoder.decoded()));
|
||||
}
|
||||
wchar_t filename_w[MAX_PATH];
|
||||
DWORD filename_len = MAX_PATH;
|
||||
HRESULT result = PathCreateFromUrlW(uri_w.get(), filename_w, &filename_len,
|
||||
/* dwFlags= */ 0);
|
||||
if (result != S_OK) {
|
||||
return Utils::CreateCStringUniquePtr(nullptr);
|
||||
return CStringUniquePtr(nullptr);
|
||||
}
|
||||
|
||||
WideToUtf8Scope utf8_path(filename_w);
|
||||
|
||||
@@ -588,7 +588,7 @@ bool Snapshot::IsPEFormattedBinary(const char* filename) {
|
||||
AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
|
||||
bool force_load_elf_from_memory,
|
||||
bool decode_uri) {
|
||||
Utils::CStringUniquePtr decoded_path(nullptr, std::free);
|
||||
CStringUniquePtr decoded_path(nullptr);
|
||||
const char* script_name = nullptr;
|
||||
if (decode_uri) {
|
||||
decoded_path = File::UriToPath(script_uri);
|
||||
@@ -636,8 +636,7 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
|
||||
#if defined(DART_TARGET_OS_LINUX) || defined(DART_TARGET_OS_MACOS)
|
||||
// On Linux and OSX, resolve the script path before passing into dlopen()
|
||||
// since dlopen will not search the filesystem for paths like 'libtest.so'.
|
||||
std::unique_ptr<char, decltype(std::free)*> absolute_path{
|
||||
realpath(script_name, nullptr), std::free};
|
||||
CStringUniquePtr absolute_path(realpath(script_name, nullptr));
|
||||
script_name = absolute_path.get();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -53,24 +53,24 @@ class StringUtilsWin {
|
||||
class WideToUtf8Scope {
|
||||
public:
|
||||
explicit WideToUtf8Scope(const wchar_t* wide)
|
||||
: utf8_(Utils::CreateCStringUniquePtr(nullptr)) {
|
||||
: utf8_(CStringUniquePtr(nullptr)) {
|
||||
intptr_t utf8_len =
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
|
||||
char* utf8 = reinterpret_cast<char*>(malloc(utf8_len));
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, nullptr, nullptr);
|
||||
length_ = utf8_len;
|
||||
utf8_ = Utils::CreateCStringUniquePtr(utf8);
|
||||
utf8_.reset(utf8);
|
||||
}
|
||||
|
||||
char* utf8() const { return utf8_.get(); }
|
||||
intptr_t length() const { return length_; }
|
||||
|
||||
// Release the ownership of the converted string and return it.
|
||||
Utils::CStringUniquePtr release() { return std::move(utf8_); }
|
||||
CStringUniquePtr release() { return std::move(utf8_); }
|
||||
|
||||
private:
|
||||
intptr_t length_;
|
||||
Utils::CStringUniquePtr utf8_;
|
||||
CStringUniquePtr utf8_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(WideToUtf8Scope);
|
||||
|
||||
@@ -254,10 +254,6 @@ char* Utils::VSCreate(const char* format, va_list args) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Utils::CStringUniquePtr Utils::CreateCStringUniquePtr(char* str) {
|
||||
return std::unique_ptr<char, decltype(std::free)*>{str, std::free};
|
||||
}
|
||||
|
||||
static void GetLastErrorAsString(char** error) {
|
||||
if (error == nullptr) return; // Nothing to do.
|
||||
|
||||
|
||||
@@ -15,6 +15,17 @@
|
||||
|
||||
namespace dart {
|
||||
|
||||
template <typename T>
|
||||
class CAllocUniquePtr : public std::unique_ptr<T, decltype(std::free)*> {
|
||||
public:
|
||||
CAllocUniquePtr()
|
||||
: std::unique_ptr<T, decltype(std::free)*>(nullptr, std::free) {}
|
||||
explicit CAllocUniquePtr(T* value)
|
||||
: std::unique_ptr<T, decltype(std::free)*>(value, std::free) {}
|
||||
};
|
||||
|
||||
using CStringUniquePtr = CAllocUniquePtr<char>;
|
||||
|
||||
class Utils {
|
||||
public:
|
||||
template <typename T>
|
||||
@@ -641,11 +652,6 @@ class Utils {
|
||||
static char* SCreate(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
|
||||
static char* VSCreate(const char* format, va_list args);
|
||||
|
||||
typedef std::unique_ptr<char, decltype(std::free)*> CStringUniquePtr;
|
||||
|
||||
// Returns str in a unique_ptr with free used as its deleter.
|
||||
static CStringUniquePtr CreateCStringUniquePtr(char* str);
|
||||
|
||||
// Load dynamic library from the given |library_path| and return the
|
||||
// library handle. |library_path| can be |nullptr| in which case
|
||||
// library handle representing the executable is returned.
|
||||
|
||||
@@ -764,7 +764,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_LoadThread) {
|
||||
#if !defined(TARGET_ARCH_IA32)
|
||||
ISOLATE_UNIT_TEST_CASE(IRTest_CachableIdempotentCall) {
|
||||
// clang-format off
|
||||
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
|
||||
int globalCounter = 0;
|
||||
|
||||
int increment() => ++globalCounter;
|
||||
@@ -785,7 +785,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_CachableIdempotentCall) {
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
)"), std::free);
|
||||
)"));
|
||||
// clang-format on
|
||||
|
||||
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
|
||||
|
||||
@@ -154,7 +154,7 @@ static void RunMemoryCopyInstrTest(intptr_t src_start,
|
||||
OS::Print("&ptr %p &ptr2 %p\n", ptr, ptr2);
|
||||
|
||||
// clang-format off
|
||||
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
|
||||
import 'dart:ffi';
|
||||
|
||||
void copyConst() {
|
||||
@@ -182,7 +182,7 @@ static void RunMemoryCopyInstrTest(intptr_t src_start,
|
||||
int length) {}
|
||||
)", pointer_prefix, ptr, pointer_prefix, ptr2,
|
||||
pointer_prefix, ptr, pointer_prefix, ptr2,
|
||||
src_start, dest_start, length), std::free);
|
||||
src_start, dest_start, length));
|
||||
// clang-format on
|
||||
|
||||
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
|
||||
|
||||
@@ -1740,8 +1740,7 @@ ISOLATE_UNIT_TEST_CASE(AllocationSinking_NoViewDataMaterialization) {
|
||||
auto* const kFunctionName = "unalignedUint16";
|
||||
auto* const kInvokeNoDeoptName = "no_deopt";
|
||||
auto* const kInvokeDeoptName = "deopt";
|
||||
auto kScript = Utils::CStringUniquePtr(
|
||||
OS::SCreate(nullptr, R"(
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
|
||||
import 'dart:_internal';
|
||||
import 'dart:typed_data';
|
||||
|
||||
@@ -1779,9 +1778,9 @@ ISOLATE_UNIT_TEST_CASE(AllocationSinking_NoViewDataMaterialization) {
|
||||
return %s(1.0);
|
||||
}
|
||||
)",
|
||||
kFunctionName, kInvokeNoDeoptName, kFunctionName,
|
||||
kInvokeDeoptName, kFunctionName),
|
||||
std::free);
|
||||
kFunctionName, kInvokeNoDeoptName,
|
||||
kFunctionName, kInvokeDeoptName,
|
||||
kFunctionName));
|
||||
|
||||
const auto& lib =
|
||||
Library::Handle(LoadTestScript(kScript.get(), NoopNativeLookup));
|
||||
@@ -1962,9 +1961,8 @@ ISOLATE_UNIT_TEST_CASE(AllocationSinking_NoViewDataMaterialization) {
|
||||
// Verifies that deoptimization at the hoisted BinarySmiOp
|
||||
// doesn't result in the infinite re-optimization loop.
|
||||
ISOLATE_UNIT_TEST_CASE(LICM_Deopt_Regress51220) {
|
||||
auto kScript =
|
||||
Utils::CStringUniquePtr(OS::SCreate(nullptr,
|
||||
R"(
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr,
|
||||
R"(
|
||||
int n = int.parse('3');
|
||||
main() {
|
||||
int x = 0;
|
||||
@@ -1976,8 +1974,7 @@ ISOLATE_UNIT_TEST_CASE(LICM_Deopt_Regress51220) {
|
||||
return x;
|
||||
}
|
||||
)",
|
||||
static_cast<int>(kSmiBits + 1 - 10)),
|
||||
std::free);
|
||||
static_cast<int>(kSmiBits + 1 - 10)));
|
||||
|
||||
const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
|
||||
const auto& function = Function::Handle(GetFunction(root_library, "main"));
|
||||
|
||||
@@ -140,8 +140,7 @@ static void TestWBEForArrays(int length) {
|
||||
// may-trigger-GC instruction (in this case CheckStackOverflow) iff they
|
||||
// are small.
|
||||
// clang-format off
|
||||
auto kScript =
|
||||
Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
|
||||
class C {
|
||||
late C next;
|
||||
}
|
||||
@@ -164,7 +163,7 @@ static void TestWBEForArrays(int length) {
|
||||
}
|
||||
|
||||
main() { foo(10); }
|
||||
)", length), std::free);
|
||||
)", length));
|
||||
// clang-format on
|
||||
|
||||
// Generate a length dependent test library uri.
|
||||
|
||||
@@ -10248,36 +10248,31 @@ TEST_CASE(DartAPI_UserTags) {
|
||||
Dart_Handle default_tag = Dart_GetDefaultUserTag();
|
||||
EXPECT_VALID(default_tag);
|
||||
|
||||
auto default_label =
|
||||
Utils::CStringUniquePtr(Dart_GetUserTagLabel(default_tag), std::free);
|
||||
CStringUniquePtr default_label(Dart_GetUserTagLabel(default_tag));
|
||||
EXPECT_STREQ(default_label.get(), "Default");
|
||||
|
||||
Dart_Handle current_tag = Dart_GetCurrentUserTag();
|
||||
EXPECT(Dart_IdentityEquals(default_tag, current_tag));
|
||||
|
||||
auto current_label =
|
||||
Utils::CStringUniquePtr(Dart_GetUserTagLabel(current_tag), std::free);
|
||||
CStringUniquePtr current_label(Dart_GetUserTagLabel(current_tag));
|
||||
EXPECT_STREQ(default_label.get(), current_label.get());
|
||||
|
||||
Dart_Handle new_tag = Dart_NewUserTag("Foo");
|
||||
EXPECT_VALID(new_tag);
|
||||
|
||||
auto new_tag_label =
|
||||
Utils::CStringUniquePtr(Dart_GetUserTagLabel(new_tag), std::free);
|
||||
CStringUniquePtr new_tag_label(Dart_GetUserTagLabel(new_tag));
|
||||
EXPECT_STREQ(new_tag_label.get(), "Foo");
|
||||
|
||||
Dart_Handle old_tag = Dart_SetCurrentUserTag(new_tag);
|
||||
EXPECT_VALID(old_tag);
|
||||
|
||||
auto old_label =
|
||||
Utils::CStringUniquePtr(Dart_GetUserTagLabel(old_tag), std::free);
|
||||
CStringUniquePtr old_label(Dart_GetUserTagLabel(old_tag));
|
||||
EXPECT_STREQ(old_label.get(), default_label.get());
|
||||
|
||||
current_tag = Dart_GetCurrentUserTag();
|
||||
EXPECT(Dart_IdentityEquals(new_tag, current_tag));
|
||||
|
||||
current_label =
|
||||
Utils::CStringUniquePtr(Dart_GetUserTagLabel(current_tag), std::free);
|
||||
current_label.reset(Dart_GetUserTagLabel(current_tag));
|
||||
EXPECT_STREQ(current_label.get(), new_tag_label.get());
|
||||
|
||||
EXPECT(Dart_GetUserTagLabel(Dart_Null()) == nullptr);
|
||||
|
||||
+1
-2
@@ -172,8 +172,7 @@ class Flag {
|
||||
|
||||
// For kString, kOptionHandler, kFlagHandler flags this stores the copy
|
||||
// of the original flag value passed to SetFlagFromString
|
||||
Utils::CStringUniquePtr string_value_ =
|
||||
Utils::CreateCStringUniquePtr(nullptr);
|
||||
CStringUniquePtr string_value_;
|
||||
union {
|
||||
void* addr_;
|
||||
bool* bool_ptr_;
|
||||
|
||||
@@ -486,7 +486,7 @@ class HeapTestHelper {
|
||||
class SendAndExitMessagesHandler : public MessageHandler {
|
||||
public:
|
||||
explicit SendAndExitMessagesHandler(Isolate* owner)
|
||||
: msg_(Utils::CreateCStringUniquePtr(nullptr)), owner_(owner) {}
|
||||
: msg_(CStringUniquePtr(nullptr)), owner_(owner) {}
|
||||
|
||||
const char* name() const { return "merge-isolates-heaps-handler"; }
|
||||
|
||||
@@ -530,7 +530,7 @@ class SendAndExitMessagesHandler : public MessageHandler {
|
||||
virtual Isolate* isolate() const { return owner_; }
|
||||
|
||||
private:
|
||||
Utils::CStringUniquePtr msg_;
|
||||
CStringUniquePtr msg_;
|
||||
Isolate* owner_;
|
||||
};
|
||||
|
||||
|
||||
@@ -5410,7 +5410,7 @@ static void TestReloadWithFieldChange(const char* prefix,
|
||||
const char* to_type,
|
||||
const char* to_init) {
|
||||
// clang-format off
|
||||
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr,
|
||||
CStringUniquePtr kScript(OS::SCreate(nullptr,
|
||||
R"(
|
||||
import 'dart:typed_data';
|
||||
|
||||
@@ -5438,7 +5438,7 @@ static void TestReloadWithFieldChange(const char* prefix,
|
||||
from_type,
|
||||
from_init,
|
||||
suffix,
|
||||
verify), std::free);
|
||||
verify));
|
||||
// clang-format on
|
||||
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScript.get(), nullptr);
|
||||
@@ -5446,7 +5446,7 @@ static void TestReloadWithFieldChange(const char* prefix,
|
||||
EXPECT_STREQ("Okay", SimpleInvokeStr(lib, "main"));
|
||||
|
||||
// clang-format off
|
||||
auto kReloadScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
|
||||
CStringUniquePtr kReloadScript(OS::SCreate(nullptr, R"(
|
||||
import 'dart:typed_data';
|
||||
|
||||
void doubleEq(double got, double expected) {
|
||||
@@ -5472,7 +5472,7 @@ static void TestReloadWithFieldChange(const char* prefix,
|
||||
}
|
||||
}
|
||||
)", prefix, to_type, to_init, suffix,
|
||||
verify), std::free);
|
||||
verify));
|
||||
// clang-format on
|
||||
|
||||
lib = TestCase::ReloadTestScript(kReloadScript.get());
|
||||
|
||||
@@ -17855,7 +17855,7 @@ class MallocCodeComments final : public CodeComments {
|
||||
for (intptr_t i = 0; i < length_; i++) {
|
||||
comments_[i].pc_offset = comments.PCOffsetAt(i);
|
||||
comments_[i].comment =
|
||||
Utils::CreateCStringUniquePtr(Utils::StrDup(comments.CommentAt(i)));
|
||||
CStringUniquePtr(Utils::StrDup(comments.CommentAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17872,7 +17872,7 @@ class MallocCodeComments final : public CodeComments {
|
||||
private:
|
||||
struct Comment {
|
||||
intptr_t pc_offset;
|
||||
Utils::CStringUniquePtr comment{nullptr, std::free};
|
||||
CStringUniquePtr comment;
|
||||
};
|
||||
|
||||
intptr_t length_;
|
||||
|
||||
@@ -6445,7 +6445,7 @@ static bool HashCodeEqualsCanonicalizeHash(
|
||||
uint32_t hashcode_canonicalize_vm = kCalculateCanonicalizeHash,
|
||||
bool check_identity = true,
|
||||
bool check_hashcode = true) {
|
||||
auto kScriptChars = Utils::CStringUniquePtr(
|
||||
CStringUniquePtr kScriptChars(
|
||||
OS::SCreate(nullptr,
|
||||
"%s"
|
||||
"\n"
|
||||
@@ -6456,8 +6456,7 @@ static bool HashCodeEqualsCanonicalizeHash(
|
||||
"valueIdentityHashCode() {\n"
|
||||
" return identityHashCode(value());\n"
|
||||
"}\n",
|
||||
value_script),
|
||||
std::free);
|
||||
value_script));
|
||||
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars.get(), nullptr);
|
||||
EXPECT_VALID(lib);
|
||||
|
||||
@@ -1000,14 +1000,12 @@ std::unique_ptr<const char[]> TimelineEvent::GetFormattedIsolateGroupId()
|
||||
return formatted_isolate_group_id;
|
||||
}
|
||||
|
||||
TimelineTrackMetadata::TimelineTrackMetadata(
|
||||
intptr_t pid,
|
||||
intptr_t tid,
|
||||
Utils::CStringUniquePtr&& track_name)
|
||||
TimelineTrackMetadata::TimelineTrackMetadata(intptr_t pid,
|
||||
intptr_t tid,
|
||||
CStringUniquePtr&& track_name)
|
||||
: pid_(pid), tid_(tid), track_name_(std::move(track_name)) {}
|
||||
|
||||
void TimelineTrackMetadata::set_track_name(
|
||||
Utils::CStringUniquePtr&& track_name) {
|
||||
void TimelineTrackMetadata::set_track_name(CStringUniquePtr&& track_name) {
|
||||
track_name_ = std::move(track_name);
|
||||
}
|
||||
|
||||
@@ -1540,13 +1538,13 @@ void TimelineEventRecorder::AddTrackMetadataBasedOnThread(
|
||||
if (entry->value == nullptr) {
|
||||
entry->value = new TimelineTrackMetadata(
|
||||
process_id, trace_id,
|
||||
Utils::CreateCStringUniquePtr(
|
||||
CStringUniquePtr(
|
||||
Utils::StrDup(thread_name == nullptr ? "" : thread_name)));
|
||||
} else {
|
||||
TimelineTrackMetadata* value =
|
||||
static_cast<TimelineTrackMetadata*>(entry->value);
|
||||
ASSERT(process_id == value->pid());
|
||||
value->set_track_name(Utils::CreateCStringUniquePtr(
|
||||
value->set_track_name(CStringUniquePtr(
|
||||
Utils::StrDup(thread_name == nullptr ? "" : thread_name)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,11 +638,11 @@ class TimelineTrackMetadata {
|
||||
public:
|
||||
TimelineTrackMetadata(intptr_t pid,
|
||||
intptr_t tid,
|
||||
Utils::CStringUniquePtr&& track_name);
|
||||
CStringUniquePtr&& track_name);
|
||||
intptr_t pid() const { return pid_; }
|
||||
intptr_t tid() const { return tid_; }
|
||||
const char* track_name() const { return track_name_.get(); }
|
||||
inline void set_track_name(Utils::CStringUniquePtr&& track_name);
|
||||
inline void set_track_name(CStringUniquePtr&& track_name);
|
||||
#if !defined(PRODUCT)
|
||||
/*
|
||||
* Prints a Chrome-format event representing the metadata stored by this
|
||||
@@ -665,7 +665,7 @@ class TimelineTrackMetadata {
|
||||
// The trace ID of the thread that this track is associated with.
|
||||
intptr_t tid_;
|
||||
// The name of this track.
|
||||
Utils::CStringUniquePtr track_name_;
|
||||
CStringUniquePtr track_name_;
|
||||
};
|
||||
|
||||
class AsyncTimelineTrackMetadata {
|
||||
|
||||
Reference in New Issue
Block a user