All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/python: change 's#' size type for Python >= 3.10
@ 2023-01-26  5:13 Marek Marczykowski-Górecki
  2023-01-26  9:14 ` Jan Beulich
  2023-01-26 14:40 ` Anthony PERARD
  0 siblings, 2 replies; 4+ messages in thread
From: Marek Marczykowski-Górecki @ 2023-01-26  5:13 UTC (permalink / raw)
  To: xen-devel; +Cc: Marek Marczykowski-Górecki, Wei Liu, Anthony PERARD

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.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/python/xen/lowlevel/xc/xc.c | 3 ++-
 tools/python/xen/lowlevel/xs/xs.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index fd008610329b..cfb2734a992b 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -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 };
diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index 0dad7fa5f2fc..3ba5a8b893d9 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -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)
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/python: change 's#' size type for Python >= 3.10
  2023-01-26  5:13 [PATCH] tools/python: change 's#' size type for Python >= 3.10 Marek Marczykowski-Górecki
@ 2023-01-26  9:14 ` Jan Beulich
  2023-01-26 12:09   ` Marek Marczykowski-Górecki
  2023-01-26 14:40 ` Anthony PERARD
  1 sibling, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2023-01-26  9:14 UTC (permalink / raw)
  To: Marek Marczykowski-Górecki; +Cc: Wei Liu, Anthony PERARD, xen-devel

On 26.01.2023 06:13, Marek Marczykowski-Górecki wrote:
> @@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/python: change 's#' size type for Python >= 3.10
  2023-01-26  9:14 ` Jan Beulich
@ 2023-01-26 12:09   ` Marek Marczykowski-Górecki
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Marczykowski-Górecki @ 2023-01-26 12:09 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Wei Liu, Anthony PERARD, xen-devel

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]

On Thu, Jan 26, 2023 at 10:14:54AM +0100, Jan Beulich wrote:
> On 26.01.2023 06:13, Marek Marczykowski-Górecki wrote:
> > @@ -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

> Irrespective of the remark of course I'll leave acking (or not) of this
> to people knowing Python better than I do.
> 
> Jan

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/python: change 's#' size type for Python >= 3.10
  2023-01-26  5:13 [PATCH] tools/python: change 's#' size type for Python >= 3.10 Marek Marczykowski-Górecki
  2023-01-26  9:14 ` Jan Beulich
@ 2023-01-26 14:40 ` Anthony PERARD
  1 sibling, 0 replies; 4+ messages in thread
From: Anthony PERARD @ 2023-01-26 14:40 UTC (permalink / raw)
  To: Marek Marczykowski-Górecki; +Cc: xen-devel, Wei Liu

On Thu, Jan 26, 2023 at 06:13:10AM +0100, Marek Marczykowski-Górecki wrote:
> 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.
> 
> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>

Thanks,

-- 
Anthony PERARD


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-26 14:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26  5:13 [PATCH] tools/python: change 's#' size type for Python >= 3.10 Marek Marczykowski-Górecki
2023-01-26  9:14 ` Jan Beulich
2023-01-26 12:09   ` Marek Marczykowski-Górecki
2023-01-26 14:40 ` Anthony PERARD

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.