python: Use a pure python implementation of 'vir*GetConnect'
[libvirt-python/ericb.git] / typewrappers.c
blob9ba99de0dbd78cb69ddbaa25f98be999ff704330
1 /*
2 * types.c: converter functions between the internal representation
3 * and the Python objects
5 * Copyright (C) 2005, 2007 Red Hat, Inc.
7 * Daniel Veillard <veillard@redhat.com>
8 */
10 #include <config.h>
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 "typewrappers.h"
19 PyObject *
20 libvirt_intWrap(int val)
22 PyObject *ret;
23 ret = PyInt_FromLong((long) val);
24 return (ret);
27 PyObject *
28 libvirt_longWrap(long val)
30 PyObject *ret;
31 ret = PyInt_FromLong(val);
32 return (ret);
35 PyObject *
36 libvirt_ulongWrap(unsigned long val)
38 PyObject *ret;
39 ret = PyLong_FromLong(val);
40 return (ret);
43 PyObject *
44 libvirt_longlongWrap(long long val)
46 PyObject *ret;
47 ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
48 return (ret);
51 PyObject *
52 libvirt_charPtrWrap(char *str)
54 PyObject *ret;
56 if (str == NULL) {
57 Py_INCREF(Py_None);
58 return (Py_None);
60 ret = PyString_FromString(str);
61 free(str);
62 return (ret);
65 PyObject *
66 libvirt_constcharPtrWrap(const char *str)
68 PyObject *ret;
70 if (str == NULL) {
71 Py_INCREF(Py_None);
72 return (Py_None);
74 ret = PyString_FromString(str);
75 return (ret);
78 PyObject *
79 libvirt_charPtrConstWrap(const char *str)
81 PyObject *ret;
83 if (str == NULL) {
84 Py_INCREF(Py_None);
85 return (Py_None);
87 ret = PyString_FromString(str);
88 return (ret);
91 PyObject *
92 libvirt_virDomainPtrWrap(virDomainPtr node)
94 PyObject *ret;
96 if (node == NULL) {
97 Py_INCREF(Py_None);
98 return (Py_None);
100 ret =
101 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainPtr",
102 NULL);
103 return (ret);
106 PyObject *
107 libvirt_virNetworkPtrWrap(virNetworkPtr node)
109 PyObject *ret;
111 if (node == NULL) {
112 Py_INCREF(Py_None);
113 return (Py_None);
115 ret =
116 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr",
117 NULL);
118 return (ret);
121 PyObject *
122 libvirt_virInterfacePtrWrap(virInterfacePtr node)
124 PyObject *ret;
126 if (node == NULL) {
127 Py_INCREF(Py_None);
128 return (Py_None);
130 ret =
131 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virInterfacePtr",
132 NULL);
133 return (ret);
136 PyObject *
137 libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
139 PyObject *ret;
141 if (node == NULL) {
142 Py_INCREF(Py_None);
143 return (Py_None);
145 ret =
146 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStoragePoolPtr",
147 NULL);
148 return (ret);
151 PyObject *
152 libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
154 PyObject *ret;
156 if (node == NULL) {
157 Py_INCREF(Py_None);
158 return (Py_None);
160 ret =
161 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStorageVolPtr",
162 NULL);
163 return (ret);
166 PyObject *
167 libvirt_virConnectPtrWrap(virConnectPtr node)
169 PyObject *ret;
171 if (node == NULL) {
172 Py_INCREF(Py_None);
173 return (Py_None);
175 ret =
176 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virConnectPtr",
177 NULL);
178 return (ret);
181 PyObject *
182 libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
184 PyObject *ret;
186 if (node == NULL) {
187 Py_INCREF(Py_None);
188 return (Py_None);
190 ret =
191 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr",
192 NULL);
193 return (ret);
196 PyObject *
197 libvirt_virSecretPtrWrap(virSecretPtr node)
199 PyObject *ret;
201 if (node == NULL) {
202 Py_INCREF(Py_None);
203 return Py_None;
205 ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virSecretPtr", NULL);
206 return (ret);
209 PyObject *
210 libvirt_virStreamPtrWrap(virStreamPtr node)
212 PyObject *ret;
214 if (node == NULL) {
215 Py_INCREF(Py_None);
216 return Py_None;
218 ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virStreamPtr", NULL);
219 return (ret);
222 PyObject *
223 libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
225 PyObject *ret;
227 if (node == NULL) {
228 Py_INCREF(Py_None);
229 printf("%s: WARNING - Wrapping None\n", __func__);
230 return (Py_None);
232 ret =
233 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback",
234 NULL);
235 return (ret);
238 PyObject *
239 libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
241 PyObject *ret;
243 if (node == NULL) {
244 printf("%s: WARNING - Wrapping None\n", __func__);
245 Py_INCREF(Py_None);
246 return (Py_None);
248 ret =
249 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
250 NULL);
251 return (ret);
254 PyObject *
255 libvirt_virFreeCallbackWrap(virFreeCallback node)
257 PyObject *ret;
259 if (node == NULL) {
260 Py_INCREF(Py_None);
261 return (Py_None);
263 ret =
264 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
265 NULL);
266 return (ret);
269 PyObject *
270 libvirt_virVoidPtrWrap(void* node)
272 PyObject *ret;
274 if (node == NULL) {
275 Py_INCREF(Py_None);
276 return (Py_None);
278 ret =
279 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*",
280 NULL);
281 return (ret);