patch 9.1.0724: if_python: link error with python 3.13 and stable ABI

Commit: 
https://github.com/vim/vim/commit/c2285a8cf397d1d694a350415fb37f7d51202ec4
Author: Yee Cheng Chin <ychin....@gmail.com>
Date:   Mon Sep 9 19:55:24 2024 +0200

    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 <ychin....@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/if_python3.c b/src/if_python3.c
index fd117f0a7..1045b8485 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -219,16 +219,9 @@ static HINSTANCE hinstPy3 = 0; // Instance of python.dll
 # define PyObject_GetItem py3_PyObject_GetItem
 # define PyObject_IsTrue py3_PyObject_IsTrue
 # define PyModule_GetDict py3_PyModule_GetDict
-# if defined(USE_LIMITED_API) \
-    && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
-#  undef Py_INCREF
-#  if Py_LIMITED_API+0 >= 0x030a00A7
-#   define _Py_IncRef py3__Py_IncRef
-#   define Py_INCREF _Py_IncRef
-#  else
-#   define Py_IncRef py3_Py_IncRef
-#   define Py_INCREF Py_IncRef
-#  endif
+# ifdef USE_LIMITED_API
+#  define Py_IncRef py3_Py_IncRef
+#  define Py_DecRef py3_Py_DecRef
 # endif
 # ifdef USE_LIMITED_API
 #  define Py_CompileString py3_Py_CompileString
@@ -403,14 +396,9 @@ static void (*py3_Py_Finalize)(void);
 static void (*py3_PyErr_SetString)(PyObject *, const char *);
 static void (*py3_PyErr_SetObject)(PyObject *, PyObject *);
 static int (*py3_PyErr_ExceptionMatches)(PyObject *);
-# if defined(USE_LIMITED_API) \
-    && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
-#  if Py_LIMITED_API+0 >= 0x030a00A7
-#   define _Py_IncRef py3__Py_IncRef
-static void (*py3__Py_IncRef)(PyObject *);
-#  else
+# ifdef USE_LIMITED_API
 static void (*py3_Py_IncRef)(PyObject *);
-#  endif
+static void (*py3_Py_DecRef)(PyObject *);
 # endif
 # ifdef USE_LIMITED_API
 static PyObject* (*py3_Py_CompileString)(const char *, const char *, int);
@@ -619,13 +607,9 @@ static struct
     {"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString},
     {"PyErr_SetObject", (PYTHON_PROC*)&py3_PyErr_SetObject},
     {"PyErr_ExceptionMatches", (PYTHON_PROC*)&py3_PyErr_ExceptionMatches},
-# if defined(USE_LIMITED_API) \
-    && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
-#  if Py_LIMITED_API+0 >= 0x030a00A7
-    {"_Py_IncRef", (PYTHON_PROC*)&py3__Py_IncRef},
-#  else
+# ifdef USE_LIMITED_API
     {"Py_IncRef", (PYTHON_PROC*)&py3_Py_IncRef},
-#  endif
+    {"Py_DecRef", (PYTHON_PROC*)&py3_Py_DecRef},
 # endif
 # ifdef USE_LIMITED_API
     {"Py_CompileString", (PYTHON_PROC*)&py3_Py_CompileString},
@@ -803,18 +787,18 @@ py3__Py_XDECREF(PyObject *op)
 #  define Py_XDECREF(op) py3__Py_XDECREF(_PyObject_CAST(op))
 # endif
 
-# if defined(USE_LIMITED_API) \
-    && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
-    static inline void
-py3__Py_XINCREF(PyObject *op)
-{
-    if (op != NULL)
-    {
-       Py_INCREF(op);
-    }
-}
+# ifdef USE_LIMITED_API
+// Use stable versions of inc/dec ref. Note that these always null-check and
+// therefore there's no difference between XINCREF and INCREF.
+#  undef Py_INCREF
+#  define Py_INCREF(obj) Py_IncRef((PyObject *)obj)
 #  undef Py_XINCREF
-#  define Py_XINCREF(op) py3__Py_XINCREF(_PyObject_CAST(op))
+#  define Py_XINCREF(obj) Py_IncRef((PyObject *)obj)
+
+#  undef Py_DECREF
+#  define Py_DECREF(obj) Py_DecRef((PyObject *)obj)
+#  undef Py_XDECREF
+#  define Py_XDECREF(obj) Py_DecRef((PyObject *)obj)
 # endif
 
 # if PY_VERSION_HEX >= 0x030900b0
diff --git a/src/version.c b/src/version.c
index db611c969..c8c0caf59 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    724,
 /**/
     723,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1snigO-005Lo0-2W%40256bit.org.

Raspunde prin e-mail lui