diff options
Diffstat (limited to 'libvirt-lxc-override.c')
-rw-r--r-- | libvirt-lxc-override.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c index 03b00b0..60b41d8 100644 --- a/libvirt-lxc-override.c +++ b/libvirt-lxc-override.c @@ -21,10 +21,18 @@ #include "libvirt-utils.h" #include "build/libvirt-lxc.h" -#ifndef __CYGWIN__ -extern void initlibvirtmod_lxc(void); +#if PY_MAJOR_VERSION > 2 +# ifndef __CYGWIN__ +extern PyObject *PyInit_libvirtmod_lxc(void); +# 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 @@ -110,30 +118,59 @@ static PyMethodDef libvirtLxcMethods[] = { {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION > 2 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +# ifndef __CYGWIN__ + "libvirtmod_lxc", +# else + "cygvirtmod_lxc", +# endif + NULL, + -1, + libvirtLxcMethods, + NULL, + NULL, + NULL, + NULL +}; + +PyObject * +# ifndef __CYGWIN__ +PyInit_libvirtmod_lxc +# else +PyInit_cygvirtmod_lxc +# 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_lxc -#else +# else initcygvirtmod_lxc -#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_lxc" -#else - "cygvirtmod_lxc" -#endif - , libvirtLxcMethods); - - initialized = 1; +# ifndef __CYGWIN__ + "libvirtmod_lxc", +# else + "cygvirtmod_lxc", +# endif + libvirtLxcMethods); } +#endif /* ! PY_MAJOR_VERSION > 2 */ |