diff options
author | Muhammad Omair Javaid <omair.javaid@linaro.org> | 2020-04-23 04:35:30 +0500 |
---|---|---|
committer | Muhammad Omair Javaid <omair.javaid@linaro.org> | 2020-04-23 04:38:32 +0500 |
commit | 478619cf9a24ad8eac806959ca6a289a9beb71ae (patch) | |
tree | 68bd520ed56aeac5cd6cbdd47afd3127d2eae032 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | |
parent | 328bb446ddd2c03e4da3e9aa0473fa2f1c52d34e (diff) | |
download | llvm-478619cf9a24ad8eac806959ca6a289a9beb71ae.zip llvm-478619cf9a24ad8eac806959ca6a289a9beb71ae.tar.gz llvm-478619cf9a24ad8eac806959ca6a289a9beb71ae.tar.bz2 |
Revert "get rid of PythonInteger::GetInteger()"
This reverts commit 7375212172951d2fc283c81d03c1a8588c3280c6.
This causes multiple test failures on LLDB AArch64 Linux buildbot.
http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/3695
Differential Revision: https://reviews.llvm.org/D78462
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 3f00f67..40ed22a 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -44,15 +44,7 @@ template <> Expected<long long> python::As<long long>(Expected<PythonObject> &&obj) { if (!obj) return obj.takeError(); - return obj->AsLongLong(); -} - -template <> -Expected<unsigned long long> -python::As<unsigned long long>(Expected<PythonObject> &&obj) { - if (!obj) - return obj.takeError(); - return obj->AsUnsignedLongLong(); + return obj.get().AsLongLong(); } template <> @@ -471,22 +463,32 @@ void PythonInteger::Convert(PyRefType &type, PyObject *&py_obj) { #endif } +int64_t PythonInteger::GetInteger() const { + if (m_py_obj) { + assert(PyLong_Check(m_py_obj) && + "PythonInteger::GetInteger has a PyObject that isn't a PyLong"); + + int overflow = 0; + int64_t result = PyLong_AsLongLongAndOverflow(m_py_obj, &overflow); + if (overflow != 0) { + // We got an integer that overflows, like 18446744072853913392L we can't + // use PyLong_AsLongLong() as it will return 0xffffffffffffffff. If we + // use the unsigned long long it will work as expected. + const uint64_t uval = PyLong_AsUnsignedLongLong(m_py_obj); + result = static_cast<int64_t>(uval); + } + return result; + } + return UINT64_MAX; +} + void PythonInteger::SetInteger(int64_t value) { *this = Take<PythonInteger>(PyLong_FromLongLong(value)); } StructuredData::IntegerSP PythonInteger::CreateStructuredInteger() const { StructuredData::IntegerSP result(new StructuredData::Integer); - // FIXME this is really not ideal. Errors are silently converted to 0 - // and overflows are silently wrapped. But we'd need larger changes - // to StructuredData to fix it, so that's how it is for now. - llvm::Expected<unsigned long long> value = AsModuloUnsignedLongLong(); - if (!value) { - llvm::consumeError(value.takeError()); - result->SetValue(0); - } else { - result->SetValue(value.get()); - } + result->SetValue(GetInteger()); return result; } |