1 Star 0 Fork 17

yezengruan/libvirt-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Fix-PY_SSIZE_T_CLEAN-deprecation-warning.patch 4.01 KB
一键复制 编辑 原始数据 按行查看 历史
imxcc 提交于 2022-01-11 10:49 . spec: use pytest instead of nose
From ccbe311a4bcb123933499126278ba48aab36427a Mon Sep 17 00:00:00 2001
From: Cole Robinson <crobinso@redhat.com>
Date: Sun, 5 Jul 2020 12:51:45 -0400
Subject: [PATCH 4/6] Fix PY_SSIZE_T_CLEAN deprecation warning
Seen running on fedora 32:
DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
ret = libvirtmod.virDomainLookupByUUID(self._o, uuid)
This comes from here: https://bugs.python.org/issue36381
See the section about PY_SSIZE_T_CLEAN here:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers
Solution is to use Py_ssize_t instead of int for unpacked '#' values,
combined with defined PY_SSIZE_T_CLEAN before importing Python.h. The
latter turns these deprecation warnings into runtime segfaults though
if we missed an instance.
I verified the virt-manager's test suite works fine after this change
Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
libvirt-override.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/libvirt-override.c b/libvirt-override.c
index 2b39ace..00efe7f 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -17,6 +17,7 @@
/* We want to see *_LAST enums. */
#define VIR_ENUM_SENTINELS
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
@@ -3040,7 +3041,7 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virDomainLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -3283,7 +3284,7 @@ libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -3992,7 +3993,7 @@ libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virStoragePoolLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -4233,7 +4234,7 @@ libvirt_virSecretLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virSecretLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -4393,7 +4394,7 @@ libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
virSecretPtr secret;
PyObject *pyobj_secret;
const char *value;
- int size;
+ Py_ssize_t size;
unsigned int flags;
if (!PyArg_ParseTuple(args, (char *)"Oz#I:virSecretSetValue", &pyobj_secret,
@@ -4402,8 +4403,8 @@ libvirt_virSecretSetValue(PyObject *self ATTRIBUTE_UNUSED,
secret = (virSecretPtr) PyvirSecret_Get(pyobj_secret);
LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virSecretSetValue(secret, (const unsigned char *)value, size,
- flags);
+ c_retval = virSecretSetValue(secret, (const unsigned char *)value,
+ (size_t) size, flags);
LIBVIRT_END_ALLOW_THREADS;
return libvirt_intWrap(c_retval);
@@ -4471,7 +4472,7 @@ libvirt_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virConnectPtr conn;
PyObject *pyobj_conn;
unsigned char * uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
&pyobj_conn, &uuid, &len))
@@ -10247,7 +10248,7 @@ libvirt_virNetworkPortLookupByUUID(PyObject *self ATTRIBUTE_UNUSED,
virNetworkPtr net;
PyObject *pyobj_net;
unsigned char *uuid;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkPortLookupByUUID",
&pyobj_net, &uuid, &len))
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yezengruan/libvirt-python.git
git@gitee.com:yezengruan/libvirt-python.git
yezengruan
libvirt-python
libvirt-python
master

搜索帮助