Skip to content

Commit 14e3467

Browse files
emkornfieldpitrou
authored andcommitted
dont rely on rtti
1 parent cd22df6 commit 14e3467

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

cpp/src/arrow/python/common.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ MemoryPool* get_memory_pool() {
5151
// PythonErroDetail
5252
namespace {
5353

54+
const char kErrorDetailTypeId[] = "existing exception on python static status.";
5455
// PythonErrorDetail indicates a python exception was raised and not
5556
// reset in C++ code (i.e. it should be propagated up through the python
5657
// stack).
5758
class PythonErrorDetail : public StatusDetail {
5859
public:
5960
PythonErrorDetail() = default;
61+
const char* type_id() const override { return kErrorDetailTypeId; }
6062
std::string ToString() const override { return "Python Error."; }
6163
};
6264

@@ -157,8 +159,8 @@ bool IsPythonError(const Status& status) {
157159
if (status.ok()) {
158160
return false;
159161
}
160-
auto detail = dynamic_cast<PythonErrorDetail*>(status.detail().get());
161-
return detail != nullptr;
162+
auto detail = status.detail().get();
163+
return detail != nullptr && detail->type_id() == kErrorDetailTypeId;
162164
}
163165

164166
} // namespace py

cpp/src/arrow/status-test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace {
2727

2828
class TestStatusDetail : public StatusDetail {
2929
public:
30+
const char* type_id() const override { return "type_id"; }
3031
std::string ToString() const override { return "a specific detail message"; }
3132
};
3233

cpp/src/arrow/status.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class ARROW_MUST_USE_RESULT ARROW_EXPORT Status;
105105
class ARROW_EXPORT StatusDetail {
106106
public:
107107
virtual ~StatusDetail() = default;
108+
// Return a unique id for the type of the StatusDetail
109+
// (effectively a poor man's substitude for RTTI).
110+
virtual const char* type_id() const = 0;
108111
virtual std::string ToString() const = 0;
109112
};
110113

cpp/src/plasma/common.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ namespace plasma {
3030

3131
namespace {
3232

33+
const char kErrorDetailTypeId[] = "plasma status detail";
34+
3335
class PlasmaStatusDetail : public arrow::StatusDetail {
3436
public:
3537
explicit PlasmaStatusDetail(PlasmaErrorCode code) : code_(code) {}
36-
38+
const char* type_id() const override { return kErrorDetailTypeId; }
3739
std::string ToString() const override {
3840
const char* type;
3941
switch (code()) {
@@ -62,8 +64,9 @@ bool IsPlasmaStatus(const arrow::Status& status, PlasmaErrorCode code) {
6264
if (status.ok()) {
6365
return false;
6466
}
65-
auto* detail = dynamic_cast<PlasmaStatusDetail*>(status.detail().get());
66-
return detail != nullptr && detail->code() == code;
67+
auto* detail = status.detail().get();
68+
return detail != nullptr && detail->type_id() == kErrorDetailTypeId &&
69+
static_cast<PlasmaStatusDetail*>(detail)->code() == code;
6770
}
6871

6972
} // namespace

0 commit comments

Comments
 (0)