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
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. */
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
26 extern PyObject
*PyInit_libvirtmod_lxc(void);
28 extern PyObject
*PyInit_cygvirtmod_lxc(void);
32 extern void initlibvirtmod_lxc(void);
34 extern void initcygvirtmod_lxc(void);
39 # define DEBUG_ERROR 1
43 # define DEBUG(fmt, ...) \
44 printf(fmt, __VA_ARGS__)
46 # define DEBUG(fmt, ...) \
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 /************************************************************************
61 ************************************************************************/
64 libvirt_lxc_virDomainLxcOpenNamespace(PyObject
*self ATTRIBUTE_UNUSED
,
68 PyObject
*pyobj_domain
;
74 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainLxcOpenNamespace",
75 &pyobj_domain
, &flags
))
77 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
81 LIBVIRT_BEGIN_ALLOW_THREADS
;
82 c_retval
= virDomainLxcOpenNamespace(domain
, &fdlist
, flags
);
83 LIBVIRT_END_ALLOW_THREADS
;
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
)
95 if (PyList_Append(py_retval
, item
) < 0) {
104 for (i
= 0; i
< c_retval
; i
++) {
105 VIR_FORCE_CLOSE(fdlist
[i
]);
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
,
140 PyInit_libvirtmod_lxc
142 PyInit_cygvirtmod_lxc
148 if (virInitialize() < 0)
151 module
= PyModule_Create(&moduledef
);
155 #else /* ! PY_MAJOR_VERSION > 2 */
164 if (virInitialize() < 0)
167 /* initialize the python extension module */
168 Py_InitModule((char *)
176 #endif /* ! PY_MAJOR_VERSION > 2 */