From a7d71b769d8e3d59515d1b9517ec5d4e0214b743 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Tue, 22 Sep 2015 10:33:57 +0200 Subject: Move utils and shared code into libvirt-utils Signed-off-by: Pavel Hrdina --- libvirt-utils.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'libvirt-utils.h') diff --git a/libvirt-utils.h b/libvirt-utils.h index bef5489..9f80133 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -22,6 +22,9 @@ #ifndef __LIBVIRT_UTILS_H__ # define __LIBVIRT_UTILS_H__ +# include +# include + # define STREQ(a,b) (strcmp(a,b) == 0) # ifndef MIN @@ -135,6 +138,22 @@ int virReallocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); + +# if PY_MAJOR_VERSION > 2 +# define libvirt_PyString_Check PyUnicode_Check +# else +# define libvirt_PyString_Check PyString_Check +# endif + + +/* The two-statement sequence "Py_INCREF(Py_None); return Py_None;" + is so common that we encapsulate it here. Now, each use is simply + return VIR_PY_NONE; */ +#define VIR_PY_NONE (Py_INCREF (Py_None), Py_None) +#define VIR_PY_INT_FAIL (libvirt_intWrap(-1)) +#define VIR_PY_INT_SUCCESS (libvirt_intWrap(0)) + + /** * VIR_ALLOC: * @ptr: pointer to hold address of allocated memory @@ -216,4 +235,36 @@ void virTypedParamsClear(virTypedParameterPtr params, int nparams); void virTypedParamsFree(virTypedParameterPtr params, int nparams); # endif /* ! LIBVIR_CHECK_VERSION(1, 0, 2) */ +char * py_str(PyObject *obj); +PyObject * getPyVirTypedParameter(const virTypedParameter *params, + int nparams); +virTypedParameterPtr setPyVirTypedParameter(PyObject *info, + const virTypedParameter *params, + int nparams) +ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + + +# if LIBVIR_CHECK_VERSION(1, 1, 0) +typedef struct { + const char *name; + int type; +} virPyTypedParamsHint; +typedef virPyTypedParamsHint *virPyTypedParamsHintPtr; + + +int virPyDictToTypedPramaOne(virTypedParameterPtr *params, + int *n, + int *max, + virPyTypedParamsHintPtr hints, + int nhints, + const char *keystr, + PyObject *value); +int virPyDictToTypedParams(PyObject *dict, + virTypedParameterPtr *ret_params, + int *ret_nparams, + virPyTypedParamsHintPtr hints, + int nhints) +ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +# endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */ + #endif /* __LIBVIRT_UTILS_H__ */ -- cgit v1.2.1