diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-04-19 17:01:43 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-05-04 08:27:53 +0200 |
commit | cb3e7f08aeaab0ab13e629ce8496dca150a449ba (patch) | |
tree | 189830b93bea625aac19f86f26dc4b04cd99f5a3 /tests/test-keyval.c | |
parent | 3d3eacaeccaab718ea0e2ddaa578bfae9e311c59 (diff) |
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
Now that we can safely call QOBJECT() on QObject * as well as its
subtypes, we can have macros qobject_ref() / qobject_unref() that work
everywhere instead of having to use QINCREF() / QDECREF() for QObject
and qobject_incref() / qobject_decref() for its subtypes.
The replacement is mechanical, except I broke a long line, and added a
cast in monitor_qmp_cleanup_req_queue_locked(). Unlike
qobject_decref(), qobject_unref() doesn't accept void *.
Note that the new macros evaluate their argument exactly once, thus no
need to shout them.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180419150145.24795-4-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Rebased, semantic conflict resolved, commit message improved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/test-keyval.c')
-rw-r--r-- | tests/test-keyval.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 029f05202a..63cb14629b 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -30,7 +30,7 @@ static void test_keyval_parse(void) /* Nothing */ qdict = keyval_parse("", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 0); - QDECREF(qdict); + qobject_unref(qdict); /* Empty key (qemu_opts_parse() accepts this) */ qdict = keyval_parse("=val", NULL, &err); @@ -70,7 +70,7 @@ static void test_keyval_parse(void) qdict = keyval_parse(params + 2, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(qdict, long_key + 1), ==, "v"); - QDECREF(qdict); + qobject_unref(qdict); /* Long key fragment */ qdict = keyval_parse(params, NULL, &error_abort); @@ -79,7 +79,7 @@ static void test_keyval_parse(void) g_assert(sub_qdict); g_assert_cmpuint(qdict_size(sub_qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(sub_qdict, long_key + 1), ==, "v"); - QDECREF(qdict); + qobject_unref(qdict); g_free(params); /* Crap after valid key */ @@ -92,13 +92,13 @@ static void test_keyval_parse(void) g_assert_cmpuint(qdict_size(qdict), ==, 2); g_assert_cmpstr(qdict_get_try_str(qdict, "a"), ==, "3"); g_assert_cmpstr(qdict_get_try_str(qdict, "b"), ==, "2,x"); - QDECREF(qdict); + qobject_unref(qdict); /* Even when it doesn't in qemu_opts_parse() */ qdict = keyval_parse("id=foo,id=bar", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "id"), ==, "bar"); - QDECREF(qdict); + qobject_unref(qdict); /* Dotted keys */ qdict = keyval_parse("a.b.c=1,a.b.c=2,d=3", NULL, &error_abort); @@ -111,7 +111,7 @@ static void test_keyval_parse(void) g_assert_cmpuint(qdict_size(sub_qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(sub_qdict, "c"), ==, "2"); g_assert_cmpstr(qdict_get_try_str(qdict, "d"), ==, "3"); - QDECREF(qdict); + qobject_unref(qdict); /* Inconsistent dotted keys */ qdict = keyval_parse("a.b=1,a=2", NULL, &err); @@ -125,7 +125,7 @@ static void test_keyval_parse(void) qdict = keyval_parse("x=y,", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "x"), ==, "y"); - QDECREF(qdict); + qobject_unref(qdict); /* Except when it isn't */ qdict = keyval_parse(",", NULL, &err); @@ -136,13 +136,13 @@ static void test_keyval_parse(void) qdict = keyval_parse("x=,,id=bar", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "x"), ==, ",id=bar"); - QDECREF(qdict); + qobject_unref(qdict); /* Anti-social ID is left to caller (qemu_opts_parse() rejects it) */ qdict = keyval_parse("id=666", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "id"), ==, "666"); - QDECREF(qdict); + qobject_unref(qdict); /* Implied value not supported (unlike qemu_opts_parse()) */ qdict = keyval_parse("an,noaus,noaus=", NULL, &err); @@ -160,7 +160,7 @@ static void test_keyval_parse(void) g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "an"); g_assert_cmpstr(qdict_get_try_str(qdict, "aus"), ==, "off"); g_assert_cmpstr(qdict_get_try_str(qdict, "noaus"), ==, ""); - QDECREF(qdict); + qobject_unref(qdict); /* Implied dotted key */ qdict = keyval_parse("val", "eins.zwei", &error_abort); @@ -169,7 +169,7 @@ static void test_keyval_parse(void) g_assert(sub_qdict); g_assert_cmpuint(qdict_size(sub_qdict), ==, 1); g_assert_cmpstr(qdict_get_try_str(sub_qdict, "zwei"), ==, "val"); - QDECREF(qdict); + qobject_unref(qdict); /* Implied key with empty value (qemu_opts_parse() accepts this) */ qdict = keyval_parse(",", "implied", &err); @@ -198,7 +198,7 @@ static void check_list012(QList *qlist) qstr = qobject_to(QString, qlist_pop(qlist)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), ==, expected[i]); - QDECREF(qstr); + qobject_unref(qstr); } g_assert(qlist_empty(qlist)); } @@ -218,14 +218,14 @@ static void test_keyval_parse_list(void) NULL, &error_abort); g_assert_cmpint(qdict_size(qdict), ==, 1); check_list012(qdict_get_qlist(qdict, "list")); - QDECREF(qdict); + qobject_unref(qdict); /* Multiple indexes, last one wins */ qdict = keyval_parse("list.1=goner,list.0=null,list.01=eins,list.2=zwei", NULL, &error_abort); g_assert_cmpint(qdict_size(qdict), ==, 1); check_list012(qdict_get_qlist(qdict, "list")); - QDECREF(qdict); + qobject_unref(qdict); /* List at deeper nesting */ qdict = keyval_parse("a.list.1=eins,a.list.00=null,a.list.2=zwei", @@ -234,7 +234,7 @@ static void test_keyval_parse_list(void) sub_qdict = qdict_get_qdict(qdict, "a"); g_assert_cmpint(qdict_size(sub_qdict), ==, 1); check_list012(qdict_get_qlist(sub_qdict, "list")); - QDECREF(qdict); + qobject_unref(qdict); /* Inconsistent dotted keys: both list and dictionary */ qdict = keyval_parse("a.b.c=1,a.b.0=2", NULL, &err); @@ -262,7 +262,7 @@ static void test_keyval_visit_bool(void) qdict = keyval_parse("bool1=on,bool2=off", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_bool(v, "bool1", &b, &error_abort); g_assert(b); @@ -274,7 +274,7 @@ static void test_keyval_visit_bool(void) qdict = keyval_parse("bool1=offer", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_bool(v, "bool1", &b, &err); error_free_or_abort(&err); @@ -292,7 +292,7 @@ static void test_keyval_visit_number(void) /* Lower limit zero */ qdict = keyval_parse("number1=0", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &error_abort); g_assert_cmpuint(u, ==, 0); @@ -304,7 +304,7 @@ static void test_keyval_visit_number(void) qdict = keyval_parse("number1=18446744073709551615,number2=-1", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &error_abort); g_assert_cmphex(u, ==, UINT64_MAX); @@ -318,7 +318,7 @@ static void test_keyval_visit_number(void) qdict = keyval_parse("number1=18446744073709551616", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &err); error_free_or_abort(&err); @@ -329,7 +329,7 @@ static void test_keyval_visit_number(void) qdict = keyval_parse("number1=-18446744073709551616", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &err); error_free_or_abort(&err); @@ -340,7 +340,7 @@ static void test_keyval_visit_number(void) qdict = keyval_parse("number1=0x2a,number2=052", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &error_abort); g_assert_cmpuint(u, ==, 42); @@ -354,7 +354,7 @@ static void test_keyval_visit_number(void) qdict = keyval_parse("number1=3.14,number2=08", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_uint64(v, "number1", &u, &err); error_free_or_abort(&err); @@ -374,7 +374,7 @@ static void test_keyval_visit_size(void) /* Lower limit zero */ qdict = keyval_parse("sz1=0", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &error_abort); g_assert_cmpuint(sz, ==, 0); @@ -390,7 +390,7 @@ static void test_keyval_visit_size(void) "sz3=9007199254740993", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &error_abort); g_assert_cmphex(sz, ==, 0x1fffffffffffff); @@ -407,7 +407,7 @@ static void test_keyval_visit_size(void) "sz2=9223372036854775295", /* 7ffffffffffffdff */ NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &error_abort); g_assert_cmphex(sz, ==, 0x7ffffffffffffc00); @@ -422,7 +422,7 @@ static void test_keyval_visit_size(void) "sz2=18446744073709550591", /* fffffffffffffbff */ NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &error_abort); g_assert_cmphex(sz, ==, 0xfffffffffffff800); @@ -437,7 +437,7 @@ static void test_keyval_visit_size(void) "sz2=18446744073709550592", /* fffffffffffffc00 */ NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &err); error_free_or_abort(&err); @@ -450,7 +450,7 @@ static void test_keyval_visit_size(void) qdict = keyval_parse("sz1=8b,sz2=1.5k,sz3=2M,sz4=0.1G,sz5=16777215T", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &error_abort); g_assert_cmpuint(sz, ==, 8); @@ -469,7 +469,7 @@ static void test_keyval_visit_size(void) /* Beyond limit with suffix */ qdict = keyval_parse("sz1=16777216T", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &err); error_free_or_abort(&err); @@ -479,7 +479,7 @@ static void test_keyval_visit_size(void) /* Trailing crap */ qdict = keyval_parse("sz1=16E,sz2=16Gi", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_size(v, "sz1", &sz, &err); error_free_or_abort(&err); @@ -498,7 +498,7 @@ static void test_keyval_visit_dict(void) qdict = keyval_parse("a.b.c=1,a.b.c=2,d=3", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_start_struct(v, "a", NULL, 0, &error_abort); visit_start_struct(v, "b", NULL, 0, &error_abort); @@ -516,7 +516,7 @@ static void test_keyval_visit_dict(void) qdict = keyval_parse("a.b=", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_start_struct(v, "a", NULL, 0, &error_abort); visit_type_int(v, "c", &i, &err); /* a.c missing */ @@ -539,7 +539,7 @@ static void test_keyval_visit_list(void) qdict = keyval_parse("a.0=,a.1=I,a.2.0=II", NULL, &error_abort); /* TODO empty list */ v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_start_list(v, "a", NULL, 0, &error_abort); visit_type_str(v, NULL, &s, &error_abort); @@ -562,7 +562,7 @@ static void test_keyval_visit_list(void) qdict = keyval_parse("a.0=,b.0.0=head", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_start_list(v, "a", NULL, 0, &error_abort); visit_check_list(v, &err); /* a[0] unexpected */ @@ -591,7 +591,7 @@ static void test_keyval_visit_optional(void) qdict = keyval_parse("a.b=1", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_optional(v, "b", &present); g_assert(!present); /* b missing */ @@ -627,7 +627,7 @@ static void test_keyval_visit_alternate(void) */ qdict = keyval_parse("a=1,b=2,c=on", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_AltStrObj(v, "a", &aso, &error_abort); g_assert_cmpint(aso->type, ==, QTYPE_QSTRING); @@ -651,19 +651,19 @@ static void test_keyval_visit_any(void) qdict = keyval_parse("a.0=null,a.1=1", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - QDECREF(qdict); + qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_any(v, "a", &any, &error_abort); qlist = qobject_to(QList, any); g_assert(qlist); qstr = qobject_to(QString, qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "null"); - QDECREF(qstr); + qobject_unref(qstr); qstr = qobject_to(QString, qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "1"); g_assert(qlist_empty(qlist)); - QDECREF(qstr); - qobject_decref(any); + qobject_unref(qstr); + qobject_unref(any); visit_check_struct(v, &error_abort); visit_end_struct(v, NULL); visit_free(v); |