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>
14 /* Horrible kludge to work around even more horrible name-space pollution
15 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
16 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
20 #include "libvirt/libvirt-lxc.h"
21 #include "libvirt/virterror.h"
22 #include "typewrappers.h"
23 #include "libvirt-lxc.h"
28 extern void initlibvirtmod_lxc(void);
30 extern void initcygvirtmod_lxc(void);
34 # define DEBUG_ERROR 1
38 # define DEBUG(fmt, ...) \
39 printf(fmt, __VA_ARGS__)
41 # define DEBUG(fmt, ...) \
45 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
46 is so common that we encapsulate it here. Now, each use is simply
47 return VIR_PY_NONE; */
48 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
49 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
50 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
52 /************************************************************************
56 ************************************************************************/
59 libvirt_lxc_virDomainLxcOpenNamespace(PyObject
*self ATTRIBUTE_UNUSED
,
63 PyObject
*pyobj_domain
;
69 if (!PyArg_ParseTuple(args
, (char *)"Oi:virDomainLxcOpenNamespace",
70 &pyobj_domain
, &flags
))
72 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
76 LIBVIRT_BEGIN_ALLOW_THREADS
;
77 c_retval
= virDomainLxcOpenNamespace(domain
, &fdlist
, flags
);
78 LIBVIRT_END_ALLOW_THREADS
;
83 py_retval
= PyList_New(c_retval
);
84 for (i
= 0 ; i
< c_retval
; i
++) {
85 PyObject
*item
= NULL
;
87 if ((item
= PyInt_FromLong(fdlist
[i
])) == NULL
)
90 if (PyList_Append(py_retval
, item
) < 0) {
98 for (i
= 0 ; i
< c_retval
; i
++) {
99 VIR_FORCE_CLOSE(fdlist
[i
]);
104 /************************************************************************
106 * The registration stuff *
108 ************************************************************************/
109 static PyMethodDef libvirtLxcMethods
[] = {
110 #include "libvirt-lxc-export.c"
111 {(char *) "virDomainLxcOpenNamespace", libvirt_lxc_virDomainLxcOpenNamespace
, METH_VARARGS
, NULL
},
112 {NULL
, NULL
, 0, NULL
}
123 static int initialized
= 0;
125 if (initialized
!= 0)
128 if (virInitialize() < 0)
131 /* initialize the python extension module */
132 Py_InitModule((char *)
138 , libvirtLxcMethods
);