summaryrefslogtreecommitdiff
path: root/libvirt-lxc-override.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2013-12-03 15:42:49 +0000
committerDaniel P. Berrange <berrange@redhat.com>2013-12-11 16:12:54 +0000
commit1b4dc721405040a979666f2abeb311f1bb9fbed7 (patch)
tree7d53f7785d09214d43877b4461a524c119afbb1c /libvirt-lxc-override.c
parentb882ae9ecf0cb4c5e1d6a429a9581106bfbcefd4 (diff)
downloadlibvirt-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-lxc-override.c')
-rw-r--r--libvirt-lxc-override.c73
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 */