diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-12-03 15:42:49 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-12-11 16:12:54 +0000 |
commit | 1b4dc721405040a979666f2abeb311f1bb9fbed7 (patch) | |
tree | 7d53f7785d09214d43877b4461a524c119afbb1c /libvirt-qemu-override.c | |
parent | b882ae9ecf0cb4c5e1d6a429a9581106bfbcefd4 (diff) | |
download | libvirt-python-1b4dc721405040a979666f2abeb311f1bb9fbed7.tar.gz |
override: Fix native module registration to work with Python3
The way native modules are registered has completely
changed, so the code must be #ifdef'd for Python2 & 3
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'libvirt-qemu-override.c')
-rw-r--r-- | libvirt-qemu-override.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index a8e8c09..72257ac 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -21,10 +21,18 @@ #include "libvirt-utils.h" #include "build/libvirt-qemu.h" -#ifndef __CYGWIN__ -extern void initlibvirtmod_qemu(void); +#if PY_MAJOR_VERSION > 2 +# ifndef __CYGWIN__ +extern PyObject *PyInit_libvirtmod_qemu(void); +# 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 @@ -128,30 +136,59 @@ static PyMethodDef libvirtQemuMethods[] = { {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION > 2 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +# ifndef __CYGWIN__ + "libvirtmod_qemu", +# else + "cygvirtmod_qemu", +# endif + NULL, + -1, + libvirtQemuMethods, + NULL, + NULL, + NULL, + NULL +}; + +PyObject * +# ifndef __CYGWIN__ +PyInit_libvirtmod_qemu +# else +PyInit_cygvirtmod_qemu +# endif + (void) +{ + PyObject *module; + + if (virInitialize() < 0) + return NULL; + + module = PyModule_Create(&moduledef); + + return module; +} +#else /* ! PY_MAJOR_VERSION > 2 */ void -#ifndef __CYGWIN__ +# ifndef __CYGWIN__ initlibvirtmod_qemu -#else +# else initcygvirtmod_qemu -#endif +# endif (void) { - static int initialized = 0; - - if (initialized != 0) - return; - if (virInitialize() < 0) return; /* initialize the python extension module */ Py_InitModule((char *) -#ifndef __CYGWIN__ - "libvirtmod_qemu" -#else - "cygvirtmod_qemu" -#endif - , libvirtQemuMethods); - - initialized = 1; +# ifndef __CYGWIN__ + "libvirtmod_qemu", +# else + "cygvirtmod_qemu", +# endif + libvirtQemuMethods); } +#endif /* ! PY_MAJOR_VERSION > 2 */ |