From 370ab6906a6e1c9cf1853acfba29c3acd1c71d7b Mon Sep 17 00:00:00 2001 From: Melvin Walls Date: Mon, 23 Jan 2023 21:02:29 -0800 Subject: [PATCH] [cpp] return managed Tuple from MakeDirCacheKey() mycpp generates code that uses pointers at the call sites for this function. --- cpp/core.cc | 4 ++-- cpp/core.h | 2 +- cpp/core_test.cc | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/core.cc b/cpp/core.cc index d37ce4dde7..1c01b9bba8 100644 --- a/cpp/core.cc +++ b/cpp/core.cc @@ -267,13 +267,13 @@ void InitShell() { gSignalHandler->signal_queue_ = AllocSignalQueue(); } -Tuple2 MakeDirCacheKey(Str* path) { +Tuple2* MakeDirCacheKey(Str* path) { struct stat st; if (::stat(path->data(), &st) == -1) { throw Alloc(errno); } - return Tuple2(path, st.st_mtime); + return Alloc>(path, st.st_mtime); } } // namespace pyos diff --git a/cpp/core.h b/cpp/core.h index bbb40eaf9b..f418b71a86 100644 --- a/cpp/core.h +++ b/cpp/core.h @@ -125,7 +125,7 @@ void SetSigwinchCode(int code); void InitShell(); -Tuple2 MakeDirCacheKey(Str* path); +Tuple2* MakeDirCacheKey(Str* path); } // namespace pyos diff --git a/cpp/core_test.cc b/cpp/core_test.cc index 9969f2c3f4..09378b125f 100644 --- a/cpp/core_test.cc +++ b/cpp/core_test.cc @@ -286,9 +286,9 @@ TEST dir_cache_key_test() { struct stat st; ASSERT(::stat("/", &st) == 0); - Tuple2 key = pyos::MakeDirCacheKey(StrFromC("/")); - ASSERT(str_equals(key.at0(), StrFromC("/"))); - ASSERT(key.at1() == st.st_mtime); + Tuple2* key = pyos::MakeDirCacheKey(StrFromC("/")); + ASSERT(str_equals(key->at0(), StrFromC("/"))); + ASSERT(key->at1() == st.st_mtime); int ec = -1; try {