From 11bd03727fdd10b8764e9c08157f8a77d015cf4b Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 18 Nov 2013 17:02:49 -0500 Subject: Import some virTypedParams* APIs from libvirt virTypedParamsClear() and virTypedParamsFree() were introduced in libvirt 1.0.2. In an effort to keep the code clean bring these two functions to libvirt-python if we're building against a version of libvirt that's older than 1.0.2 --- libvirt-utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libvirt-utils.c') diff --git a/libvirt-utils.c b/libvirt-utils.c index 9c29a1c..d1f6e70 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "libvirt-utils.h" /** @@ -138,3 +139,48 @@ int virFileClose(int *fdptr) return rc; } + +#if ! LIBVIR_CHECK_VERSION(1, 0, 2) +/** + * virTypedParamsClear: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters. The memory occupied by @params + * is not free; use virTypedParamsFree if you want it to be freed too. + * + * Returns nothing. + */ +void +virTypedParamsClear(virTypedParameterPtr params, + int nparams) +{ + size_t i; + + if (!params) + return; + + for (i = 0; i < nparams; i++) { + if (params[i].type == VIR_TYPED_PARAM_STRING) + VIR_FREE(params[i].value.s); + } +} + +/** + * virTypedParamsFree: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters and the memory occuiped by + * @params. + * + * Returns nothing. + */ +void +virTypedParamsFree(virTypedParameterPtr params, + int nparams) +{ + virTypedParamsClear(params, nparams); + VIR_FREE(params); +} +#endif /* ! LIBVIR_CHECK_VERSION(1, 0, 2) */ -- cgit