From 52712d3ff7a2f7bcf737996d6ab59ef2cc29c20d Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Fri, 8 May 2020 10:56:30 -0700 Subject: 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 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 --- .../ScriptInterpreter/Python/PythonDataObjects.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h') 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 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 AsLongLong() const; + + llvm::Expected AsUnsignedLongLong() const; + + // wraps on overflow, instead of raising an error. + llvm::Expected AsModuloUnsignedLongLong() const; llvm::Expected IsInstance(const PythonObject &cls) { if (!m_py_obj || !cls.IsValid()) @@ -400,6 +397,10 @@ template <> llvm::Expected As(llvm::Expected &&obj); template <> +llvm::Expected +As(llvm::Expected &&obj); + +template <> llvm::Expected As(llvm::Expected &&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; -- cgit v1.1