qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PULL 15/53] tests: replace free_all() usage with g_auto
Date: Tue, 19 Apr 2022 07:50:31 +0200	[thread overview]
Message-ID: <20220419055109.142788-16-pbonzini@redhat.com> (raw)
In-Reply-To: <20220419055109.142788-1-pbonzini@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Use more idiomatic glib/auto-style code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220323155743.1585078-11-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/unit/check-qobject.c | 127 ++++++++++++-------------------------
 1 file changed, 40 insertions(+), 87 deletions(-)

diff --git a/tests/unit/check-qobject.c b/tests/unit/check-qobject.c
index c3d50e9994..7903ebf4cf 100644
--- a/tests/unit/check-qobject.c
+++ b/tests/unit/check-qobject.c
@@ -74,21 +74,6 @@ static void do_test_equality(bool expected, int _, ...)
 #define check_unequal(...) \
     do_test_equality(false, 0, __VA_ARGS__, &test_equality_end_of_arguments)
 
-static void do_free_all(int _, ...)
-{
-    va_list ap;
-    QObject *obj;
-
-    va_start(ap, _);
-    while ((obj = va_arg(ap, QObject *)) != NULL) {
-        qobject_unref(obj);
-    }
-    va_end(ap);
-}
-
-#define free_all(...) \
-    do_free_all(0, __VA_ARGS__, NULL)
-
 static void qobject_is_equal_null_test(void)
 {
     check_unequal(qnull(), NULL);
@@ -96,15 +81,14 @@ static void qobject_is_equal_null_test(void)
 
 static void qobject_is_equal_num_test(void)
 {
-    QNum *u0, *i0, *d0, *dnan, *um42, *im42, *dm42;
+    g_autoptr(QNum) u0 = qnum_from_uint(0u);
+    g_autoptr(QNum) i0 = qnum_from_int(0);
+    g_autoptr(QNum) d0 = qnum_from_double(0.0);
+    g_autoptr(QNum) dnan = qnum_from_double(NAN);
+    g_autoptr(QNum) um42 = qnum_from_uint((uint64_t)-42);
+    g_autoptr(QNum) im42 = qnum_from_int(-42);
+    g_autoptr(QNum) dm42 = qnum_from_double(-42.0);
 
-    u0 = qnum_from_uint(0u);
-    i0 = qnum_from_int(0);
-    d0 = qnum_from_double(0.0);
-    dnan = qnum_from_double(NAN);
-    um42 = qnum_from_uint((uint64_t)-42);
-    im42 = qnum_from_int(-42);
-    dm42 = qnum_from_double(-42.0);
 
     /* Integers representing a mathematically equal number should
      * compare equal */
@@ -121,60 +105,45 @@ static void qobject_is_equal_num_test(void)
     check_unequal(um42, im42);
     check_unequal(um42, dm42);
     check_unequal(im42, dm42);
-
-    free_all(u0, i0, d0, dnan, um42, im42, dm42);
 }
 
 static void qobject_is_equal_bool_test(void)
 {
-    QBool *btrue_0, *btrue_1, *bfalse_0, *bfalse_1;
-
-    btrue_0 = qbool_from_bool(true);
-    btrue_1 = qbool_from_bool(true);
-    bfalse_0 = qbool_from_bool(false);
-    bfalse_1 = qbool_from_bool(false);
+    g_autoptr(QBool) btrue_0 = qbool_from_bool(true);
+    g_autoptr(QBool) btrue_1 = qbool_from_bool(true);
+    g_autoptr(QBool) bfalse_0 = qbool_from_bool(false);
+    g_autoptr(QBool) bfalse_1 = qbool_from_bool(false);
 
     check_equal(btrue_0, btrue_1);
     check_equal(bfalse_0, bfalse_1);
     check_unequal(btrue_0, bfalse_0);
-
-    free_all(btrue_0, btrue_1, bfalse_0, bfalse_1);
 }
 
 static void qobject_is_equal_string_test(void)
 {
-    QString *str_base, *str_whitespace_0, *str_whitespace_1, *str_whitespace_2;
-    QString *str_whitespace_3, *str_case, *str_built;
-
-    str_base = qstring_from_str("foo");
-    str_whitespace_0 = qstring_from_str(" foo");
-    str_whitespace_1 = qstring_from_str("foo ");
-    str_whitespace_2 = qstring_from_str("foo\b");
-    str_whitespace_3 = qstring_from_str("fooo\b");
-    str_case = qstring_from_str("Foo");
-
+    g_autoptr(QString) str_base = qstring_from_str("foo");
+    g_autoptr(QString) str_whitespace_0 = qstring_from_str(" foo");
+    g_autoptr(QString) str_whitespace_1 = qstring_from_str("foo ");
+    g_autoptr(QString) str_whitespace_2 = qstring_from_str("foo\b");
+    g_autoptr(QString) str_whitespace_3 = qstring_from_str("fooo\b");
+    g_autoptr(QString) str_case = qstring_from_str("Foo");
     /* Should yield "foo" */
-    str_built = qstring_from_substr("buffoon", 3, 6);
+    g_autoptr(QString) str_built = qstring_from_substr("buffoon", 3, 6);
 
     check_unequal(str_base, str_whitespace_0, str_whitespace_1,
                   str_whitespace_2, str_whitespace_3, str_case);
 
     check_equal(str_base, str_built);
-
-    free_all(str_base, str_whitespace_0, str_whitespace_1, str_whitespace_2,
-             str_whitespace_3, str_case, str_built);
 }
 
 static void qobject_is_equal_list_test(void)
 {
-    QList *list_0, *list_1, *list_cloned;
-    QList *list_reordered, *list_longer, *list_shorter;
-
-    list_0 = qlist_new();
-    list_1 = qlist_new();
-    list_reordered = qlist_new();
-    list_longer = qlist_new();
-    list_shorter = qlist_new();
+    g_autoptr(QList) list_0 = qlist_new();
+    g_autoptr(QList) list_1 = qlist_new();
+    g_autoptr(QList) list_reordered = qlist_new();
+    g_autoptr(QList) list_longer = qlist_new();
+    g_autoptr(QList) list_shorter = qlist_new();
+    g_autoptr(QList) list_cloned = NULL;
 
     qlist_append_int(list_0, 1);
     qlist_append_int(list_0, 2);
@@ -205,26 +174,20 @@ static void qobject_is_equal_list_test(void)
      * itself */
     qlist_append(list_0, qnum_from_double(NAN));
     g_assert(qobject_is_equal(QOBJECT(list_0), QOBJECT(list_0)) == false);
-
-    free_all(list_0, list_1, list_cloned, list_reordered, list_longer,
-             list_shorter);
 }
 
 static void qobject_is_equal_dict_test(void)
 {
-    QDict *dict_0, *dict_1, *dict_cloned;
-    QDict *dict_different_key, *dict_different_value, *dict_different_null_key;
-    QDict *dict_longer, *dict_shorter, *dict_nested;
-    QDict *dict_crumpled;
-
-    dict_0 = qdict_new();
-    dict_1 = qdict_new();
-    dict_different_key = qdict_new();
-    dict_different_value = qdict_new();
-    dict_different_null_key = qdict_new();
-    dict_longer = qdict_new();
-    dict_shorter = qdict_new();
-    dict_nested = qdict_new();
+    g_autoptr(QDict) dict_cloned = NULL;
+    g_autoptr(QDict) dict_crumpled = NULL;
+    g_autoptr(QDict) dict_0 = qdict_new();
+    g_autoptr(QDict) dict_1 = qdict_new();
+    g_autoptr(QDict) dict_different_key = qdict_new();
+    g_autoptr(QDict) dict_different_value = qdict_new();
+    g_autoptr(QDict) dict_different_null_key = qdict_new();
+    g_autoptr(QDict) dict_longer = qdict_new();
+    g_autoptr(QDict) dict_shorter = qdict_new();
+    g_autoptr(QDict) dict_nested = qdict_new();
 
     qdict_put_int(dict_0, "f.o", 1);
     qdict_put_int(dict_0, "bar", 2);
@@ -284,31 +247,21 @@ static void qobject_is_equal_dict_test(void)
      * itself */
     qdict_put(dict_0, "NaN", qnum_from_double(NAN));
     g_assert(qobject_is_equal(QOBJECT(dict_0), QOBJECT(dict_0)) == false);
-
-    free_all(dict_0, dict_1, dict_cloned, dict_different_key,
-             dict_different_value, dict_different_null_key, dict_longer,
-             dict_shorter, dict_nested, dict_crumpled);
 }
 
 static void qobject_is_equal_conversion_test(void)
 {
-    QNum *u0, *i0, *d0;
-    QString *s0, *s_empty;
-    QBool *bfalse;
-
-    u0 = qnum_from_uint(0u);
-    i0 = qnum_from_int(0);
-    d0 = qnum_from_double(0.0);
-    s0 = qstring_from_str("0");
-    s_empty = qstring_new();
-    bfalse = qbool_from_bool(false);
+    g_autoptr(QNum) u0 = qnum_from_uint(0u);
+    g_autoptr(QNum) i0 = qnum_from_int(0);
+    g_autoptr(QNum) d0 = qnum_from_double(0.0);
+    g_autoptr(QString) s0 = qstring_from_str("0");
+    g_autoptr(QString) s_empty = qstring_new();
+    g_autoptr(QBool) bfalse = qbool_from_bool(false);
 
     /* No automatic type conversion */
     check_unequal(u0, s0, s_empty, bfalse, qnull(), NULL);
     check_unequal(i0, s0, s_empty, bfalse, qnull(), NULL);
     check_unequal(d0, s0, s_empty, bfalse, qnull(), NULL);
-
-    free_all(u0, i0, d0, s0, s_empty, bfalse);
 }
 
 int main(int argc, char **argv)
-- 
2.35.1




  parent reply	other threads:[~2022-04-19  6:06 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19  5:50 [PULL for-7.1 00/53] Misc pull request for QEMU 7.1 Paolo Bonzini
2022-04-19  5:50 ` [PULL 01/53] qapi, target/i386/sev: Add cpu0-id to query-sev-capabilities Paolo Bonzini
2022-04-19  7:16   ` Dov Murik
2022-04-20 19:06     ` Dov Murik
2022-04-19  5:50 ` [PULL 02/53] qtest: replace gettimeofday with GTimer Paolo Bonzini
2022-04-19  5:50 ` [PULL 03/53] qga: replace qemu_gettimeofday() with g_get_real_time() Paolo Bonzini
2022-04-19  5:50 ` [PULL 04/53] Replace " Paolo Bonzini
2022-04-19  5:50 ` [PULL 05/53] oslib: drop qemu_gettimeofday() Paolo Bonzini
2022-04-19  5:50 ` [PULL 06/53] meson: use chardev_ss dependencies Paolo Bonzini
2022-04-19  5:50 ` [PULL 07/53] meson: add util dependency for oslib-posix on freebsd Paolo Bonzini
2022-04-19  5:50 ` [PULL 08/53] meson: remove unneeded py3 Paolo Bonzini
2022-04-19  5:50 ` [PULL 09/53] meson: remove test-qdev-global-props dependency on testqapi Paolo Bonzini
2022-04-19  5:50 ` [PULL 10/53] char: move qemu_openpty_raw from util/ to char/ Paolo Bonzini
2022-04-19  5:50 ` [PULL 11/53] Replace config-time define HOST_WORDS_BIGENDIAN Paolo Bonzini
2022-04-19  5:50 ` [PULL 12/53] Replace TARGET_WORDS_BIGENDIAN Paolo Bonzini
2022-04-19  5:50 ` [PULL 13/53] osdep: poison {HOST,TARGET}_WORDS_BIGENDIAN Paolo Bonzini
2022-04-19  5:50 ` [PULL 14/53] include/qapi: add g_autoptr support for qobject types Paolo Bonzini
2022-04-19  5:50 ` Paolo Bonzini [this message]
2022-04-19  5:50 ` [PULL 16/53] Replace qemu_real_host_page variables with inlined functions Paolo Bonzini
2022-04-19  5:50 ` [PULL 17/53] qga: replace deprecated g_get_current_time() Paolo Bonzini
2022-04-19  5:50 ` [PULL 18/53] error-report: replace deprecated g_get_current_time() with glib >= 2.62 Paolo Bonzini
2022-04-19  5:50 ` [PULL 19/53] util: rename qemu-error.c to match its header name Paolo Bonzini
2022-04-19  5:50 ` [PULL 20/53] error-report: use error_printf() for program prefix Paolo Bonzini
2022-04-19  5:50 ` [PULL 21/53] include: move TFR to osdep.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 22/53] include: move qemu_write_full() declaration " Paolo Bonzini
2022-04-19  5:50 ` [PULL 23/53] include: move qemu_pipe() " Paolo Bonzini
2022-04-19  5:50 ` [PULL 24/53] include: move coroutine IO functions to coroutine.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 25/53] include: move dump_in_progress() to runstate.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 26/53] include: move C/util-related declarations to cutils.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 27/53] include: move cpu_exec* declarations to cpu-common.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 28/53] include: move target page bits declaration to page-vary.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 29/53] include: move progress API to qemu-progress.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 30/53] include: move qemu_get_vm_name() to sysemu.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 31/53] include: move os_*() to os-foo.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 32/53] include: move page_size_init() to include/hw/core/cpu.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 33/53] Move CPU softfloat unions to cpu-float.h Paolo Bonzini
2022-04-19  5:50 ` [PULL 34/53] Move fcntl_setfl() to oslib-posix Paolo Bonzini
2022-04-19  5:50 ` [PULL 35/53] qga: remove explicit environ argument from exec/spawn Paolo Bonzini
2022-04-19  5:50 ` [PULL 36/53] Remove qemu-common.h include from most units Paolo Bonzini
2022-04-19  5:50 ` [PULL 37/53] build-sys: drop ntddscsi.h check Paolo Bonzini
2022-04-19  5:50 ` [PULL 38/53] build-sys: simplify AF_VSOCK check Paolo Bonzini
2022-04-19  5:50 ` [PULL 39/53] whpx: Added support for breakpoints and stepping Paolo Bonzini
2022-04-19  5:50 ` [PULL 40/53] thread-posix: remove the posix semaphore support Paolo Bonzini
2022-04-19  5:50 ` [PULL 41/53] thread-posix: use monotonic clock for QemuCond and QemuSemaphore Paolo Bonzini
2022-04-19  5:50 ` [PULL 42/53] thread-posix: implement Semaphore with QemuCond and QemuMutex Paolo Bonzini
2022-04-19  5:50 ` [PULL 43/53] thread-posix: optimize qemu_sem_timedwait with zero timeout Paolo Bonzini
2022-04-19  5:51 ` [PULL 44/53] hyperv: SControl is optional to enable SynIc Paolo Bonzini
2022-04-19  5:51 ` [PULL 45/53] hyperv: Add definitions for syndbg Paolo Bonzini
2022-04-19  5:51 ` [PULL 46/53] hyperv: Add support to process syndbg commands Paolo Bonzini
2022-04-19  5:51 ` [PULL 47/53] hw: hyperv: Initial commit for Synthetic Debugging device Paolo Bonzini
2022-04-19  5:51 ` [PULL 48/53] s390x: follow qdev tree to detect SCSI device on a CCW bus Paolo Bonzini
2022-04-19  5:51 ` [PULL 49/53] virtio-ccw: move vhost_ccw_scsi to a separate file Paolo Bonzini
2022-04-19  5:51 ` [PULL 50/53] virtio-ccw: move device type declarations to .c files Paolo Bonzini
2022-04-19  5:51 ` [PULL 51/53] virtio-ccw: do not include headers for all virtio devices Paolo Bonzini
2022-04-19  5:51 ` [PULL 52/53] target/i386: do not access beyond the low 128 bits of SSE registers Paolo Bonzini
2022-04-19  5:51 ` [PULL 53/53] target/i386: Remove unused XMMReg, YMMReg types and CPUState fields Paolo Bonzini
2022-04-19  9:32 ` [PULL for-7.1 00/53] Misc pull request for QEMU 7.1 Peter Maydell
2022-04-20  3:57 ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220419055109.142788-16-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).