util: virtypedparam: Introduce 'virTypedParamListFetch'

Introduce a helper that fetches the typed parameters from the list while
still preserving ownership of the pointer by the list.

In the future this will be also able to report errors stored in the
list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-04-18 15:45:31 +02:00
parent 8ea33c8c18
commit 0fac024958
3 changed files with 33 additions and 0 deletions

View File

@ -3556,6 +3556,7 @@ virTypedParamListAddString;
virTypedParamListAddUInt;
virTypedParamListAddULLong;
virTypedParamListConcat;
virTypedParamListFetch;
virTypedParamListFree;
virTypedParamListFromParams;
virTypedParamListNew;

View File

@ -746,6 +746,32 @@ virTypedParamListFree(virTypedParamList *list)
}
/**
* virTypedParamListFetch:
*
* @list: virTypedParamList object
* @par: if not NULL filled with the typed parameters stored in @list
* @npar: if not NULL filled with the number of typed parameters stored in @list
*
* Checks that @list has no errors stored and optionally fills @par and @npar
* with a valid list of typed parameters. The typed parameters still belong to
* @list and will be freed together.
*/
int
virTypedParamListFetch(virTypedParamList *list,
virTypedParameterPtr *par,
size_t *npar)
{
if (par)
*par = list->par;
if (npar)
*npar = list->npar;
return 0;
}
size_t
virTypedParamListStealParams(virTypedParamList *list,
virTypedParameterPtr *params)

View File

@ -152,6 +152,12 @@ size_t
virTypedParamListStealParams(virTypedParamList *list,
virTypedParameterPtr *params);
int
virTypedParamListFetch(virTypedParamList *list,
virTypedParameterPtr *par,
size_t *npar)
G_GNUC_WARN_UNUSED_RESULT;
virTypedParamList *
virTypedParamListFromParams(virTypedParameterPtr *params,
size_t nparams);