mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 17:15:39 +08:00
dont rely on rtti
This commit is contained in:
1 parent
cd22df64d6
commit
14e3467b5c
4 files changed
+14
-5
No files matched your search
@@ -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<PythonErrorDetail*>(status.detail().get());
|
||||
return detail != nullptr;
|
||||
auto detail = status.detail().get();
|
||||
return detail != nullptr && detail->type_id() == kErrorDetailTypeId;
|
||||
}
|
||||
|
||||
} // namespace py
|
||||
|
||||
@@ -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"; }
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<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
|
||||
|
||||
Reference in new issue
Block a user