From 7375212172951d2fc283c81d03c1a8588c3280c6 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Tue, 21 Apr 2020 16:53:47 -0700 Subject: get rid of PythonInteger::GetInteger() 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 Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D78462 --- .../ScriptInterpreter/Python/PythonDataObjects.h | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 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..b09f42e 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -370,6 +370,27 @@ public: return r; } + llvm::Expected AsUnsignedLongLong() { + if (!m_py_obj) + return nullDeref(); + assert(!PyErr_Occurred()); + long long r = PyLong_AsUnsignedLongLong(m_py_obj); + if (PyErr_Occurred()) + return exception(); + return r; + } + + llvm::Expected AsModuloUnsignedLongLong() const { + // wraps on overflow, instead of raising an error. + if (!m_py_obj) + return nullDeref(); + assert(!PyErr_Occurred()); + unsigned long long r = PyLong_AsUnsignedLongLongMask(m_py_obj); + if (PyErr_Occurred()) + return exception(); + return r; + } + llvm::Expected IsInstance(const PythonObject &cls) { if (!m_py_obj || !cls.IsValid()) return nullDeref(); @@ -400,6 +421,10 @@ template <> llvm::Expected As(llvm::Expected &&obj); template <> +llvm::Expected +As(llvm::Expected &&obj); + +template <> llvm::Expected As(llvm::Expected &&obj); @@ -491,8 +516,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