Fix building python bindings: Skip bindings for virSaveLastError and
[libvirt-python/ericb.git] / types.c
blob7981f802baa4b7105ec7971313b884c1f6af130d
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 "libvirt_wrap.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_virStoragePoolPtrWrap(virStoragePoolPtr 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 *) "virStoragePoolPtr",
132 NULL);
133 return (ret);
136 PyObject *
137 libvirt_virStorageVolPtrWrap(virStorageVolPtr 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 *) "virStorageVolPtr",
147 NULL);
148 return (ret);
151 PyObject *
152 libvirt_virConnectPtrWrap(virConnectPtr 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 *) "virConnectPtr",
162 NULL);
163 return (ret);
166 PyObject *
167 libvirt_virNodeDevicePtrWrap(virNodeDevicePtr 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 *) "virNodeDevicePtr",
177 NULL);
178 return (ret);
181 PyObject *
182 libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
184 PyObject *ret;
186 if (node == NULL) {
187 Py_INCREF(Py_None);
188 printf("%s: WARNING - Wrapping None\n", __func__);
189 return (Py_None);
191 ret =
192 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback",
193 NULL);
194 return (ret);
197 PyObject *
198 libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
200 PyObject *ret;
202 if (node == NULL) {
203 printf("%s: WARNING - Wrapping None\n", __func__);
204 Py_INCREF(Py_None);
205 return (Py_None);
207 ret =
208 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
209 NULL);
210 return (ret);
213 PyObject *
214 libvirt_virFreeCallbackWrap(virFreeCallback node)
216 PyObject *ret;
218 if (node == NULL) {
219 Py_INCREF(Py_None);
220 return (Py_None);
222 ret =
223 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
224 NULL);
225 return (ret);
228 PyObject *
229 libvirt_virVoidPtrWrap(void* node)
231 PyObject *ret;
233 if (node == NULL) {
234 Py_INCREF(Py_None);
235 return (Py_None);
237 ret =
238 PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*",
239 NULL);
240 return (ret);