python3-pybluez: fix a runtime issue with python 3.10

Message ID 20220614115906.37309-1-brgl@bgdev.pl
State New
Headers show
Series python3-pybluez: fix a runtime issue with python 3.10 | expand

Commit Message

Bartosz Golaszewski June 14, 2022, 11:59 a.m. UTC
Add an upstream patch that's not part of any release yet that addresses
an issue with python 3.10 (related to a missing macro).

Link: https://github.com/pybluez/pybluez/issues/426
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 ...hen-parsing-buffer-length-fix-426-42.patch | 153 ++++++++++++++++++
 .../python/python3-pybluez_0.23.bb            |   1 +
 2 files changed, 154 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-pybluez/0001-Use-Py_ssize_t-when-parsing-buffer-length-fix-426-42.patch

Comments

Bartosz Golaszewski June 22, 2022, 8:59 p.m. UTC | #1
On Tue, Jun 14, 2022 at 1:59 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> Add an upstream patch that's not part of any release yet that addresses
> an issue with python 3.10 (related to a missing macro).
>
> Link: https://github.com/pybluez/pybluez/issues/426
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---

Hey, I think this got lost because I forgot the [meta-python] label.

Should I resend or can you pick it up without it?

Bart
Khem Raj June 29, 2022, 4:59 p.m. UTC | #2
On 6/22/22 4:59 PM, Bartosz Golaszewski wrote:
> On Tue, Jun 14, 2022 at 1:59 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>> Add an upstream patch that's not part of any release yet that addresses
>> an issue with python 3.10 (related to a missing macro).
>>
>> Link: https://github.com/pybluez/pybluez/issues/426
>> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
>> ---
> Hey, I think this got lost because I forgot the [meta-python] label.
>
> Should I resend or can you pick it up without it?


No need, I took care of it while staging.


> Bart

Patch

diff --git a/meta-python/recipes-devtools/python/python3-pybluez/0001-Use-Py_ssize_t-when-parsing-buffer-length-fix-426-42.patch b/meta-python/recipes-devtools/python/python3-pybluez/0001-Use-Py_ssize_t-when-parsing-buffer-length-fix-426-42.patch
new file mode 100644
index 000000000..9126aba8d
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-pybluez/0001-Use-Py_ssize_t-when-parsing-buffer-length-fix-426-42.patch
@@ -0,0 +1,153 @@ 
+From aa8ee5e5e934908f0357364f6ec90a3ecda62880 Mon Sep 17 00:00:00 2001
+From: Nicolas Schodet <nico@ni.fr.eu.org>
+Date: Mon, 3 Jan 2022 02:37:01 +0100
+Subject: [PATCH] Use Py_ssize_t when parsing buffer length, fix #426 (#427)
+
+From python 3.9 documentation:
+
+> For all # variants of formats (s#, y#, etc.), the macro
+> PY_SSIZE_T_CLEAN must be defined before including Python.h. On Python
+> 3.9 and older, the type of the length argument is Py_ssize_t if the
+> PY_SSIZE_T_CLEAN macro is defined, or int otherwise.
+
+From python 3.8 changes:
+
+> Use of # variants of formats in parsing or building value (e.g.
+> PyArg_ParseTuple(), Py_BuildValue(), PyObject_CallFunction(), etc.)
+> without PY_SSIZE_T_CLEAN defined raises DeprecationWarning now. It
+> will be removed in 3.10 or 4.0. Read Parsing arguments and building
+> values for detail. (Contributed by Inada Naoki in bpo-36381.)
+
+Fixes https://github.com/pybluez/pybluez/issues/426
+---
+Upstream-Status: Accepted
+
+ bluez/btmodule.c | 23 ++++++++++++++---------
+ msbt/_msbt.c     |  6 ++++--
+ 2 files changed, 18 insertions(+), 11 deletions(-)
+
+diff --git a/bluez/btmodule.c b/bluez/btmodule.c
+index 518b723..912a489 100644
+--- a/bluez/btmodule.c
++++ b/bluez/btmodule.c
+@@ -16,7 +16,8 @@ Local naming conventions:
+ - names starting with bt_ are module-level functions
+ 
+ */
+-
++#define PY_SSIZE_T_CLEAN 1
++#include "Python.h"
+ #include "btmodule.h"
+ #include "structmember.h"
+ 
+@@ -732,7 +733,7 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)
+     int optname;
+     int res;
+     void *buf;
+-    int buflen;
++    Py_ssize_t buflen;
+     int flag;
+ 
+     if (PyArg_ParseTuple(args, "iii:setsockopt", &level, &optname, &flag)) {
+@@ -2001,7 +2002,8 @@ static PyObject *
+ bt_hci_send_cmd(PyObject *self, PyObject *args)
+ {
+     PySocketSockObject *socko = NULL;
+-    int err, plen = 0;
++    int err;
++    Py_ssize_t plen = 0;
+     uint16_t ogf, ocf;
+     char *param = NULL;
+     int dd = 0;
+@@ -2036,6 +2038,7 @@ bt_hci_send_req(PyObject *self, PyObject *args, PyObject *kwds)
+     int err;
+     int to=0;
+     char rparam[256];
++    Py_ssize_t req_clen;
+     struct hci_request req = { 0 };
+     int dd = 0;
+ 
+@@ -2043,9 +2046,10 @@ bt_hci_send_req(PyObject *self, PyObject *args, PyObject *kwds)
+                                 "timeout", 0 };
+ 
+     if( !PyArg_ParseTupleAndKeywords(args, kwds, "OHHii|s#i", keywords,
+-                &socko, &req.ogf, &req.ocf, &req.event, &req.rlen, 
+-                &req.cparam, &req.clen, &to) )
++                &socko, &req.ogf, &req.ocf, &req.event, &req.rlen,
++                &req.cparam, &req_clen, &to) )
+         return 0;
++    req.clen = req_clen;
+ 
+     req.rparam = rparam;
+     dd = socko->sock_fd;
+@@ -2274,7 +2278,8 @@ Returns the name of the device, or raises an error on failure");
+ static PyObject * bt_hci_filter_ ## name (PyObject *self, PyObject *args )\
+ { \
+     char *param; \
+-    int len, arg; \
++    Py_ssize_t len; \
++    int arg; \
+     if( !PyArg_ParseTuple(args,"s#i", &param, &len, &arg) ) \
+         return 0; \
+     if( len != sizeof(struct hci_filter) ) { \
+@@ -2303,7 +2308,7 @@ DECL_HCI_FILTER_OP_1(test_opcode, "test opcode!")
+ static PyObject * bt_hci_filter_ ## name (PyObject *self, PyObject *args )\
+ { \
+     char *param; \
+-    int len; \
++    Py_ssize_t len; \
+     if( !PyArg_ParseTuple(args,"s#", &param, &len) ) \
+         return 0; \
+     if( len != sizeof(struct hci_filter) ) { \
+@@ -2364,7 +2369,7 @@ static PyObject *
+ bt_ba2str(PyObject *self, PyObject *args)
+ {
+     char *data=NULL;
+-    int len=0;
++    Py_ssize_t len=0;
+     char ba_str[19] = {0};
+     if (!PyArg_ParseTuple(args, "s#", &data, &len)) return 0;
+     ba2str((bdaddr_t*)data, ba_str);
+@@ -2579,7 +2584,7 @@ bt_sdp_advertise_service( PyObject *self, PyObject *args )
+          *provider = NULL, 
+          *description = NULL;
+     PyObject *service_classes, *profiles, *protocols;
+-    int namelen = 0, provlen = 0, desclen = 0;
++    Py_ssize_t namelen = 0, provlen = 0, desclen = 0;
+     uuid_t svc_uuid = { 0 };
+     int i;
+     char addrbuf[256] = { 0 };
+diff --git a/msbt/_msbt.c b/msbt/_msbt.c
+index b3d27ff..81f5ee9 100644
+--- a/msbt/_msbt.c
++++ b/msbt/_msbt.c
+@@ -2,6 +2,8 @@
+ #define UNICODE
+ #endif
+ 
++#define PY_SSIZE_T_CLEAN 1
++
+ #include <winsock2.h>
+ #include <ws2bth.h>
+ #include <BluetoothAPIs.h>
+@@ -155,7 +157,7 @@ static PyObject *
+ msbt_bind(PyObject *self, PyObject *args)
+ {
+     wchar_t *addrstr = NULL;
+-    int addrstrlen = -1;
++    Py_ssize_t addrstrlen = -1;
+     int sockfd = -1;
+     int port = -1;
+     char buf[100] = { 0 };
+@@ -765,7 +767,7 @@ msbt_set_service_raw(PyObject *self, PyObject *args)
+     WSAESETSERVICEOP op;
+ 
+     char *record = NULL;
+-    int reclen = -1;
++    Py_ssize_t reclen = -1;
+     BTH_SET_SERVICE *si = NULL;
+     int silen = -1;
+     ULONG sdpVersion = BTH_SDP_VERSION;
+-- 
+2.34.1
+
diff --git a/meta-python/recipes-devtools/python/python3-pybluez_0.23.bb b/meta-python/recipes-devtools/python/python3-pybluez_0.23.bb
index b32f3a362..6a1df273a 100644
--- a/meta-python/recipes-devtools/python/python3-pybluez_0.23.bb
+++ b/meta-python/recipes-devtools/python/python3-pybluez_0.23.bb
@@ -7,6 +7,7 @@  DEPENDS = "bluez5"
 LICENSE = "GPL-2.0-only"
 LIC_FILES_CHKSUM = "file://COPYING;md5=8a71d0475d08eee76d8b6d0c6dbec543"
 
+SRC_URI += "file://0001-Use-Py_ssize_t-when-parsing-buffer-length-fix-426-42.patch"
 SRC_URI[md5sum] = "afbe8429bb82d2c46a3d0f5f4f898f9d"
 SRC_URI[sha256sum] = "c8f04d2e78951eaa9de486b4d49381704e8943d0a6e6e58f55fcd7b8582e90de"