summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Takata <kentkt@csc.jp>2023-10-06 19:27:13 +0200
committerChristian Brabandt <cb@256bit.org>2023-10-06 19:27:13 +0200
commitfa145f200966e47e11c403520374d6d37cfd1de7 (patch)
treec044575d65f75505d6a51caab65fc5680ebf04d1
parent26e8f7b0ab451e76319d113038c86c79488bbbc4 (diff)
patch 9.0.1996: Cannot build with python312v9.0.1996
Problem: Cannot build with python312 Solution: Define wrapper types and functions for python 3.12 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(). closes: #13281 closes: #13290 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Ken Takata <kentkt@csc.jp>
-rw-r--r--src/if_python3.c49
-rw-r--r--src/version.c2
2 files changed, 46 insertions, 5 deletions
diff --git a/src/if_python3.c b/src/if_python3.c
index bbbebc39f1..52027bd562 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -68,8 +68,6 @@
#endif
#define PY_SSIZE_T_CLEAN
-#define PyLong_Type (*py3_PyLong_Type)
-#define PyBool_Type (*py3_PyBool_Type)
#ifdef Py_LIMITED_API
# define USE_LIMITED_API // Using Python 3 limited ABI
@@ -297,6 +295,10 @@ static HINSTANCE hinstPy3 = 0; // Instance of python.dll
# define PyFloat_Type (*py3_PyFloat_Type)
# 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
@@ -496,9 +498,9 @@ static PyTypeObject* py3_PyStdPrinter_Type;
# endif
static PyTypeObject* py3_PySlice_Type;
static PyTypeObject* py3_PyFloat_Type;
-PyTypeObject* py3_PyBool_Type;
+static PyTypeObject* py3_PyBool_Type;
# if PY_VERSION_HEX >= 0x030c00b0
-PyTypeObject* py3_PyLong_Type;
+static PyTypeObject* py3_PyLong_Type;
# endif
static int (*py3_PyNumber_Check)(PyObject *);
static PyObject* (*py3_PyNumber_Long)(PyObject *);
@@ -696,8 +698,9 @@ static struct
# endif
{"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
{"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type},
-# if PY_VERSION_HEX < 0x030c00b0
{"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},
@@ -789,6 +792,42 @@ py3__PyObject_TypeCheck(PyObject *ob, PyTypeObject *type)
# endif
# 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);
+}
+# 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);
+}
+# undef PyList_GET_SIZE
+# define PyList_GET_SIZE(op) py3_PyList_GET_SIZE(_PyObject_CAST(op))
+# endif
+
# ifdef MSWIN
/*
* Look up the library "libname" using the InstallPath registry key.
diff --git a/src/version.c b/src/version.c
index ce13dcc776..ec25a1213d 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 */
/**/
+ 1996,
+/**/
1995,
/**/
1994,