build: clean up stray files found by 'make distcheck'
[libvirt-python/ericb.git] / typewrappers.h
blobd871d3fcc7a8f43d4b4fd9ed5fdb4f5ed8efe4dd
1 /*
2 * libvirt_wrap.h: type wrappers for libvir python bindings
4 * Copyright (C) 2005, 2011-2012 Red Hat, Inc.
6 * Daniel Veillard <veillard@redhat.com>
7 */
9 #include <Python.h>
10 #include <stdbool.h>
11 #include <libvirt/libvirt.h>
12 #include <libvirt/virterror.h>
14 #ifdef __GNUC__
15 # ifdef ATTRIBUTE_UNUSED
16 # undef ATTRIBUTE_UNUSED
17 # endif
18 # ifndef ATTRIBUTE_UNUSED
19 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
20 # endif /* ATTRIBUTE_UNUSED */
21 #else
22 # define ATTRIBUTE_UNUSED
23 #endif
25 /* Work around really old python. */
26 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
27 typedef ssize_t Py_ssize_t;
28 #endif
30 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
31 (((PyvirConnect_Object *)(v))->obj))
33 typedef struct {
34 PyObject_HEAD
35 virConnectPtr obj;
36 } PyvirConnect_Object;
39 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
40 (((PyvirDomain_Object *)(v))->obj))
42 typedef struct {
43 PyObject_HEAD
44 virDomainPtr obj;
45 } PyvirDomain_Object;
48 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
49 (((PyvirNetwork_Object *)(v))->obj))
51 typedef struct {
52 PyObject_HEAD
53 virNetworkPtr obj;
54 } PyvirNetwork_Object;
57 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
58 (((PyvirInterface_Object *)(v))->obj))
60 typedef struct {
61 PyObject_HEAD
62 virInterfacePtr obj;
63 } PyvirInterface_Object;
66 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
67 (((PyvirStoragePool_Object *)(v))->obj))
69 typedef struct {
70 PyObject_HEAD
71 virStoragePoolPtr obj;
72 } PyvirStoragePool_Object;
75 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
76 (((PyvirStorageVol_Object *)(v))->obj))
78 typedef struct {
79 PyObject_HEAD
80 virStorageVolPtr obj;
81 } PyvirStorageVol_Object;
84 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
85 (((PyvirNodeDevice_Object *)(v))->obj))
87 typedef struct {
88 PyObject_HEAD
89 virNodeDevicePtr obj;
90 } PyvirNodeDevice_Object;
92 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
93 (((PyvirSecret_Object *)(v))->obj))
95 typedef struct {
96 PyObject_HEAD
97 virSecretPtr obj;
98 } PyvirSecret_Object;
100 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
101 (((PyvirNWFilter_Object *)(v))->obj))
103 typedef struct {
104 PyObject_HEAD
105 virNWFilterPtr obj;
106 } PyvirNWFilter_Object;
109 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
110 (((PyvirStream_Object *)(v))->obj))
112 typedef struct {
113 PyObject_HEAD
114 virStreamPtr obj;
115 } PyvirStream_Object;
118 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
119 (((PyvirDomainSnapshot_Object *)(v))->obj))
121 typedef struct {
122 PyObject_HEAD
123 virDomainSnapshotPtr obj;
124 } PyvirDomainSnapshot_Object;
127 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
128 (((PyvirEventHandleCallback_Object *)(v))->obj))
130 typedef struct {
131 PyObject_HEAD
132 virEventHandleCallback obj;
133 } PyvirEventHandleCallback_Object;
135 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
136 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
138 typedef struct {
139 PyObject_HEAD
140 virEventTimeoutCallback obj;
141 } PyvirEventTimeoutCallback_Object;
143 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
144 (((PyvirFreeCallback_Object *)(v))->obj))
146 typedef struct {
147 PyObject_HEAD
148 virFreeCallback obj;
149 } PyvirFreeCallback_Object;
151 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
152 (((PyvirVoidPtr_Object *)(v))->obj))
154 typedef struct {
155 PyObject_HEAD
156 void* obj;
157 } PyvirVoidPtr_Object;
159 PyObject * libvirt_intWrap(int val);
160 PyObject * libvirt_longWrap(long val);
161 PyObject * libvirt_ulongWrap(unsigned long val);
162 PyObject * libvirt_longlongWrap(long long val);
163 PyObject * libvirt_ulonglongWrap(unsigned long long val);
164 PyObject * libvirt_charPtrWrap(char *str);
165 PyObject * libvirt_charPtrSizeWrap(char *str, Py_ssize_t size);
166 PyObject * libvirt_constcharPtrWrap(const char *str);
167 int libvirt_intUnwrap(PyObject *obj, int *val);
168 int libvirt_uintUnwrap(PyObject *obj, unsigned int *val);
169 int libvirt_longUnwrap(PyObject *obj, long *val);
170 int libvirt_ulongUnwrap(PyObject *obj, unsigned long *val);
171 int libvirt_longlongUnwrap(PyObject *obj, long long *val);
172 int libvirt_ulonglongUnwrap(PyObject *obj, unsigned long long *val);
173 int libvirt_doubleUnwrap(PyObject *obj, double *val);
174 int libvirt_boolUnwrap(PyObject *obj, bool *val);
175 PyObject * libvirt_virConnectPtrWrap(virConnectPtr node);
176 PyObject * libvirt_virDomainPtrWrap(virDomainPtr node);
177 PyObject * libvirt_virNetworkPtrWrap(virNetworkPtr node);
178 PyObject * libvirt_virInterfacePtrWrap(virInterfacePtr node);
179 PyObject * libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node);
180 PyObject * libvirt_virStorageVolPtrWrap(virStorageVolPtr node);
181 PyObject * libvirt_virEventHandleCallbackWrap(virEventHandleCallback node);
182 PyObject * libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node);
183 PyObject * libvirt_virFreeCallbackWrap(virFreeCallback node);
184 PyObject * libvirt_virVoidPtrWrap(void* node);
185 PyObject * libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node);
186 PyObject * libvirt_virSecretPtrWrap(virSecretPtr node);
187 PyObject * libvirt_virNWFilterPtrWrap(virNWFilterPtr node);
188 PyObject * libvirt_virStreamPtrWrap(virStreamPtr node);
189 PyObject * libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node);
192 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
193 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
194 * can be used as a single statement, as in
195 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
197 * When GCC is compiling C code in non-ANSI mode, it will use the
198 * compiler __extension__ to wrap the statements within `({' and '})' braces.
199 * When compiling on platforms where configure has defined
200 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
201 * For any other platforms (SunOS4 is known to have this issue), wrap the
202 * statements with `if (1)' and `else (void) 0'.
204 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
205 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
206 # define LIBVIRT_STMT_START (void) __extension__ (
207 # define LIBVIRT_STMT_END )
208 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
209 # if defined (HAVE_DOWHILE_MACROS)
210 # define LIBVIRT_STMT_START do
211 # define LIBVIRT_STMT_END while (0)
212 # else /* !HAVE_DOWHILE_MACROS */
213 # define LIBVIRT_STMT_START if (1)
214 # define LIBVIRT_STMT_END else (void) 0
215 # endif /* !HAVE_DOWHILE_MACROS */
216 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
217 #endif
219 #define LIBVIRT_BEGIN_ALLOW_THREADS \
220 LIBVIRT_STMT_START { \
221 PyThreadState *_save = NULL; \
222 if (PyEval_ThreadsInitialized()) \
223 _save = PyEval_SaveThread();
225 #define LIBVIRT_END_ALLOW_THREADS \
226 if (PyEval_ThreadsInitialized()) \
227 PyEval_RestoreThread(_save); \
228 } LIBVIRT_STMT_END
230 #define LIBVIRT_ENSURE_THREAD_STATE \
231 LIBVIRT_STMT_START { \
232 PyGILState_STATE _save = PyGILState_UNLOCKED; \
233 if (PyEval_ThreadsInitialized()) \
234 _save = PyGILState_Ensure();
236 #define LIBVIRT_RELEASE_THREAD_STATE \
237 if (PyEval_ThreadsInitialized()) \
238 PyGILState_Release(_save); \
239 } LIBVIRT_STMT_END