tools/python: change 's#' size type for Python >= 3.10
PATCH 1/1 tools/python: change 's#' size type for Python >= 3.10
Python < 3.10 by default uses 'int' type for data+size string types (s#), unless PY_SSIZE_T_CLEAN is defined - in which case it uses Py_ssize_t. The former behavior was removed in Python 3.10 and now it's required to define PY_SSIZE_T_CLEAN before including Python.h, and using Py_ssize_t for the length argument. The PY_SSIZE_T_CLEAN behavior is supported since Python 2.5.
Adjust bindings accordingly.
--- tools/python/xen/lowlevel/xc/xc.c | 3 ++- tools/python/xen/lowlevel/xs/xs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +2 -1
@@ -4,6 +4,7 @@* Copyright (c) 2003-2004, K A Fraser (University of Cambridge) */ +#define PY_SSIZE_T_CLEAN #include <Python.h> #define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h>
@@ -1774,7 +1775,7 @@ static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) {xc_interface *xc_handle;char *policy; -uint32_t len; +Py_ssize_t len;int ret;static char *kwd_list[] = {"policy" ,NULL };
tools/python/xen/lowlevel/xs/xs.c +2 -1
@@ -18,6 +18,7 @@* Copyright (C) 2005 XenSource Ltd. */ +#define PY_SSIZE_T_CLEAN #include <Python.h> #include <stdbool.h>
@@ -141,7 +142,7 @@ static PyObject *xspy_write(XsHandle *self, PyObject *args)char *thstr;char *path;char *data; -int data_n; +Py_ssize_t data_n;bool result;if (!xh)
Signature · 1 line
2.37.3
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) · line 1778
Quoted 6 lines · Marek Marczykowski-Górecki
tools/python/xen/lowlevel/xc/xc.c +1
-1@@ -1774,7 +1775,7 @@ static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) {xc_interface *xc_handle;char *policy; -uint32_t len; +Py_ssize_t len;
I find this suspicious - by the name, this is a signed type when an unsigned one was used here before (and properly, imo).
Irrespective of the remark of course I'll leave acking (or not) of this to people knowing Python better than I do.
Jan
Quoted 10 lines · Jan Beulich
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) · line 1778
Quoted 6 lines · Marek Marczykowski-Górecki
tools/python/xen/lowlevel/xc/xc.c +1
-1@@ -1774,7 +1775,7 @@ static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) {xc_interface *xc_handle;char *policy; -uint32_t len; +Py_ssize_t len;I find this suspicious - by the name, this is a signed type when an unsigned one was used here before (and properly, imo).
It is suspicious indeed, but correct according to the documentation:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers
Quoted 4 lines
Irrespective of the remark of course I'll leave acking (or not) of this to people knowing Python better than I do.
Jan
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 10 lines · Marek Marczykowski-Górecki
Python < 3.10 by default uses 'int' type for data+size string types (s#), unless
PY_SSIZE_T_CLEANis defined - in which case it usesPy_ssize_t. The former behavior was removed in Python 3.10 and now it's required to definePY_SSIZE_T_CLEANbefore includingPython.h, and usingPy_ssize_tfor the length argument. ThePY_SSIZE_T_CLEANbehavior is supported since Python 2.5.Adjust bindings accordingly.
Signed-off-by Marek Marczykowski-Górecki <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD