Re-land "get rid of PythonInteger::GetInteger()"

This was reverted due to a python2-specific bug.  Re-landing with a fix
for python2.

Summary:
One small step in my long running quest to improve python exception handling in
LLDB.  Replace GetInteger() which just returns an int with As<long long> and
friends, which return Expected types that can track python exceptions

Reviewers: labath, jasonmolenda, JDevlieghere, vadimcn, omjavaid

Reviewed By: labath, omjavaid

Subscribers: omjavaid, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D78462
This commit is contained in:
Lawrence D'Anna
2020-05-08 10:56:30 -07:00
parent ae920a81ff
commit 52712d3ff7
6 changed files with 149 additions and 127 deletions

View File

@@ -360,15 +360,12 @@ public:
return !!r;
}
llvm::Expected<long long> AsLongLong() {
if (!m_py_obj)
return nullDeref();
assert(!PyErr_Occurred());
long long r = PyLong_AsLongLong(m_py_obj);
if (PyErr_Occurred())
return exception();
return r;
}
llvm::Expected<long long> AsLongLong() const;
llvm::Expected<long long> AsUnsignedLongLong() const;
// wraps on overflow, instead of raising an error.
llvm::Expected<unsigned long long> AsModuloUnsignedLongLong() const;
llvm::Expected<bool> IsInstance(const PythonObject &cls) {
if (!m_py_obj || !cls.IsValid())
@@ -399,6 +396,10 @@ template <> llvm::Expected<bool> As<bool>(llvm::Expected<PythonObject> &&obj);
template <>
llvm::Expected<long long> As<long long>(llvm::Expected<PythonObject> &&obj);
template <>
llvm::Expected<unsigned long long>
As<unsigned long long>(llvm::Expected<PythonObject> &&obj);
template <>
llvm::Expected<std::string> As<std::string>(llvm::Expected<PythonObject> &&obj);
@@ -491,8 +492,6 @@ public:
static bool Check(PyObject *py_obj);
static void Convert(PyRefType &type, PyObject *&py_obj);
int64_t GetInteger() const;
void SetInteger(int64_t value);
StructuredData::IntegerSP CreateStructuredInteger() const;