mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: string: Introduce macro for automatic string lists
Similar to VIR_AUTOPTR, VIR_AUTOSTRINGLIST defines a list of strings which will be freed if the pointer is leaving scope. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
24c4fab8ec
commit
daefda165b
@ -2958,6 +2958,7 @@ virStringHasControlChars;
|
|||||||
virStringIsEmpty;
|
virStringIsEmpty;
|
||||||
virStringIsPrintable;
|
virStringIsPrintable;
|
||||||
virStringListAdd;
|
virStringListAdd;
|
||||||
|
virStringListAutoFree;
|
||||||
virStringListFree;
|
virStringListFree;
|
||||||
virStringListFreeCount;
|
virStringListFreeCount;
|
||||||
virStringListGetFirstWithPrefix;
|
virStringListGetFirstWithPrefix;
|
||||||
|
@ -318,6 +318,16 @@ void virStringListFree(char **strings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void virStringListAutoFree(char ***strings)
|
||||||
|
{
|
||||||
|
if (!*strings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
virStringListFree(*strings);
|
||||||
|
*strings = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virStringListFreeCount:
|
* virStringListFreeCount:
|
||||||
* @strings: array of strings to free
|
* @strings: array of strings to free
|
||||||
|
@ -53,6 +53,7 @@ int virStringListCopy(char ***dst,
|
|||||||
const char **src);
|
const char **src);
|
||||||
|
|
||||||
void virStringListFree(char **strings);
|
void virStringListFree(char **strings);
|
||||||
|
void virStringListAutoFree(char ***strings);
|
||||||
void virStringListFreeCount(char **strings,
|
void virStringListFreeCount(char **strings,
|
||||||
size_t count);
|
size_t count);
|
||||||
|
|
||||||
@ -307,6 +308,15 @@ int virStringParsePort(const char *str,
|
|||||||
unsigned int *port)
|
unsigned int *port)
|
||||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIR_AUTOSTRINGLIST:
|
||||||
|
*
|
||||||
|
* Declares a NULL-terminated list of strings which will be automatically freed
|
||||||
|
* when the pointer goes out of scope.
|
||||||
|
*/
|
||||||
|
# define VIR_AUTOSTRINGLIST \
|
||||||
|
__attribute__((cleanup(virStringListAutoFree))) char **
|
||||||
|
|
||||||
VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree);
|
VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree);
|
||||||
|
|
||||||
#endif /* LIBVIRT_VIRSTRING_H */
|
#endif /* LIBVIRT_VIRSTRING_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user