[libvirt PATCH 0/2] tests: use g_auto more (glib chronicles)

Convert two more functions to use automatic cleanup. Ján Tomko (2): tests: use g_auto in testQemuGetCaps tests: use g_auto in qemuTestParseCapabilitiesArch tests/qemucaps2xmltest.c | 16 ++++++---------- tests/testutilsqemu.c | 10 +++------- 2 files changed, 9 insertions(+), 17 deletions(-) -- 2.31.1

Refactor testQemuGetCaps to use g_auto for cleanup, remove the error label and use g_steal_pointer for the successful return path. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemucaps2xmltest.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index ce1116b792..78a2148e1a 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -50,22 +50,22 @@ testQemuDataInit(testQemuData *data) static virQEMUCaps * testQemuGetCaps(char *caps) { - virQEMUCaps *qemuCaps = NULL; + g_autoptr(virQEMUCaps) qemuCaps = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; ssize_t i, n; g_autofree xmlNodePtr *nodes = NULL; if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt))) - goto error; + return NULL; if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) { fprintf(stderr, "failed to parse qemu capabilities flags"); - goto error; + return NULL; } if (!(qemuCaps = virQEMUCapsNew())) - goto error; + return NULL; for (i = 0; i < n; i++) { g_autofree char *str = virXMLPropString(nodes[i], "name"); @@ -73,17 +73,13 @@ testQemuGetCaps(char *caps) int flag = virQEMUCapsTypeFromString(str); if (flag < 0) { fprintf(stderr, "Unknown qemu capabilities flag %s", str); - goto error; + return NULL; } virQEMUCapsSet(qemuCaps, flag); } } - return qemuCaps; - - error: - virObjectUnref(qemuCaps); - return NULL; + return g_steal_pointer(&qemuCaps); } static virCaps * -- 2.31.1

Refactor qemuTestParseCapabilitiesArch to use g_auto fro cleanup. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/testutilsqemu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 81d4a44f9a..ea9a283297 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -304,19 +304,15 @@ virQEMUCaps * qemuTestParseCapabilitiesArch(virArch arch, const char *capsFile) { - virQEMUCaps *qemuCaps = NULL; + g_autoptr(virQEMUCaps) qemuCaps = NULL; g_autofree char *binary = g_strdup_printf("/usr/bin/qemu-system-%s", virArchToString(arch)); if (!(qemuCaps = virQEMUCapsNewBinary(binary)) || virQEMUCapsLoadCache(arch, qemuCaps, capsFile, true) < 0) - goto error; + return NULL; - return qemuCaps; - - error: - virObjectUnref(qemuCaps); - return NULL; + return g_steal_pointer(&qemuCaps); } -- 2.31.1

On Fri, Aug 20, 2021 at 2:01 PM Ján Tomko <jtomko@redhat.com> wrote:
Convert two more functions to use automatic cleanup.
Ján Tomko (2): tests: use g_auto in testQemuGetCaps tests: use g_auto in qemuTestParseCapabilitiesArch
tests/qemucaps2xmltest.c | 16 ++++++---------- tests/testutilsqemu.c | 10 +++------- 2 files changed, 9 insertions(+), 17 deletions(-)
-- 2.31.1
Reviewed-by: Kristina Hanicova <khanicov@redhat.com> Kristina

On Fri, Aug 20, 2021 at 01:57:53PM +0200, Ján Tomko wrote:
Convert two more functions to use automatic cleanup.
Ján Tomko (2): tests: use g_auto in testQemuGetCaps tests: use g_auto in qemuTestParseCapabilitiesArch
tests/qemucaps2xmltest.c | 16 ++++++---------- tests/testutilsqemu.c | 10 +++------- 2 files changed, 9 insertions(+), 17 deletions(-)
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
-- 2.31.1
participants (3)
-
Ján Tomko
-
Kristina Hanicova
-
Martin Kletzander