Skip to content

Commit d9eba57

Browse files
elmarcoMarkus Armbruster
authored and
Markus Armbruster
committed
qlit: make qlit_equal_qobject return a bool
Make it more obvious about the expected return values. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20170825105913.4060-7-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
1 parent 60cc2eb commit d9eba57

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

include/qapi/qmp/qlit.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ struct QLitDictEntry {
4444
#define QLIT_QLIST(val) \
4545
{ .type = QTYPE_QLIST, .value.qlist = (val) }
4646

47-
int qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
47+
bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
4848

4949
#endif /* QLIT_H */

qobject/qlit.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121
typedef struct QListCompareHelper {
2222
int index;
2323
QLitObject *objs;
24-
int result;
24+
bool result;
2525
} QListCompareHelper;
2626

2727
static void compare_helper(QObject *obj, void *opaque)
2828
{
2929
QListCompareHelper *helper = opaque;
3030

31-
if (helper->result == 0) {
31+
if (!helper->result) {
3232
return;
3333
}
3434

3535
if (helper->objs[helper->index].type == QTYPE_NONE) {
36-
helper->result = 0;
36+
helper->result = false;
3737
return;
3838
}
3939

4040
helper->result =
4141
qlit_equal_qobject(&helper->objs[helper->index++], obj);
4242
}
4343

44-
int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
44+
bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
4545
{
4646
int64_t val;
4747

4848
if (!rhs || lhs->type != qobject_type(rhs)) {
49-
return 0;
49+
return false;
5050
}
5151

5252
switch (lhs->type) {
@@ -64,18 +64,18 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
6464
lhs->value.qdict[i].key);
6565

6666
if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
67-
return 0;
67+
return false;
6868
}
6969
}
7070

71-
return 1;
71+
return true;
7272
}
7373
case QTYPE_QLIST: {
7474
QListCompareHelper helper;
7575

7676
helper.index = 0;
7777
helper.objs = lhs->value.qlist;
78-
helper.result = 1;
78+
helper.result = true;
7979

8080
qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
8181

@@ -85,5 +85,5 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
8585
break;
8686
}
8787

88-
return 0;
88+
return false;
8989
}

tests/check-qjson.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1094,13 +1094,13 @@ static void simple_dict(void)
10941094
QString *str;
10951095

10961096
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1097-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1097+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
10981098

10991099
str = qobject_to_json(obj);
11001100
qobject_decref(obj);
11011101

11021102
obj = qobject_from_json(qstring_get_str(str), &error_abort);
1103-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1103+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
11041104
qobject_decref(obj);
11051105
QDECREF(str);
11061106
}
@@ -1203,13 +1203,13 @@ static void simple_list(void)
12031203
QString *str;
12041204

12051205
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1206-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1206+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
12071207

12081208
str = qobject_to_json(obj);
12091209
qobject_decref(obj);
12101210

12111211
obj = qobject_from_json(qstring_get_str(str), &error_abort);
1212-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1212+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
12131213
qobject_decref(obj);
12141214
QDECREF(str);
12151215
}
@@ -1265,13 +1265,13 @@ static void simple_whitespace(void)
12651265
QString *str;
12661266

12671267
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
1268-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1268+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
12691269

12701270
str = qobject_to_json(obj);
12711271
qobject_decref(obj);
12721272

12731273
obj = qobject_from_json(qstring_get_str(str), &error_abort);
1274-
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
1274+
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
12751275

12761276
qobject_decref(obj);
12771277
QDECREF(str);
@@ -1295,7 +1295,7 @@ static void simple_varargs(void)
12951295
g_assert(embedded_obj != NULL);
12961296

12971297
obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
1298-
g_assert(qlit_equal_qobject(&decoded, obj) == 1);
1298+
g_assert(qlit_equal_qobject(&decoded, obj));
12991299

13001300
qobject_decref(obj);
13011301
}

0 commit comments

Comments
 (0)