Blender V5.0
python_compat.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#pragma once
14
15#include <Python.h>
16
17/* Removes `intialized` member from Python 3.13+. */
18#if PY_VERSION_HEX >= 0x030d0000
19# define PY_ARG_PARSER_HEAD_COMPAT()
20#elif PY_VERSION_HEX >= 0x030c0000
21/* Add `intialized` member for Python 3.12+. */
22# define PY_ARG_PARSER_HEAD_COMPAT() 0,
23#else
24# define PY_ARG_PARSER_HEAD_COMPAT()
25#endif
26
27/* Python 3.13 made some changes, use the "new" names. */
28#if PY_VERSION_HEX < 0x030d0000
29# define PyObject_GetOptionalAttr _PyObject_LookupAttr
30
31[[nodiscard]] Py_LOCAL_INLINE(int)
32 PyObject_GetOptionalAttrString(PyObject *obj, const char *name, PyObject **result)
33{
34 PyObject *oname = PyUnicode_FromString(name);
35 if (oname == nullptr) {
36 *result = nullptr;
37 return -1;
38 }
39 const int status = PyObject_GetOptionalAttr(obj, oname, result);
40 Py_DECREF(oname);
41 return status;
42}
43
44# define Py_IsFinalizing _Py_IsFinalizing
45#endif
46
47/* Python 3.14 made some changes, use the "new" names. */
48#if PY_VERSION_HEX < 0x030e0000
49# define Py_HashPointer _Py_HashPointer
50# define PyThreadState_GetUnchecked _PyThreadState_UncheckedGet
51/* TODO: Support: `PyDict_Pop`, it has different arguments. */
52#endif
53
54#if PY_VERSION_HEX >= 0x030d0000 /* >= 3.13 */
55int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max);
56#endif
Py_LOCAL_INLINE(int) PyObject_GetOptionalAttrString(PyObject *obj
#define PyObject_GetOptionalAttr
Py_DECREF(oname)
const char * name
const int status
#define min(a, b)
Definition sort.cc:36
max
Definition text_draw.cc:251