Skip to content

Commit c2285a8

Browse files
ychinchrisbra
authored andcommitted
patch 9.1.0724: if_python: link error with python 3.13 and stable ABI
Problem: if_python: link error with python 3.13 and stable ABI (zdohnal) Solution: Use the correct stable APIs Py_IncRef and Py_DecRef instead (Yee Cheng Chin) This fixes #15460 properly. There was an attempt to fix it in v9.1.0668, but it did it by manually copy and pasting definitions from Python 3.13 headers, which is problematic as it makes Vim dependent on low-level implementation details which are subject to change. That change also pulls in dependencies to private APIs (`_Py_IncRef`) which is a very bad idea as the next version of Python could very well remove that. The core issue was simply that `Py_INCREF` and similar functions are not part of the stable API. We are supposed to be using `Py_IncRef` instead which performs null-check (similar to `Py_XINCREF`) and is available as a linkable function. We simply need to call it instead of the macro. We simply remap `Py_INCREF` (and friends) to the function version in stable API similar to how we mapped other functions. related #15460 closes: #15648 Signed-off-by: Yee Cheng Chin <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 97a5be4 commit c2285a8

2 files changed

Lines changed: 20 additions & 34 deletions

File tree

src/if_python3.c

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,9 @@ static HINSTANCE hinstPy3 = 0; // Instance of python.dll
219219
# define PyObject_GetItem py3_PyObject_GetItem
220220
# define PyObject_IsTrue py3_PyObject_IsTrue
221221
# define PyModule_GetDict py3_PyModule_GetDict
222-
# if defined(USE_LIMITED_API) \
223-
&& (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
224-
# undef Py_INCREF
225-
# if Py_LIMITED_API+0 >= 0x030a00A7
226-
# define _Py_IncRef py3__Py_IncRef
227-
# define Py_INCREF _Py_IncRef
228-
# else
229-
# define Py_IncRef py3_Py_IncRef
230-
# define Py_INCREF Py_IncRef
231-
# endif
222+
# ifdef USE_LIMITED_API
223+
# define Py_IncRef py3_Py_IncRef
224+
# define Py_DecRef py3_Py_DecRef
232225
# endif
233226
# ifdef USE_LIMITED_API
234227
# define Py_CompileString py3_Py_CompileString
@@ -403,14 +396,9 @@ static void (*py3_Py_Finalize)(void);
403396
static void (*py3_PyErr_SetString)(PyObject *, const char *);
404397
static void (*py3_PyErr_SetObject)(PyObject *, PyObject *);
405398
static int (*py3_PyErr_ExceptionMatches)(PyObject *);
406-
# if defined(USE_LIMITED_API) \
407-
&& (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
408-
# if Py_LIMITED_API+0 >= 0x030a00A7
409-
# define _Py_IncRef py3__Py_IncRef
410-
static void (*py3__Py_IncRef)(PyObject *);
411-
# else
399+
# ifdef USE_LIMITED_API
412400
static void (*py3_Py_IncRef)(PyObject *);
413-
# endif
401+
static void (*py3_Py_DecRef)(PyObject *);
414402
# endif
415403
# ifdef USE_LIMITED_API
416404
static PyObject* (*py3_Py_CompileString)(const char *, const char *, int);
@@ -619,13 +607,9 @@ static struct
619607
{"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString},
620608
{"PyErr_SetObject", (PYTHON_PROC*)&py3_PyErr_SetObject},
621609
{"PyErr_ExceptionMatches", (PYTHON_PROC*)&py3_PyErr_ExceptionMatches},
622-
# if defined(USE_LIMITED_API) \
623-
&& (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
624-
# if Py_LIMITED_API+0 >= 0x030a00A7
625-
{"_Py_IncRef", (PYTHON_PROC*)&py3__Py_IncRef},
626-
# else
610+
# ifdef USE_LIMITED_API
627611
{"Py_IncRef", (PYTHON_PROC*)&py3_Py_IncRef},
628-
# endif
612+
{"Py_DecRef", (PYTHON_PROC*)&py3_Py_DecRef},
629613
# endif
630614
# ifdef USE_LIMITED_API
631615
{"Py_CompileString", (PYTHON_PROC*)&py3_Py_CompileString},
@@ -803,18 +787,18 @@ py3__Py_XDECREF(PyObject *op)
803787
# define Py_XDECREF(op) py3__Py_XDECREF(_PyObject_CAST(op))
804788
# endif
805789

806-
# if defined(USE_LIMITED_API) \
807-
&& (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
808-
static inline void
809-
py3__Py_XINCREF(PyObject *op)
810-
{
811-
if (op != NULL)
812-
{
813-
Py_INCREF(op);
814-
}
815-
}
790+
# ifdef USE_LIMITED_API
791+
// Use stable versions of inc/dec ref. Note that these always null-check and
792+
// therefore there's no difference between XINCREF and INCREF.
793+
# undef Py_INCREF
794+
# define Py_INCREF(obj) Py_IncRef((PyObject *)obj)
816795
# undef Py_XINCREF
817-
# define Py_XINCREF(op) py3__Py_XINCREF(_PyObject_CAST(op))
796+
# define Py_XINCREF(obj) Py_IncRef((PyObject *)obj)
797+
798+
# undef Py_DECREF
799+
# define Py_DECREF(obj) Py_DecRef((PyObject *)obj)
800+
# undef Py_XDECREF
801+
# define Py_XDECREF(obj) Py_DecRef((PyObject *)obj)
818802
# endif
819803

820804
# if PY_VERSION_HEX >= 0x030900b0

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
724,
707709
/**/
708710
723,
709711
/**/

0 commit comments

Comments
 (0)