diff options
author | Lawrence D'Anna <lawrence_danna@apple.com> | 2020-05-08 10:56:30 -0700 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2020-05-08 10:57:10 -0700 |
commit | 52712d3ff7a2f7bcf737996d6ab59ef2cc29c20d (patch) | |
tree | cf0b823eed5f3fc69e1a11f43b028d29b5b20992 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | |
parent | ae920a81ffa3c7e3c14de131d0d55abd31bbff7d (diff) | |
download | llvm-52712d3ff7a2f7bcf737996d6ab59ef2cc29c20d.zip llvm-52712d3ff7a2f7bcf737996d6ab59ef2cc29c20d.tar.gz llvm-52712d3ff7a2f7bcf737996d6ab59ef2cc29c20d.tar.bz2 |
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
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index 1689680..ba127ea 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -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()) @@ -400,6 +397,10 @@ 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; |