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 /************************************************************************
54 ************************************************************************/
57 libvirt_lxc_virDomainLxcOpenNamespace(PyObject
*self ATTRIBUTE_UNUSED
,
62 PyObject
*pyobj_domain
;
68 if (!PyArg_ParseTuple(args
, (char *)"OI:virDomainLxcOpenNamespace",
69 &pyobj_domain
, &flags
))
71 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
75 LIBVIRT_BEGIN_ALLOW_THREADS
;
76 c_retval
= virDomainLxcOpenNamespace(domain
, &fdlist
, flags
);
77 LIBVIRT_END_ALLOW_THREADS
;
82 if ((py_retval
= PyList_New(0)) == NULL
)
85 for (i
= 0; i
< c_retval
; i
++)
86 VIR_PY_LIST_APPEND_GOTO(py_retval
, libvirt_intWrap(fdlist
[i
]), error
);
93 for (i
= 0; i
< c_retval
; i
++) {
94 VIR_FORCE_CLOSE(fdlist
[i
]);
99 /************************************************************************
101 * The registration stuff *
103 ************************************************************************/
104 static PyMethodDef libvirtLxcMethods
[] = {
105 #include "build/libvirt-lxc-export.c"
106 {(char *) "virDomainLxcOpenNamespace", libvirt_lxc_virDomainLxcOpenNamespace
, METH_VARARGS
, NULL
},
107 {NULL
, NULL
, 0, NULL
}
110 #if PY_MAJOR_VERSION > 2
111 static struct PyModuleDef moduledef
= {
112 PyModuleDef_HEAD_INIT
,
129 PyInit_libvirtmod_lxc
131 PyInit_cygvirtmod_lxc
137 if (virInitialize() < 0)
140 module
= PyModule_Create(&moduledef
);
144 #else /* ! PY_MAJOR_VERSION > 2 */
153 if (virInitialize() < 0)
156 /* initialize the python extension module */
157 Py_InitModule((char *)
165 #endif /* ! PY_MAJOR_VERSION > 2 */