From 14e3467b5ca0ba4235b0febd9ef13e421ab3ca72 Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Sat, 22 Jun 2019 03:14:20 -0700 Subject: [PATCH] dont rely on rtti --- cpp/src/arrow/python/common.cc | 6 ++++-- cpp/src/arrow/status-test.cc | 1 + cpp/src/arrow/status.h | 3 +++ cpp/src/plasma/common.cc | 9 ++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/python/common.cc b/cpp/src/arrow/python/common.cc index 5a6cf54f69ab3..ad7864697e5f2 100644 --- a/cpp/src/arrow/python/common.cc +++ b/cpp/src/arrow/python/common.cc @@ -51,12 +51,14 @@ MemoryPool* get_memory_pool() { // PythonErroDetail namespace { +const char kErrorDetailTypeId[] = "existing exception on python static status."; // PythonErrorDetail indicates a python exception was raised and not // reset in C++ code (i.e. it should be propagated up through the python // stack). class PythonErrorDetail : public StatusDetail { public: PythonErrorDetail() = default; + const char* type_id() const override { return kErrorDetailTypeId; } std::string ToString() const override { return "Python Error."; } }; @@ -157,8 +159,8 @@ bool IsPythonError(const Status& status) { if (status.ok()) { return false; } - auto detail = dynamic_cast(status.detail().get()); - return detail != nullptr; + auto detail = status.detail().get(); + return detail != nullptr && detail->type_id() == kErrorDetailTypeId; } } // namespace py diff --git a/cpp/src/arrow/status-test.cc b/cpp/src/arrow/status-test.cc index eb8ad93ddde40..b151e462b2803 100644 --- a/cpp/src/arrow/status-test.cc +++ b/cpp/src/arrow/status-test.cc @@ -27,6 +27,7 @@ namespace { class TestStatusDetail : public StatusDetail { public: + const char* type_id() const override { return "type_id"; } std::string ToString() const override { return "a specific detail message"; } }; diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h index 46c329a6b71b2..7cafc41902df2 100644 --- a/cpp/src/arrow/status.h +++ b/cpp/src/arrow/status.h @@ -105,6 +105,9 @@ class ARROW_MUST_USE_RESULT ARROW_EXPORT Status; class ARROW_EXPORT StatusDetail { public: virtual ~StatusDetail() = default; + // Return a unique id for the type of the StatusDetail + // (effectively a poor man's substitude for RTTI). + virtual const char* type_id() const = 0; virtual std::string ToString() const = 0; }; diff --git a/cpp/src/plasma/common.cc b/cpp/src/plasma/common.cc index 32cd05a5a8def..84a1601952e80 100644 --- a/cpp/src/plasma/common.cc +++ b/cpp/src/plasma/common.cc @@ -30,10 +30,12 @@ namespace plasma { namespace { +const char kErrorDetailTypeId[] = "plasma status detail"; + class PlasmaStatusDetail : public arrow::StatusDetail { public: explicit PlasmaStatusDetail(PlasmaErrorCode code) : code_(code) {} - + const char* type_id() const override { return kErrorDetailTypeId; } std::string ToString() const override { const char* type; switch (code()) { @@ -62,8 +64,9 @@ bool IsPlasmaStatus(const arrow::Status& status, PlasmaErrorCode code) { if (status.ok()) { return false; } - auto* detail = dynamic_cast(status.detail().get()); - return detail != nullptr && detail->code() == code; + auto* detail = status.detail().get(); + return detail != nullptr && detail->type_id() == kErrorDetailTypeId && + static_cast(detail)->code() == code; } } // namespace