Bump version to 1.2.8 for new dev cycle
[libvirt-python/ericb.git] / libvirt-lxc-override.c
blobba97551c66efc4922c4d9df5fe20d48d55c561e7
1 /*
2 * libvir.c: this modules implements the main part of the glue of the
3 * libvir library and the Python interpreter. It provides the
4 * entry points where an automatically generated stub is
5 * unpractical
7 * Copyright (C) 2012-2013 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
12 /* Horrible kludge to work around even more horrible name-space pollution
13 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
14 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
15 #undef HAVE_PTHREAD_H
17 #include <Python.h>
18 #include <libvirt/libvirt-lxc.h>
19 #include <libvirt/virterror.h>
20 #include "typewrappers.h"
21 #include "libvirt-utils.h"
22 #include "build/libvirt-lxc.h"
24 #if PY_MAJOR_VERSION > 2
25 # ifndef __CYGWIN__
26 extern PyObject *PyInit_libvirtmod_lxc(void);
27 # else
28 extern PyObject *PyInit_cygvirtmod_lxc(void);
29 # endif
30 #else
31 # ifndef __CYGWIN__
32 extern void initlibvirtmod_lxc(void);
33 # else
34 extern void initcygvirtmod_lxc(void);
35 # endif
36 #endif
38 #if 0
39 # define DEBUG_ERROR 1
40 #endif
42 #if DEBUG_ERROR
43 # define DEBUG(fmt, ...) \
44 printf(fmt, __VA_ARGS__)
45 #else
46 # define DEBUG(fmt, ...) \
47 do {} while (0)
48 #endif
50 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
51 is so common that we encapsulate it here. Now, each use is simply
52 return VIR_PY_NONE; */
53 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
54 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
55 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
57 /************************************************************************
58 * *
59 * Statistics *
60 * *
61 ************************************************************************/
63 static PyObject *
64 libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
65 PyObject *args) {
66 PyObject *py_retval;
67 virDomainPtr domain;
68 PyObject *pyobj_domain;
69 unsigned int flags;
70 int c_retval;
71 int *fdlist = NULL;
72 size_t i;
74 if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainLxcOpenNamespace",
75 &pyobj_domain, &flags))
76 return NULL;
77 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
79 if (domain == NULL)
80 return VIR_PY_NONE;
81 LIBVIRT_BEGIN_ALLOW_THREADS;
82 c_retval = virDomainLxcOpenNamespace(domain, &fdlist, flags);
83 LIBVIRT_END_ALLOW_THREADS;
85 if (c_retval < 0)
86 return VIR_PY_NONE;
88 py_retval = PyList_New(0);
89 for (i = 0; i < c_retval; i++) {
90 PyObject *item = NULL;
92 if ((item = libvirt_intWrap(fdlist[i])) == NULL)
93 goto error;
95 if (PyList_Append(py_retval, item) < 0) {
96 Py_DECREF(item);
97 goto error;
100 VIR_FREE(fdlist);
101 return py_retval;
103 error:
104 for (i = 0; i < c_retval; i++) {
105 VIR_FORCE_CLOSE(fdlist[i]);
107 VIR_FREE(fdlist);
108 return VIR_PY_NONE;
110 /************************************************************************
112 * The registration stuff *
114 ************************************************************************/
115 static PyMethodDef libvirtLxcMethods[] = {
116 #include "build/libvirt-lxc-export.c"
117 {(char *) "virDomainLxcOpenNamespace", libvirt_lxc_virDomainLxcOpenNamespace, METH_VARARGS, NULL},
118 {NULL, NULL, 0, NULL}
121 #if PY_MAJOR_VERSION > 2
122 static struct PyModuleDef moduledef = {
123 PyModuleDef_HEAD_INIT,
124 # ifndef __CYGWIN__
125 "libvirtmod_lxc",
126 # else
127 "cygvirtmod_lxc",
128 # endif
129 NULL,
131 libvirtLxcMethods,
132 NULL,
133 NULL,
134 NULL,
135 NULL
138 PyObject *
139 # ifndef __CYGWIN__
140 PyInit_libvirtmod_lxc
141 # else
142 PyInit_cygvirtmod_lxc
143 # endif
144 (void)
146 PyObject *module;
148 if (virInitialize() < 0)
149 return NULL;
151 module = PyModule_Create(&moduledef);
153 return module;
155 #else /* ! PY_MAJOR_VERSION > 2 */
156 void
157 # ifndef __CYGWIN__
158 initlibvirtmod_lxc
159 # else
160 initcygvirtmod_lxc
161 # endif
162 (void)
164 if (virInitialize() < 0)
165 return;
167 /* initialize the python extension module */
168 Py_InitModule((char *)
169 # ifndef __CYGWIN__
170 "libvirtmod_lxc",
171 # else
172 "cygvirtmod_lxc",
173 # endif
174 libvirtLxcMethods);
176 #endif /* ! PY_MAJOR_VERSION > 2 */