[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
This commit is contained in:
Jonas Devlieghere authored and GitHub committed 2024-10-31 08:46:35 -07:00
1 parent 9234ae1bbe
commit 9ce0a61bdb
4 files changed
+20 -16

No files matched your search

@@ -71,12 +71,12 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&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::ArgInfo> 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);