diff options
author | David Spickett <david.spickett@linaro.org> | 2025-01-29 09:56:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-29 09:56:41 +0000 |
commit | 9ea64dd8781328d831d7c69a586f0c84dece1c11 (patch) | |
tree | c2fbaec5a5874a01e06695db85cf12071e1b9891 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | |
parent | 776ef9d1bec66875c554e8a5bd0e3ae8c9543d9a (diff) | |
download | llvm-9ea64dd8781328d831d7c69a586f0c84dece1c11.zip llvm-9ea64dd8781328d831d7c69a586f0c84dece1c11.tar.gz llvm-9ea64dd8781328d831d7c69a586f0c84dece1c11.tar.bz2 |
[lldb] Make Python >= 3.8 required for LLDB 21 (#124735)
As decided on
https://discourse.llvm.org/t/rfc-lets-document-and-enforce-a-minimum-python-version-for-lldb/82731.
LLDB 20 recommended `>= 3.8` but did not remove support for anything
earlier. Now we are in what will become LLDB 21, so I'm removing that
support and making
`>= 3.8` required.
See https://docs.python.org/3/c-api/apiabiversion.html#c.PY_VERSION_HEX
for the format of PY_VERSION_HEX.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index a0f8cf9..1340425 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -73,10 +73,8 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) { static bool python_is_finalizing() { #if PY_VERSION_HEX >= 0x030d0000 return Py_IsFinalizing(); -#elif PY_VERSION_HEX >= 0x03070000 - return _Py_IsFinalizing(); #else - return _Py_Finalizing != nullptr; + return _Py_IsFinalizing(); #endif } @@ -810,7 +808,6 @@ bool PythonCallable::Check(PyObject *py_obj) { return PyCallable_Check(py_obj); } -#if PY_VERSION_HEX >= 0x03030000 static const char get_arg_info_script[] = R"( from inspect import signature, Parameter, ismethod from collections import namedtuple @@ -832,15 +829,12 @@ def main(f): raise Exception(f'unknown parameter kind: {kind}') return ArgInfo(count, varargs) )"; -#endif Expected<PythonCallable::ArgInfo> PythonCallable::GetArgInfo() const { ArgInfo result = {}; if (!IsValid()) return nullDeref(); -#if PY_VERSION_HEX >= 0x03030000 - // no need to synchronize access to this global, we already have the GIL static PythonScript get_arg_info(get_arg_info_script); Expected<PythonObject> pyarginfo = get_arg_info(*this); @@ -852,57 +846,6 @@ Expected<PythonCallable::ArgInfo> PythonCallable::GetArgInfo() const { cantFail(As<bool>(pyarginfo.get().GetAttribute("has_varargs"))); result.max_positional_args = has_varargs ? ArgInfo::UNBOUNDED : count; -#else - PyObject *py_func_obj; - bool is_bound_method = false; - bool is_class = false; - - if (PyType_Check(m_py_obj) || PyClass_Check(m_py_obj)) { - auto init = GetAttribute("__init__"); - if (!init) - return init.takeError(); - py_func_obj = init.get().get(); - is_class = true; - } else { - py_func_obj = m_py_obj; - } - - if (PyMethod_Check(py_func_obj)) { - py_func_obj = PyMethod_GET_FUNCTION(py_func_obj); - PythonObject im_self = GetAttributeValue("im_self"); - if (im_self.IsValid() && !im_self.IsNone()) - is_bound_method = true; - } else { - // see if this is a callable object with an __call__ method - if (!PyFunction_Check(py_func_obj)) { - PythonObject __call__ = GetAttributeValue("__call__"); - if (__call__.IsValid()) { - auto __callable__ = __call__.AsType<PythonCallable>(); - if (__callable__.IsValid()) { - py_func_obj = PyMethod_GET_FUNCTION(__callable__.get()); - PythonObject im_self = __callable__.GetAttributeValue("im_self"); - if (im_self.IsValid() && !im_self.IsNone()) - is_bound_method = true; - } - } - } - } - - if (!py_func_obj) - return result; - - PyCodeObject *code = (PyCodeObject *)PyFunction_GET_CODE(py_func_obj); - if (!code) - return result; - - auto count = code->co_argcount; - bool has_varargs = !!(code->co_flags & CO_VARARGS); - result.max_positional_args = - has_varargs ? ArgInfo::UNBOUNDED - : (count - (int)is_bound_method) - (int)is_class; - -#endif - return result; } |