From f4b2c1f90f4281b9b40f1005683db10d856d9d65 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 20 Mar 2025 12:22:39 -0700 Subject: [PATCH 1/4] Return result from get_backend_name --- runtime/executor/method_meta.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/runtime/executor/method_meta.cpp b/runtime/executor/method_meta.cpp index 933670c526f..eb019f64e71 100644 --- a/runtime/executor/method_meta.cpp +++ b/runtime/executor/method_meta.cpp @@ -245,12 +245,15 @@ size_t MethodMeta::num_backends() const { return delegates ? delegates->size() : 0; } -const char* MethodMeta::get_backend_name(size_t index) const { - const auto delegates = s_plan_->delegates(); - if (delegates && index < delegates->size()) { - return delegates->Get(index)->id()->c_str(); - } - return nullptr; +Result MethodMeta::get_backend_name(size_t index) const { + const auto count = num_backends(); + ET_CHECK_OR_RETURN_ERROR( + index < count, + InvalidArgument, + "Index %zu out of range. num_backends: %zu", + index, + count); + return s_plan_->delegates()->Get(index)->id()->c_str(); } size_t MethodMeta::num_instructions() const { From eba49099cdc320164e6f189319198ebdd0825fa4 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 20 Mar 2025 12:24:05 -0700 Subject: [PATCH 2/4] Update method_meta.h --- runtime/executor/method_meta.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/executor/method_meta.h b/runtime/executor/method_meta.h index 9d38d133cbc..1d912642674 100644 --- a/runtime/executor/method_meta.h +++ b/runtime/executor/method_meta.h @@ -203,11 +203,11 @@ class MethodMeta final { /** * Get the backend name at the given index. * - * @param[in] index The index of the backend name. - * @returns The backend name as a C-style string, or nullptr if the index is - * invalid. + * @param index The index of the backend name. + * @returns A Result wrapping the backend name as a C-style string + * on success, or an error if the index is invalid. */ - const char* get_backend_name(size_t index) const; + Result get_backend_name(size_t index) const; /** * Get the number of instructions in this method. From 07f1095c6dd575854f3d03a0befd2c5ade202a9a Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 20 Mar 2025 12:26:10 -0700 Subject: [PATCH 3/4] Update backend_integration_test.cpp --- runtime/executor/test/backend_integration_test.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/runtime/executor/test/backend_integration_test.cpp b/runtime/executor/test/backend_integration_test.cpp index f9e3bb7b188..587c7b353eb 100644 --- a/runtime/executor/test/backend_integration_test.cpp +++ b/runtime/executor/test/backend_integration_test.cpp @@ -362,18 +362,20 @@ TEST_P(BackendIntegrationTest, GetBackendNamesSuccess) { EXPECT_TRUE(method_meta->uses_backend(StubBackend::kName)); // Retrieve the number of backends. - size_t num_backends = method_meta->num_backends(); + const size_t num_backends = method_meta->num_backends(); EXPECT_GT(num_backends, 0u); // Iterate through each backend and verify its name. for (size_t i = 0; i < num_backends; ++i) { - const char* name = method_meta->get_backend_name(i); - EXPECT_NE(name, nullptr); + auto backend_name_result = method_meta->get_backend_name(i); + ASSERT_TRUE(backend_name_result.ok()); + const char* name = backend_name_result.get(); // For this test, we expect that the only backend is StubBackend. EXPECT_STREQ(name, StubBackend::kName); } - // Check that an out-of-range index returns nullptr. - EXPECT_EQ(method_meta->get_backend_name(num_backends), nullptr); + // Check that an out-of-range index returns an error. + auto out_of_range_result = method_meta->get_backend_name(num_backends); + EXPECT_FALSE(out_of_range_result.ok()); } TEST_P(BackendIntegrationTest, FreeingProcessedBufferSucceeds) { From 8ccd36b63ad65b942ee5c55c951d878450b954d9 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 20 Mar 2025 12:49:46 -0700 Subject: [PATCH 4/4] Update method_meta.h --- runtime/executor/method_meta.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/executor/method_meta.h b/runtime/executor/method_meta.h index 1d912642674..d9bb64d68a7 100644 --- a/runtime/executor/method_meta.h +++ b/runtime/executor/method_meta.h @@ -203,7 +203,7 @@ class MethodMeta final { /** * Get the backend name at the given index. * - * @param index The index of the backend name. + * @param[in] index The index of the backend name. * @returns A Result wrapping the backend name as a C-style string * on success, or an error if the index is invalid. */