Build: resolve error with Python 3.14

Include local version of _PyArg_CheckPositional which is private
for CPython as of Python 3.14.

Ref !147783
This commit is contained in:
Campbell Barton
2025-10-10 17:30:10 +11:00
parent b9dcc087a9
commit 224bd118eb
4 changed files with 81 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ set(SRC
imbuf_py_api.cc
py_capi_rna.cc
py_capi_utils.cc
python_compat.cc
bl_math_py_api.hh
blf_py_api.hh
@@ -28,9 +29,9 @@ set(SRC
imbuf_py_api.hh
py_capi_rna.hh
py_capi_utils.hh
python_compat.hh
# header-only
python_compat.hh
python_utildefines.hh
)

View File

@@ -0,0 +1,76 @@
/* SPDX-FileCopyrightText: 2025 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup pygen
*
* Functions relating to compatibility across Python versions.
*/
#include <Python.h> /* IWYU pragma: keep. */
#include "BLI_utildefines.h" /* IWYU pragma: keep. */
#include "python_compat.hh" /* IWYU pragma: keep. */
#if PY_VERSION_HEX >= 0x030e0000 /* >=3.14 */
/* Removed in Python 3.14. */
int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max)
{
BLI_assert(min >= 0);
BLI_assert(min <= max);
if (nargs < min) {
if (name != nullptr) {
PyErr_Format(PyExc_TypeError,
"%.200s expected %s%zd argument%s, got %zd",
name,
(min == max ? "" : "at least "),
min,
min == 1 ? "" : "s",
nargs);
}
else {
PyErr_Format(PyExc_TypeError,
"unpacked tuple should have %s%zd element%s,"
" but has %zd",
(min == max ? "" : "at least "),
min,
min == 1 ? "" : "s",
nargs);
}
return 0;
}
if (nargs == 0) {
return 1;
}
if (nargs > max) {
if (name != nullptr) {
PyErr_Format(PyExc_TypeError,
"%.200s expected %s%zd argument%s, got %zd",
name,
(min == max ? "" : "at most "),
max,
max == 1 ? "" : "s",
nargs);
}
else {
PyErr_Format(PyExc_TypeError,
"unpacked tuple should have %s%zd element%s,"
" but has %zd",
(min == max ? "" : "at most "),
max,
max == 1 ? "" : "s",
nargs);
}
return 0;
}
return 1;
}
#endif

View File

@@ -48,6 +48,7 @@
#if PY_VERSION_HEX < 0x030e0000
# define Py_HashPointer _Py_HashPointer
# define PyThreadState_GetUnchecked _PyThreadState_UncheckedGet
/* TODO: Support: `PyDict_Pop`, it has different arguments. */
#else /* >= 3.14 */
int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t min, Py_ssize_t max);
#endif

View File

@@ -29,6 +29,7 @@
#include "BLI_utildefines.h"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
#include "../generic/python_utildefines.hh"
/* ---------------------------------INTERSECTION FUNCTIONS-------------------- */