From 9ce0a61bdbf13d4d0f2e13e1bb6e7a4bb9d01858 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 31 Oct 2024 08:46:35 -0700 Subject: [lldb] Use PY_VERSION_HEX to simplify conditional compilation (NFC) (#114346) Use PY_VERSION_HEX to simplify conditional compilation depending on the Python version. This also adds a static_assert to lldb-python to error out with a meaningful diagnostic when you try building LLDB with an older Python version in preparation for [1]. [1] https://discourse.llvm.org/t/rfc-lets-document-and-enforce-a-minimum-python-version-for-lldb/82731/15 --- .../Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 90ccd10..a0f8cf9 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -71,12 +71,12 @@ Expected python::As(Expected &&obj) { } static bool python_is_finalizing() { -#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13) || (PY_MAJOR_VERSION > 3) +#if PY_VERSION_HEX >= 0x030d0000 return Py_IsFinalizing(); -#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7 - return _Py_Finalizing != nullptr; -#else +#elif PY_VERSION_HEX >= 0x03070000 return _Py_IsFinalizing(); +#else + return _Py_Finalizing != nullptr; #endif } @@ -810,7 +810,7 @@ bool PythonCallable::Check(PyObject *py_obj) { return PyCallable_Check(py_obj); } -#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3 +#if PY_VERSION_HEX >= 0x03030000 static const char get_arg_info_script[] = R"( from inspect import signature, Parameter, ismethod from collections import namedtuple @@ -839,7 +839,7 @@ Expected PythonCallable::GetArgInfo() const { if (!IsValid()) return nullDeref(); -#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3 +#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); -- cgit v1.1