From 7e858b83d3924498f56e74f6e23616e3e156f637 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 23 Dec 2024 15:40:56 +0800 Subject: [PATCH 1/2] GH-45099: [C++] Avoid static const variable in the status.h --- cpp/src/arrow/status.cc | 5 +++++ cpp/src/arrow/status.h | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/status.cc b/cpp/src/arrow/status.cc index 8cbc6842c4bc..7ad24781a642 100644 --- a/cpp/src/arrow/status.cc +++ b/cpp/src/arrow/status.cc @@ -141,6 +141,11 @@ std::string Status::ToStringWithoutContextLines() const { return message; } +const std::string& Status::message() const { + static const std::string no_message = ""; + return ok() ? no_message : state_->msg; +} + void Status::Abort() const { Abort(std::string()); } void Status::Abort(const std::string& message) const { diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h index 853fc284ee31..419174d83585 100644 --- a/cpp/src/arrow/status.h +++ b/cpp/src/arrow/status.h @@ -332,10 +332,7 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparablecode; } /// \brief Return the specific error message attached to this status. - const std::string& message() const { - static const std::string no_message = ""; - return ok() ? no_message : state_->msg; - } + const std::string& message() const; /// \brief Return the status detail attached to this message. const std::shared_ptr& detail() const { From 38d8edf505a959f2d7135f568714346d716e99a9 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 23 Dec 2024 16:08:04 +0800 Subject: [PATCH 2/2] fix detail --- cpp/src/arrow/status.cc | 5 +++++ cpp/src/arrow/status.h | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/status.cc b/cpp/src/arrow/status.cc index 7ad24781a642..55ce3fb78d25 100644 --- a/cpp/src/arrow/status.cc +++ b/cpp/src/arrow/status.cc @@ -146,6 +146,11 @@ const std::string& Status::message() const { return ok() ? no_message : state_->msg; } +const std::shared_ptr& Status::detail() const { + static std::shared_ptr no_detail = NULLPTR; + return state_ ? state_->detail : no_detail; +} + void Status::Abort() const { Abort(std::string()); } void Status::Abort(const std::string& message) const { diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h index 419174d83585..42e8929ce0b4 100644 --- a/cpp/src/arrow/status.h +++ b/cpp/src/arrow/status.h @@ -335,10 +335,7 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable& detail() const { - static std::shared_ptr no_detail = NULLPTR; - return state_ ? state_->detail : no_detail; - } + const std::shared_ptr& detail() const; /// \brief Return a new Status copying the existing status, but /// updating with the existing detail.