2023-08-30 14:05:32 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup pygen
|
|
|
|
|
* \brief header-only compatibility defines.
|
2025-06-20 04:19:35 +00:00
|
|
|
*
|
|
|
|
|
* \note this header should not be removed/cleaned where Python is used.
|
|
|
|
|
* Because its required for Blender to build against different versions of Python.
|
2023-08-30 14:05:32 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-01-07 12:39:13 +01:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2024-10-18 12:23:34 +11:00
|
|
|
/* Removes `intialized` member from Python 3.13+. */
|
|
|
|
|
#if PY_VERSION_HEX >= 0x030d0000
|
|
|
|
|
# define PY_ARG_PARSER_HEAD_COMPAT()
|
|
|
|
|
#elif PY_VERSION_HEX >= 0x030c0000
|
2023-08-30 14:05:32 +10:00
|
|
|
/* Add `intialized` member for Python 3.12+. */
|
|
|
|
|
# define PY_ARG_PARSER_HEAD_COMPAT() 0,
|
|
|
|
|
#else
|
|
|
|
|
# define PY_ARG_PARSER_HEAD_COMPAT()
|
|
|
|
|
#endif
|
2024-10-18 12:23:34 +11:00
|
|
|
|
|
|
|
|
/* Python 3.13 made some changes, use the "new" names. */
|
|
|
|
|
#if PY_VERSION_HEX < 0x030d0000
|
|
|
|
|
# define PyObject_GetOptionalAttr _PyObject_LookupAttr
|
2025-02-13 20:45:26 +11:00
|
|
|
|
2025-07-04 02:08:57 +00:00
|
|
|
[[nodiscard]] Py_LOCAL_INLINE(int)
|
|
|
|
|
PyObject_GetOptionalAttrString(PyObject *obj, const char *name, PyObject **result)
|
|
|
|
|
{
|
|
|
|
|
PyObject *oname = PyUnicode_FromString(name);
|
|
|
|
|
if (oname == nullptr) {
|
|
|
|
|
*result = nullptr;
|
2025-07-04 13:20:39 +10:00
|
|
|
return -1;
|
2025-07-04 02:08:57 +00:00
|
|
|
}
|
|
|
|
|
const int status = PyObject_GetOptionalAttr(obj, oname, result);
|
|
|
|
|
Py_DECREF(oname);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 20:45:26 +11:00
|
|
|
# define Py_IsFinalizing _Py_IsFinalizing
|
2024-10-18 12:23:34 +11:00
|
|
|
#endif
|
2025-06-20 04:19:35 +00:00
|
|
|
|
|
|
|
|
/* Python 3.14 made some changes, use the "new" names. */
|
|
|
|
|
#if PY_VERSION_HEX < 0x030e0000
|
|
|
|
|
# define Py_HashPointer _Py_HashPointer
|
|
|
|
|
# define PyThreadState_GetUnchecked _PyThreadState_UncheckedGet
|
|
|
|
|
/* TODO: Support: `PyDict_Pop`, it has different arguments. */
|
2025-10-10 17:30:10 +11:00
|
|
|
#else /* >= 3.14 */
|
|
|
|
|
int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max);
|
2025-06-20 04:19:35 +00:00
|
|
|
#endif
|