Skip to content

Commit

Permalink
dont rely on rtti
Browse files Browse the repository at this point in the history
  • Loading branch information
emkornfield authored and pitrou committed Jul 2, 2019
1 parent cd22df6 commit 14e3467
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cpp/src/arrow/python/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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."; }
};

Expand Down Expand Up @@ -157,8 +159,8 @@ bool IsPythonError(const Status& status) {
if (status.ok()) {
return false;
}
auto detail = dynamic_cast<PythonErrorDetail*>(status.detail().get());
return detail != nullptr;
auto detail = status.detail().get();
return detail != nullptr && detail->type_id() == kErrorDetailTypeId;
}

} // namespace py
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/status-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }
};

Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
9 changes: 6 additions & 3 deletions cpp/src/plasma/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -62,8 +64,9 @@ bool IsPlasmaStatus(const arrow::Status& status, PlasmaErrorCode code) {
if (status.ok()) {
return false;
}
auto* detail = dynamic_cast<PlasmaStatusDetail*>(status.detail().get());
return detail != nullptr && detail->code() == code;
auto* detail = status.detail().get();
return detail != nullptr && detail->type_id() == kErrorDetailTypeId &&
static_cast<PlasmaStatusDetail*>(detail)->code() == code;
}

} // namespace
Expand Down

0 comments on commit 14e3467

Please sign in to comment.