diff --git a/0001-Revert-Drop-support-for-python-2.patch b/0001-Revert-Drop-support-for-python-2.patch new file mode 100644 index 0000000000000000000000000000000000000000..b105dc06b965c0c2fb08d0ea984d8bede80799e4 --- /dev/null +++ b/0001-Revert-Drop-support-for-python-2.patch @@ -0,0 +1,879 @@ +From 82e72144b667f80eede9d9aa4ac450e4f8f365ac Mon Sep 17 00:00:00 2001 +From: FFrog +Date: Sun, 8 Aug 2021 16:36:39 +0800 +Subject: [PATCH] Revert "Drop support for python 2" + +This reverts commit b22e4f2441078aec048b9503fde2b45e78710ce1. +--- + examples/consolecallback.py | 2 +- + examples/dominfo.py | 2 +- + examples/domipaddrs.py | 2 +- + examples/domrestore.py | 2 +- + examples/domsave.py | 2 +- + examples/domstart.py | 2 +- + examples/esxlist.py | 2 +- + examples/event-test.py | 2 +- + examples/guest-vcpus/guest-vcpu-daemon.py | 2 +- + examples/guest-vcpus/guest-vcpu.py | 2 +- + examples/nodestats.py | 2 +- + examples/topology.py | 2 +- + generator.py | 2 +- + libvirt-lxc-override.c | 51 +++++++-- + libvirt-override.c | 51 +++++++-- + libvirt-qemu-override.c | 51 +++++++-- + libvirt-utils.c | 17 ++- + libvirt-utils.h | 6 +- + sanitytest.py | 2 +- + setup.py | 9 +- + typewrappers.c | 133 +++++++++++++++++++--- + typewrappers.h | 5 + + 26 files changed, 380 insertions(+), 71 deletions(-) + +diff --git a/examples/consolecallback.py b/examples/consolecallback.py +index 1347384..c539a92 100644 +--- a/examples/consolecallback.py ++++ b/examples/consolecallback.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # consolecallback - provide a persistent console that survives guest reboots + + import sys, os, logging, libvirt, tty, termios, atexit +diff --git a/examples/dominfo.py b/examples/dominfo.py +index 0a39f4c..d3049cd 100755 +--- a/examples/dominfo.py ++++ b/examples/dominfo.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # dominfo - print some information about a domain + + import libvirt +diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py +index bda308c..d6d5cac 100755 +--- a/examples/domipaddrs.py ++++ b/examples/domipaddrs.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # domipaddrs - print domain interfaces along with their MAC and IP addresses + + import libvirt +diff --git a/examples/domrestore.py b/examples/domrestore.py +index 96f4955..06fdfbc 100755 +--- a/examples/domrestore.py ++++ b/examples/domrestore.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # domstart - make sure a given domU is running, if not start it + + import libvirt +diff --git a/examples/domsave.py b/examples/domsave.py +index 4940cce..727217c 100755 +--- a/examples/domsave.py ++++ b/examples/domsave.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # domstart - make sure a given domU is running, if not start it + + import libvirt +diff --git a/examples/domstart.py b/examples/domstart.py +index 7ff6cb9..ce1b60c 100755 +--- a/examples/domstart.py ++++ b/examples/domstart.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # domstart - make sure a given domU is running, if not start it + + import libvirt +diff --git a/examples/esxlist.py b/examples/esxlist.py +index d86e064..0d47b00 100755 +--- a/examples/esxlist.py ++++ b/examples/esxlist.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # esxlist - list active domains of an ESX host and print some info. + # also demonstrates how to use the libvirt.openAuth() method + +diff --git a/examples/event-test.py b/examples/event-test.py +index fddef64..4458e22 100755 +--- a/examples/event-test.py ++++ b/examples/event-test.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # + # + # +diff --git a/examples/guest-vcpus/guest-vcpu-daemon.py b/examples/guest-vcpus/guest-vcpu-daemon.py +index 30fcb9c..c7c08a8 100755 +--- a/examples/guest-vcpus/guest-vcpu-daemon.py ++++ b/examples/guest-vcpus/guest-vcpu-daemon.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + + import libvirt + import threading +diff --git a/examples/guest-vcpus/guest-vcpu.py b/examples/guest-vcpus/guest-vcpu.py +index 479ec40..8faba87 100755 +--- a/examples/guest-vcpus/guest-vcpu.py ++++ b/examples/guest-vcpus/guest-vcpu.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + + import libvirt + import sys +diff --git a/examples/nodestats.py b/examples/nodestats.py +index ae2a442..c01dead 100755 +--- a/examples/nodestats.py ++++ b/examples/nodestats.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # Print some host NUMA node statistics + # + # Authors: +diff --git a/examples/topology.py b/examples/topology.py +index 197c87a..191669c 100755 +--- a/examples/topology.py ++++ b/examples/topology.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # Parse topology information from the capabilities XML and use + # them to calculate host topology + # +diff --git a/generator.py b/generator.py +index 426f007..ee53308 100755 +--- a/generator.py ++++ b/generator.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + # + # generate python wrappers from the XML API description + # +diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c +index 138ba5b..d7af154 100644 +--- a/libvirt-lxc-override.c ++++ b/libvirt-lxc-override.c +@@ -4,13 +4,13 @@ + * entry points where an automatically generated stub is + * unpractical + * +- * Copyright (C) 2012-2019 Red Hat, Inc. ++ * Copyright (C) 2012-2013 Red Hat, Inc. + * + * Daniel Veillard + */ + + /* Horrible kludge to work around even more horrible name-space pollution +- via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, ++ via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ + #undef HAVE_PTHREAD_H + +@@ -21,10 +21,18 @@ + #include "libvirt-utils.h" + #include "build/libvirt-lxc.h" + +-#ifndef __CYGWIN__ ++#if PY_MAJOR_VERSION > 2 ++# ifndef __CYGWIN__ + extern PyObject *PyInit_libvirtmod_lxc(void); +-#else ++# else + extern PyObject *PyInit_cygvirtmod_lxc(void); ++# endif ++#else ++# ifndef __CYGWIN__ ++extern void initlibvirtmod_lxc(void); ++# else ++extern void initcygvirtmod_lxc(void); ++# endif + #endif + + #if 0 +@@ -99,13 +107,14 @@ static PyMethodDef libvirtLxcMethods[] = { + {NULL, NULL, 0, NULL} + }; + ++#if PY_MAJOR_VERSION > 2 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + "libvirtmod_lxc", +-#else ++# else + "cygvirtmod_lxc", +-#endif ++# endif + NULL, + -1, + libvirtLxcMethods, +@@ -116,11 +125,11 @@ static struct PyModuleDef moduledef = { + }; + + PyObject * +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + PyInit_libvirtmod_lxc +-#else ++# else + PyInit_cygvirtmod_lxc +-#endif ++# endif + (void) + { + PyObject *module; +@@ -132,3 +141,25 @@ PyInit_cygvirtmod_lxc + + return module; + } ++#else /* ! PY_MAJOR_VERSION > 2 */ ++void ++# ifndef __CYGWIN__ ++initlibvirtmod_lxc ++# else ++initcygvirtmod_lxc ++# endif ++(void) ++{ ++ if (virInitialize() < 0) ++ return; ++ ++ /* initialize the python extension module */ ++ Py_InitModule((char *) ++# ifndef __CYGWIN__ ++ "libvirtmod_lxc", ++# else ++ "cygvirtmod_lxc", ++# endif ++ libvirtLxcMethods); ++} ++#endif /* ! PY_MAJOR_VERSION > 2 */ +diff --git a/libvirt-override.c b/libvirt-override.c +index 2b39ace..e48af21 100644 +--- a/libvirt-override.c ++++ b/libvirt-override.c +@@ -4,13 +4,13 @@ + * entry points where an automatically generated stub is + * unpractical + * +- * Copyright (C) 2005-2019 Red Hat, Inc. ++ * Copyright (C) 2005, 2007-2015 Red Hat, Inc. + * + * Daniel Veillard + */ + + /* Horrible kludge to work around even more horrible name-space pollution +- via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, ++ via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ + #undef HAVE_PTHREAD_H + +@@ -25,10 +25,18 @@ + #include "build/libvirt.h" + #include "libvirt-utils.h" + +-#ifndef __CYGWIN__ ++#if PY_MAJOR_VERSION > 2 ++# ifndef __CYGWIN__ + extern PyObject *PyInit_libvirtmod(void); +-#else ++# else + extern PyObject *PyInit_cygvirtmod(void); ++# endif ++#else ++# ifndef __CYGWIN__ ++extern void initlibvirtmod(void); ++# else ++extern void initcygvirtmod(void); ++# endif + #endif + + #if 0 +@@ -10628,13 +10636,14 @@ static PyMethodDef libvirtMethods[] = { + {NULL, NULL, 0, NULL} + }; + ++#if PY_MAJOR_VERSION > 2 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + "libvirtmod", +-#else ++# else + "cygvirtmod", +-#endif ++# endif + NULL, + -1, + libvirtMethods, +@@ -10645,11 +10654,11 @@ static struct PyModuleDef moduledef = { + }; + + PyObject * +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + PyInit_libvirtmod +-#else ++# else + PyInit_cygvirtmod +-#endif ++# endif + (void) + { + PyObject *module; +@@ -10661,3 +10670,25 @@ PyInit_cygvirtmod + + return module; + } ++#else /* ! PY_MAJOR_VERSION > 2 */ ++void ++# ifndef __CYGWIN__ ++initlibvirtmod ++# else ++initcygvirtmod ++# endif ++(void) ++{ ++ if (virInitialize() < 0) ++ return; ++ ++ /* initialize the python extension module */ ++ Py_InitModule((char *) ++# ifndef __CYGWIN__ ++ "libvirtmod", ++# else ++ "cygvirtmod", ++# endif ++ libvirtMethods); ++} ++#endif /* ! PY_MAJOR_VERSION > 2 */ +diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c +index 6ae95b4..f166f6e 100644 +--- a/libvirt-qemu-override.c ++++ b/libvirt-qemu-override.c +@@ -4,13 +4,13 @@ + * entry points where an automatically generated stub is + * unpractical + * +- * Copyright (C) 2011-2019 Red Hat, Inc. ++ * Copyright (C) 2011-2014 Red Hat, Inc. + * + * Daniel Veillard + */ + + /* Horrible kludge to work around even more horrible name-space pollution +- via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, ++ via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ + #undef HAVE_PTHREAD_H + +@@ -21,10 +21,18 @@ + #include "libvirt-utils.h" + #include "build/libvirt-qemu.h" + +-#ifndef __CYGWIN__ ++#if PY_MAJOR_VERSION > 2 ++# ifndef __CYGWIN__ + extern PyObject *PyInit_libvirtmod_qemu(void); +-#else ++# else + extern PyObject *PyInit_cygvirtmod_qemu(void); ++# endif ++#else ++# ifndef __CYGWIN__ ++extern void initlibvirtmod_qemu(void); ++# else ++extern void initcygvirtmod_qemu(void); ++# endif + #endif + + #if 0 +@@ -343,13 +351,14 @@ static PyMethodDef libvirtQemuMethods[] = { + {NULL, NULL, 0, NULL} + }; + ++#if PY_MAJOR_VERSION > 2 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + "libvirtmod_qemu", +-#else ++# else + "cygvirtmod_qemu", +-#endif ++# endif + NULL, + -1, + libvirtQemuMethods, +@@ -360,11 +369,11 @@ static struct PyModuleDef moduledef = { + }; + + PyObject * +-#ifndef __CYGWIN__ ++# ifndef __CYGWIN__ + PyInit_libvirtmod_qemu +-#else ++# else + PyInit_cygvirtmod_qemu +-#endif ++# endif + (void) + { + PyObject *module; +@@ -376,3 +385,25 @@ PyInit_cygvirtmod_qemu + + return module; + } ++#else /* ! PY_MAJOR_VERSION > 2 */ ++void ++# ifndef __CYGWIN__ ++initlibvirtmod_qemu ++# else ++initcygvirtmod_qemu ++# endif ++(void) ++{ ++ if (virInitialize() < 0) ++ return; ++ ++ /* initialize the python extension module */ ++ Py_InitModule((char *) ++# ifndef __CYGWIN__ ++ "libvirtmod_qemu", ++# else ++ "cygvirtmod_qemu", ++# endif ++ libvirtQemuMethods); ++} ++#endif /* ! PY_MAJOR_VERSION > 2 */ +diff --git a/libvirt-utils.c b/libvirt-utils.c +index d8ff11d..78b94ca 100644 +--- a/libvirt-utils.c ++++ b/libvirt-utils.c +@@ -1,7 +1,7 @@ + /* + * libvirt-utils.c: misc helper APIs for python binding + * +- * Copyright (C) 2013-2019 Red Hat, Inc. ++ * Copyright (C) 2013 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public +@@ -274,7 +274,11 @@ setPyVirTypedParameter(PyObject *info, + int nparams) + { + PyObject *key, *value; ++#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4 ++ int pos = 0; ++#else + Py_ssize_t pos = 0; ++#endif + virTypedParameterPtr temp = NULL, ret = NULL; + Py_ssize_t size; + ssize_t i; +@@ -412,6 +416,13 @@ virPyDictToTypedParamOne(virTypedParameterPtr *params, + type = VIR_TYPED_PARAM_LLONG; + else + type = VIR_TYPED_PARAM_ULLONG; ++#if PY_MAJOR_VERSION < 3 ++ } else if (PyInt_Check(value)) { ++ if (PyInt_AS_LONG(value) < 0) ++ type = VIR_TYPED_PARAM_LLONG; ++ else ++ type = VIR_TYPED_PARAM_ULLONG; ++#endif + } else if (PyFloat_Check(value)) { + type = VIR_TYPED_PARAM_DOUBLE; + } +@@ -509,7 +520,11 @@ virPyDictToTypedParams(PyObject *dict, + { + PyObject *key; + PyObject *value; ++#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4 ++ int pos = 0; ++#else + Py_ssize_t pos = 0; ++#endif + virTypedParameterPtr params = NULL; + int n = 0; + int max = 0; +diff --git a/libvirt-utils.h b/libvirt-utils.h +index 82f0af8..cc3d278 100644 +--- a/libvirt-utils.h ++++ b/libvirt-utils.h +@@ -139,7 +139,11 @@ int virReallocN(void *ptrptr, size_t size, size_t count) + void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); + + +-# define libvirt_PyString_Check PyUnicode_Check ++# if PY_MAJOR_VERSION > 2 ++# define libvirt_PyString_Check PyUnicode_Check ++# else ++# define libvirt_PyString_Check PyString_Check ++# endif + + + #define VIR_N_ELEMENTS(array) (sizeof(array) / sizeof(*(array))) +diff --git a/sanitytest.py b/sanitytest.py +index 1bedd55..0b415fd 100644 +--- a/sanitytest.py ++++ b/sanitytest.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + + import sys + import lxml +diff --git a/setup.py b/setup.py +index 56b6eea..187b21a 100755 +--- a/setup.py ++++ b/setup.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python + + from distutils.core import setup, Extension, Command + from distutils.command.build import build +@@ -17,10 +17,6 @@ import re + import shutil + import time + +-if sys.version_info[0] != 3: +- print("libvirt-python requires Python 3.x to build") +- sys.exit(1) +- + MIN_LIBVIRT = "0.9.11" + MIN_LIBVIRT_LXC = "1.0.2" + +@@ -346,7 +342,7 @@ setup(name = 'libvirt-python', + description = 'The libvirt virtualization API python binding', + long_description = + '''The libvirt-python package provides a module that permits applications +-written in the Python 3.x programming language to call the interface ++written in the Python programming language to call the interface + supplied by the libvirt library, to manage the virtualization capabilities + of recent versions of Linux (and other OSes).''', + license = 'LGPLv2+', +@@ -367,6 +363,7 @@ of recent versions of Linux (and other OSes).''', + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", + "Programming Language :: Python", ++ "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + ] + ) +diff --git a/typewrappers.c b/typewrappers.c +index 3b1df87..2507859 100644 +--- a/typewrappers.c ++++ b/typewrappers.c +@@ -2,88 +2,141 @@ + * types.c: converter functions between the internal representation + * and the Python objects + * +- * Copyright (C) 2005-2019 Red Hat, Inc. ++ * Copyright (C) 2005, 2007, 2012 Red Hat, Inc. + * + * Daniel Veillard + */ + + /* Horrible kludge to work around even more horrible name-space pollution +- * via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, +- * which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ ++ * via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, ++ * which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ + #undef HAVE_PTHREAD_H + + #include "typewrappers.h" + #include "libvirt-utils.h" + ++#ifndef Py_CAPSULE_H ++typedef void(*PyCapsule_Destructor)(void *, void *); ++#endif ++ + static PyObject * + libvirt_buildPyObject(void *cobj, + const char *name, + PyCapsule_Destructor destr) + { +- return PyCapsule_New(cobj, name, destr); ++ PyObject *ret; ++ ++#ifdef Py_CAPSULE_H ++ ret = PyCapsule_New(cobj, name, destr); ++#else ++ ret = PyCObject_FromVoidPtrAndDesc(cobj, (void *) name, destr); ++#endif /* _TEST_CAPSULE */ ++ ++ return ret; + } + + PyObject * + libvirt_intWrap(int val) + { +- return PyLong_FromLong((long) val); ++ PyObject *ret; ++#if PY_MAJOR_VERSION > 2 ++ ret = PyLong_FromLong((long) val); ++#else ++ ret = PyInt_FromLong((long) val); ++#endif ++ return ret; + } + + PyObject * + libvirt_uintWrap(uint val) + { +- return PyLong_FromLong((long) val); ++ PyObject *ret; ++#if PY_MAJOR_VERSION > 2 ++ ret = PyLong_FromLong((long) val); ++#else ++ ret = PyInt_FromLong((long) val); ++#endif ++ return ret; + } + + PyObject * + libvirt_longWrap(long val) + { +- return PyLong_FromLong(val); ++ PyObject *ret; ++ ret = PyLong_FromLong(val); ++ return ret; + } + + PyObject * + libvirt_ulongWrap(unsigned long val) + { +- return PyLong_FromLong(val); ++ PyObject *ret; ++ ret = PyLong_FromLong(val); ++ return ret; + } + + PyObject * + libvirt_longlongWrap(long long val) + { +- return PyLong_FromLongLong(val); ++ PyObject *ret; ++ ret = PyLong_FromLongLong(val); ++ return ret; + } + + PyObject * + libvirt_ulonglongWrap(unsigned long long val) + { +- return PyLong_FromUnsignedLongLong(val); ++ PyObject *ret; ++ ret = PyLong_FromUnsignedLongLong(val); ++ return ret; + } + + PyObject * + libvirt_charPtrSizeWrap(char *str, Py_ssize_t size) + { ++ PyObject *ret; ++ + if (str == NULL) { + return VIR_PY_NONE; + } +- return PyBytes_FromStringAndSize(str, size); ++#if PY_MAJOR_VERSION > 2 ++ ret = PyBytes_FromStringAndSize(str, size); ++#else ++ ret = PyString_FromStringAndSize(str, size); ++#endif ++ return ret; + } + + PyObject * + libvirt_charPtrWrap(char *str) + { ++ PyObject *ret; ++ + if (str == NULL) { + return VIR_PY_NONE; + } +- return PyUnicode_FromString(str); ++#if PY_MAJOR_VERSION > 2 ++ ret = PyUnicode_FromString(str); ++#else ++ ret = PyString_FromString(str); ++#endif ++ return ret; + } + + PyObject * + libvirt_constcharPtrWrap(const char *str) + { ++ PyObject *ret; ++ + if (str == NULL) { + return VIR_PY_NONE; + } +- return PyUnicode_FromString(str); ++#if PY_MAJOR_VERSION > 2 ++ ret = PyUnicode_FromString(str); ++#else ++ ret = PyString_FromString(str); ++#endif ++ return ret; + } + + PyObject * +@@ -110,7 +163,11 @@ libvirt_intUnwrap(PyObject *obj, + * to C long type directly. If it is of PyLong_Type, PyInt_AsLong + * will call PyLong_AsLong() to deal with it automatically. + */ ++#if PY_MAJOR_VERSION > 2 + long_val = PyLong_AsLong(obj); ++#else ++ long_val = PyInt_AsLong(obj); ++#endif + if ((long_val == -1) && PyErr_Occurred()) + return -1; + +@@ -139,7 +196,11 @@ libvirt_uintUnwrap(PyObject *obj, + return -1; + } + ++#if PY_MAJOR_VERSION > 2 + long_val = PyLong_AsLong(obj); ++#else ++ long_val = PyInt_AsLong(obj); ++#endif + if ((long_val == -1) && PyErr_Occurred()) + return -1; + +@@ -208,7 +269,14 @@ libvirt_longlongUnwrap(PyObject *obj, + return -1; + } + ++#if PY_MAJOR_VERSION == 2 ++ /* If obj is of PyInt_Type, PyLong_AsLongLong ++ * will call PyInt_AsLong() to handle it automatically. ++ */ ++ if (PyInt_Check(obj) || PyLong_Check(obj)) ++#else + if (PyLong_Check(obj)) ++#endif + llong_val = PyLong_AsLongLong(obj); + else + PyErr_SetString(PyExc_TypeError, "an integer is required"); +@@ -231,7 +299,21 @@ libvirt_ulonglongUnwrap(PyObject *obj, + return -1; + } + ++#if PY_MAJOR_VERSION == 2 ++ /* The PyLong_AsUnsignedLongLong doesn't check the type of ++ * obj, only accept argument of PyLong_Type, so we check it instead. ++ */ ++ if (PyInt_Check(obj)) { ++ long long llong_val = PyInt_AsLong(obj); ++ if (llong_val < 0) ++ PyErr_SetString(PyExc_OverflowError, ++ "negative Python int cannot be converted to C unsigned long long"); ++ else ++ ullong_val = llong_val; ++ } else if (PyLong_Check(obj)) { ++#else + if (PyLong_Check(obj)) { ++#endif + ullong_val = PyLong_AsUnsignedLongLong(obj); + } else { + PyErr_SetString(PyExc_TypeError, "an integer is required"); +@@ -285,7 +367,9 @@ int + libvirt_charPtrUnwrap(PyObject *obj, + char **str) + { ++#if PY_MAJOR_VERSION > 2 + PyObject *bytes; ++#endif + const char *ret; + *str = NULL; + if (!obj) { +@@ -293,15 +377,21 @@ libvirt_charPtrUnwrap(PyObject *obj, + return -1; + } + ++#if PY_MAJOR_VERSION > 2 + if (!(bytes = PyUnicode_AsUTF8String(obj))) + return -1; + ret = PyBytes_AsString(bytes); ++#else ++ ret = PyString_AsString(obj); ++#endif + if (ret) { + *str = strdup(ret); + if (!*str) + PyErr_NoMemory(); + } ++#if PY_MAJOR_VERSION > 2 + Py_DECREF(bytes); ++#endif + return ret && *str ? 0 : -1; + } + +@@ -310,6 +400,10 @@ libvirt_charPtrSizeUnwrap(PyObject *obj, + char **str, + Py_ssize_t *size) + { ++ int ret; ++#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4 ++ int isize; ++#endif + *str = NULL; + *size = 0; + if (!obj) { +@@ -317,7 +411,18 @@ libvirt_charPtrSizeUnwrap(PyObject *obj, + return -1; + } + +- return PyBytes_AsStringAndSize(obj, str, size); ++#if PY_MAJOR_VERSION > 2 ++ ret = PyBytes_AsStringAndSize(obj, str, size); ++#else ++# if PY_MINOR_VERSION <= 4 ++ ret = PyString_AsStringAndSize(obj, str, &isize); ++ *size = isize; ++# else ++ ret = PyString_AsStringAndSize(obj, str, size); ++# endif ++#endif ++ ++ return ret; + } + + PyObject * +diff --git a/typewrappers.h b/typewrappers.h +index fc923bf..486017a 100644 +--- a/typewrappers.h ++++ b/typewrappers.h +@@ -22,6 +22,11 @@ + # define ATTRIBUTE_UNUSED + #endif + ++/* Work around really old python. */ ++#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 ++typedef ssize_t Py_ssize_t; ++#endif ++ + #if !LIBVIR_CHECK_VERSION(4, 5, 0) + typedef struct _virNWFilterBinding *virNWFilterBindingPtr; + #endif +-- +2.27.0 + diff --git a/libvirt-python-6.2.0.tar b/libvirt-python-6.2.0.tar deleted file mode 100644 index 65d3ede722ffc68939f757adf920b8cc76c04f8d..0000000000000000000000000000000000000000 Binary files a/libvirt-python-6.2.0.tar and /dev/null differ diff --git a/libvirt-python-6.2.0.tar.gz b/libvirt-python-6.2.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..3e9bcc8daf4fccfafc9dd015792dced3d189a634 Binary files /dev/null and b/libvirt-python-6.2.0.tar.gz differ diff --git a/libvirt-python.spec b/libvirt-python.spec index 8d47f9a5407f3d4c8db2d7466f02f9e7c41dd3eb..19491b690f4af23de250c48718ab0e762a118392 100644 --- a/libvirt-python.spec +++ b/libvirt-python.spec @@ -6,9 +6,10 @@ Name: libvirt-python Version: 6.2.0 -Release: 2 +Release: 3 Summary: The libvirt virtualization API python2 binding -Source0: libvirt-python-6.2.0.tar +Source0: libvirt-python-6.2.0.tar.gz +Patch0: 0001-Revert-Drop-support-for-python-2.patch Url: http://libvirt.org License: LGPLv2+ BuildRequires: libvirt-devel == %{version} @@ -78,7 +79,7 @@ of recent versions of Linux (and other OSes). %endif %prep -%setup -q +%autosetup -p1 find examples -type f -exec chmod 0644 \{\} \; @@ -131,6 +132,8 @@ find examples -type f -exec chmod 0644 \{\} \; %endif %changelog +* Sun Aug 8 2021 openstack-sig +- Fix python2 support for libvirt-python * Mon May 24 2021 openstack-sig - Delete needless definition * Mon May 24 2021 openstack-sig