Skip to content

Commit 396058a

Browse files
ychinchrisbra
authored andcommitted
patch 9.0.2036: if_python: rework python3.12 build dependency
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 <[email protected]> Co-authored-by: Yee Cheng Chin <[email protected]>
1 parent 8f4fb00 commit 396058a

File tree

2 files changed

+8
-40
lines changed

2 files changed

+8
-40
lines changed

src/if_python3.c

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ static HINSTANCE hinstPy3 = 0; // Instance of python.dll
299299
# define PyNumber_Check (*py3_PyNumber_Check)
300300
# define PyNumber_Long (*py3_PyNumber_Long)
301301
# define PyBool_Type (*py3_PyBool_Type)
302-
# if PY_VERSION_HEX >= 0x030c00b0
303-
# define PyLong_Type (*py3_PyLong_Type)
304-
# endif
305302
# define PyErr_NewException py3_PyErr_NewException
306303
# ifdef Py_DEBUG
307304
# define _Py_NegativeRefcount py3__Py_NegativeRefcount
@@ -501,9 +498,6 @@ static PyTypeObject* py3_PyStdPrinter_Type;
501498
static PyTypeObject* py3_PySlice_Type;
502499
static PyTypeObject* py3_PyFloat_Type;
503500
static PyTypeObject* py3_PyBool_Type;
504-
# if PY_VERSION_HEX >= 0x030c00b0
505-
static PyTypeObject* py3_PyLong_Type;
506-
# endif
507501
static int (*py3_PyNumber_Check)(PyObject *);
508502
static PyObject* (*py3_PyNumber_Long)(PyObject *);
509503
static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
@@ -701,9 +695,6 @@ static struct
701695
{"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
702696
{"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type},
703697
{"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type},
704-
# if PY_VERSION_HEX >= 0x030c00b0
705-
{"PyLong_Type", (PYTHON_PROC*)&py3_PyLong_Type},
706-
# endif
707698
{"PyNumber_Check", (PYTHON_PROC*)&py3_PyNumber_Check},
708699
{"PyNumber_Long", (PYTHON_PROC*)&py3_PyNumber_Long},
709700
{"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException},
@@ -795,39 +786,14 @@ py3__PyObject_TypeCheck(PyObject *ob, PyTypeObject *type)
795786
# endif
796787

797788
# if !defined(USE_LIMITED_API) && PY_VERSION_HEX >= 0x030c00b0
798-
// Py_SIZE() uses PyLong_Type and PyBool_Type starting from Python 3.12.
799-
// We need to define our own Py_SIZE() to replace Py{Bool,Long}_Type with
800-
// py3_Py{Bool,Long}_Type.
801-
// We also need to redefine PyTuple_GET_SIZE() and PyList_GET_SIZE(), because
802-
// they use Py_SIZE().
803-
static inline Py_ssize_t
804-
py3_Py_SIZE(PyObject *ob)
805-
{
806-
assert(ob->ob_type != &PyLong_Type);
807-
assert(ob->ob_type != &PyBool_Type);
808-
PyVarObject *var_ob = _PyVarObject_CAST(ob);
809-
return var_ob->ob_size;
810-
}
811-
# undef Py_SIZE
812-
# define Py_SIZE(ob) py3_Py_SIZE(_PyObject_CAST(ob))
813-
814-
static inline Py_ssize_t
815-
py3_PyTuple_GET_SIZE(PyObject *op)
816-
{
817-
PyTupleObject *tuple = _PyTuple_CAST(op);
818-
return Py_SIZE(tuple);
819-
}
789+
// PyTuple_GET_SIZE/PyList_GET_SIZE are inlined functions that use Py_SIZE(),
790+
// which started to introduce linkage dependency from Python 3.12. When we
791+
// build Python in dynamic mode, we don't link against it in build time, and
792+
// this would fail to build. Just use the non-inlined version instead.
820793
# undef PyTuple_GET_SIZE
821-
# define PyTuple_GET_SIZE(op) py3_PyTuple_GET_SIZE(_PyObject_CAST(op))
822-
823-
static inline
824-
Py_ssize_t py3_PyList_GET_SIZE(PyObject *op)
825-
{
826-
PyListObject *list = _PyList_CAST(op);
827-
return Py_SIZE(list);
828-
}
794+
# define PyTuple_GET_SIZE(o) PyTuple_Size(o)
829795
# undef PyList_GET_SIZE
830-
# define PyList_GET_SIZE(op) py3_PyList_GET_SIZE(_PyObject_CAST(op))
796+
# define PyList_GET_SIZE(o) PyList_Size(o)
831797
# endif
832798

833799
# ifdef MSWIN

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+
2036,
707709
/**/
708710
2035,
709711
/**/

0 commit comments

Comments
 (0)