diff options
author | Yee Cheng Chin <ychin.git@gmail.com> | 2023-10-17 10:38:11 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-17 10:38:11 +0200 |
commit | 396058acd0cc66e5071d052e03d2067b134952af (patch) | |
tree | 1569de6fb38ad992152589d8637ba775e9051542 | |
parent | 8f4fb007e4d472b09ff6bed9ffa485e0c3093699 (diff) |
patch 9.0.2036: if_python: rework python3.12 build dependencyv9.0.2036
Problem: if_python: rework python3.12 build dependency
(after 9.0.1996)
Solution: use PyTuple_Size instead of inlining the Py_SIZE
into the Vim code base
Use a simpler fix for Python 3.12 build issues
Python 3.12 introduced link dependencies to their `Py_SIZE()` inline
function, which #13290 fixed by copying the inline function to Vim's
Python binding code. This works but it's fragile, as a future update may
change the implementation of `Py_SIZE` and there is no way for us to
know.
The reason we need `Py_SIZE` to begin with is that we use
`PyTuple_GET_SIZE()` which calls that. Just fix it by mapping that to
(confusingly similarly named) `PyTuple_Size()`, which we already do in
the stable ABI implementation. There's a minor performance cost in that
it's not inlined and it does error checking but that's fine as we only
call this function rarely (in an error handler).
related: #13290
closes: #13359
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
-rw-r--r-- | src/if_python3.c | 46 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 8 insertions, 40 deletions
diff --git a/src/if_python3.c b/src/if_python3.c index a177371720..c39f42a6c7 100644 --- a/src/if_python3.c +++ b/src/if_python3.c @@ -299,9 +299,6 @@ static HINSTANCE hinstPy3 = 0; // Instance of python.dll # define PyNumber_Check (*py3_PyNumber_Check) # define PyNumber_Long (*py3_PyNumber_Long) # define PyBool_Type (*py3_PyBool_Type) -# if PY_VERSION_HEX >= 0x030c00b0 -# define PyLong_Type (*py3_PyLong_Type) -# endif # define PyErr_NewException py3_PyErr_NewException # ifdef Py_DEBUG # define _Py_NegativeRefcount py3__Py_NegativeRefcount @@ -501,9 +498,6 @@ static PyTypeObject* py3_PyStdPrinter_Type; static PyTypeObject* py3_PySlice_Type; static PyTypeObject* py3_PyFloat_Type; static PyTypeObject* py3_PyBool_Type; -# if PY_VERSION_HEX >= 0x030c00b0 -static PyTypeObject* py3_PyLong_Type; -# endif static int (*py3_PyNumber_Check)(PyObject *); static PyObject* (*py3_PyNumber_Long)(PyObject *); static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); @@ -701,9 +695,6 @@ static struct {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type}, {"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type}, -# if PY_VERSION_HEX >= 0x030c00b0 - {"PyLong_Type", (PYTHON_PROC*)&py3_PyLong_Type}, -# endif {"PyNumber_Check", (PYTHON_PROC*)&py3_PyNumber_Check}, {"PyNumber_Long", (PYTHON_PROC*)&py3_PyNumber_Long}, {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, @@ -795,39 +786,14 @@ py3__PyObject_TypeCheck(PyObject *ob, PyTypeObject *type) # endif # if !defined(USE_LIMITED_API) && PY_VERSION_HEX >= 0x030c00b0 -// Py_SIZE() uses PyLong_Type and PyBool_Type starting from Python 3.12. -// We need to define our own Py_SIZE() to replace Py{Bool,Long}_Type with -// py3_Py{Bool,Long}_Type. -// We also need to redefine PyTuple_GET_SIZE() and PyList_GET_SIZE(), because -// they use Py_SIZE(). - static inline Py_ssize_t -py3_Py_SIZE(PyObject *ob) -{ - assert(ob->ob_type != &PyLong_Type); - assert(ob->ob_type != &PyBool_Type); - PyVarObject *var_ob = _PyVarObject_CAST(ob); - return var_ob->ob_size; -} -# undef Py_SIZE -# define Py_SIZE(ob) py3_Py_SIZE(_PyObject_CAST(ob)) - - static inline Py_ssize_t -py3_PyTuple_GET_SIZE(PyObject *op) -{ - PyTupleObject *tuple = _PyTuple_CAST(op); - return Py_SIZE(tuple); -} +// PyTuple_GET_SIZE/PyList_GET_SIZE are inlined functions that use Py_SIZE(), +// which started to introduce linkage dependency from Python 3.12. When we +// build Python in dynamic mode, we don't link against it in build time, and +// this would fail to build. Just use the non-inlined version instead. # undef PyTuple_GET_SIZE -# define PyTuple_GET_SIZE(op) py3_PyTuple_GET_SIZE(_PyObject_CAST(op)) - - static inline -Py_ssize_t py3_PyList_GET_SIZE(PyObject *op) -{ - PyListObject *list = _PyList_CAST(op); - return Py_SIZE(list); -} +# define PyTuple_GET_SIZE(o) PyTuple_Size(o) # undef PyList_GET_SIZE -# define PyList_GET_SIZE(op) py3_PyList_GET_SIZE(_PyObject_CAST(op)) +# define PyList_GET_SIZE(o) PyList_Size(o) # endif # ifdef MSWIN diff --git a/src/version.c b/src/version.c index 6f39f950f8..02441bceb2 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2036, +/**/ 2035, /**/ 2034, |