Just like libvirt itself is able to work with both major version of python, libvirt-glib should do the same. Even the code I'm introducing here is copied from there (and changed slightly to reflect project name). Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- python/libvirt-glib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/python/libvirt-glib.c b/python/libvirt-glib.c index 1daca36..8b3920d 100644 --- a/python/libvirt-glib.c +++ b/python/libvirt-glib.c @@ -17,11 +17,19 @@ #include <glib.h> #include "libvirt-glib/libvirt-glib.h" +#if PY_MAJOR_VERSION > 2 +# ifndef __CYGWIN__ +extern PyObject *PyInit_libvirtglibmod(void); +# else +extern PyObject *PyInit_cygvirtglibmod(void); +# endif +#else #ifndef __CYGWIN__ extern void initlibvirtglibmod(void); #else extern void initcygvirtglibmod(void); #endif +#endif #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None) @@ -38,6 +46,41 @@ static PyMethodDef libvirtGLibMethods[] = { {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION > 2 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +# ifndef __CYGWIN__ + "libvirtglibmod", +# else + "cygvirtglibmod", +# endif + NULL, + -1, + libvirtGLibMethods, + NULL, + NULL, + NULL, + NULL +}; + +PyObject * +# ifndef __CYGWIN__ +PyInit_libvirtglibmod +# else +PyInit_cygvirtglibmod +# endif +(void) +{ + PyObject *module; + + if (gvir_init_check(NULL, NULL, NULL) < 0) + return NULL; + + module = PyModule_Create(&moduledef); + + return module; +} +#else /* ! PY_MAJOR_VERSION > 2 */ void #ifndef __CYGWIN__ initlibvirtglibmod @@ -57,3 +100,4 @@ initcygvirtglibmod , libvirtGLibMethods); } +#endif /* ! PY_MAJOR_VERSION > 2 */ -- 2.8.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list