qobject: Use 'bool' for qbool

We require a C99 compiler, so let's use 'bool' instead of 'int'
when dealing with boolean values.  There are few enough clients
to fix them all in one pass.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Eric Blake 2015-05-15 16:24:59 -06:00 committed by Markus Armbruster
parent 0a3346f5de
commit fc48ffc39e
16 changed files with 39 additions and 38 deletions

View File

@ -520,7 +520,7 @@ static void dump_qobject(fprintf_function func_fprintf, void *f,
} }
case QTYPE_QBOOL: { case QTYPE_QBOOL: {
QBool *value = qobject_to_qbool(obj); QBool *value = qobject_to_qbool(obj);
func_fprintf(f, "%s", qbool_get_int(value) ? "true" : "false"); func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false");
break; break;
} }
case QTYPE_QERROR: { case QTYPE_QERROR: {

View File

@ -1024,9 +1024,9 @@ static void quorum_refresh_filename(BlockDriverState *bs)
qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD, qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD,
QOBJECT(qint_from_int(s->threshold))); QOBJECT(qint_from_int(s->threshold)));
qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY, qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY,
QOBJECT(qbool_from_int(s->is_blkverify))); QOBJECT(qbool_from_bool(s->is_blkverify)));
qdict_put_obj(opts, QUORUM_OPT_REWRITE, qdict_put_obj(opts, QUORUM_OPT_REWRITE,
QOBJECT(qbool_from_int(s->rewrite_corrupted))); QOBJECT(qbool_from_bool(s->rewrite_corrupted)));
qdict_put_obj(opts, "children", QOBJECT(children)); qdict_put_obj(opts, "children", QOBJECT(children));
bs->full_open_options = opts; bs->full_open_options = opts;

View File

@ -1059,8 +1059,8 @@ static void vvfat_parse_filename(const char *filename, QDict *options,
/* Fill in the options QDict */ /* Fill in the options QDict */
qdict_put(options, "dir", qstring_from_str(filename)); qdict_put(options, "dir", qstring_from_str(filename));
qdict_put(options, "fat-type", qint_from_int(fat_type)); qdict_put(options, "fat-type", qint_from_int(fat_type));
qdict_put(options, "floppy", qbool_from_int(floppy)); qdict_put(options, "floppy", qbool_from_bool(floppy));
qdict_put(options, "rw", qbool_from_int(rw)); qdict_put(options, "rw", qbool_from_bool(rw));
} }
static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,

View File

@ -14,16 +14,16 @@
#ifndef QBOOL_H #ifndef QBOOL_H
#define QBOOL_H #define QBOOL_H
#include <stdint.h> #include <stdbool.h>
#include "qapi/qmp/qobject.h" #include "qapi/qmp/qobject.h"
typedef struct QBool { typedef struct QBool {
QObject_HEAD; QObject_HEAD;
int value; bool value;
} QBool; } QBool;
QBool *qbool_from_int(int value); QBool *qbool_from_bool(bool value);
int qbool_get_int(const QBool *qb); bool qbool_get_bool(const QBool *qb);
QBool *qobject_to_qbool(const QObject *obj); QBool *qobject_to_qbool(const QObject *obj);
#endif /* QBOOL_H */ #endif /* QBOOL_H */

View File

@ -3940,7 +3940,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
case 'b': case 'b':
{ {
const char *beg; const char *beg;
int val; bool val;
while (qemu_isspace(*p)) { while (qemu_isspace(*p)) {
p++; p++;
@ -3950,14 +3950,14 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
p++; p++;
} }
if (p - beg == 2 && !memcmp(beg, "on", p - beg)) { if (p - beg == 2 && !memcmp(beg, "on", p - beg)) {
val = 1; val = true;
} else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) { } else if (p - beg == 3 && !memcmp(beg, "off", p - beg)) {
val = 0; val = false;
} else { } else {
monitor_printf(mon, "Expected 'on' or 'off'\n"); monitor_printf(mon, "Expected 'on' or 'off'\n");
goto fail; goto fail;
} }
qdict_put(qdict, key, qbool_from_int(val)); qdict_put(qdict, key, qbool_from_bool(val));
} }
break; break;
case '-': case '-':
@ -3988,7 +3988,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
} else { } else {
/* has option */ /* has option */
p++; p++;
qdict_put(qdict, key, qbool_from_int(1)); qdict_put(qdict, key, qbool_from_bool(true));
} }
} }
} }

View File

@ -248,7 +248,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name,
return; return;
} }
*obj = qbool_get_int(qobject_to_qbool(qobj)); *obj = qbool_get_bool(qobject_to_qbool(qobj));
} }
static void qmp_input_type_str(Visitor *v, char **obj, const char *name, static void qmp_input_type_str(Visitor *v, char **obj, const char *name,

View File

@ -166,7 +166,7 @@ static void qmp_output_type_bool(Visitor *v, bool *obj, const char *name,
Error **errp) Error **errp)
{ {
QmpOutputVisitor *qov = to_qov(v); QmpOutputVisitor *qov = to_qov(v);
qmp_output_add(qov, name, qbool_from_int(*obj)); qmp_output_add(qov, name, qbool_from_bool(*obj));
} }
static void qmp_output_type_str(Visitor *v, char **obj, const char *name, static void qmp_output_type_str(Visitor *v, char **obj, const char *name,

View File

@ -558,9 +558,9 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
} }
if (token_is_keyword(token, "true")) { if (token_is_keyword(token, "true")) {
ret = QOBJECT(qbool_from_int(true)); ret = QOBJECT(qbool_from_bool(true));
} else if (token_is_keyword(token, "false")) { } else if (token_is_keyword(token, "false")) {
ret = QOBJECT(qbool_from_int(false)); ret = QOBJECT(qbool_from_bool(false));
} else if (token_is_keyword(token, "null")) { } else if (token_is_keyword(token, "null")) {
ret = qnull(); ret = qnull();
} else { } else {
@ -593,7 +593,7 @@ static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap)
if (token_is_escape(token, "%p")) { if (token_is_escape(token, "%p")) {
obj = va_arg(*ap, QObject *); obj = va_arg(*ap, QObject *);
} else if (token_is_escape(token, "%i")) { } else if (token_is_escape(token, "%i")) {
obj = QOBJECT(qbool_from_int(va_arg(*ap, int))); obj = QOBJECT(qbool_from_bool(va_arg(*ap, int)));
} else if (token_is_escape(token, "%d")) { } else if (token_is_escape(token, "%d")) {
obj = QOBJECT(qint_from_int(va_arg(*ap, int))); obj = QOBJECT(qint_from_int(va_arg(*ap, int)));
} else if (token_is_escape(token, "%ld")) { } else if (token_is_escape(token, "%ld")) {

View File

@ -23,11 +23,11 @@ static const QType qbool_type = {
}; };
/** /**
* qbool_from_int(): Create a new QBool from an int * qbool_from_bool(): Create a new QBool from a bool
* *
* Return strong reference. * Return strong reference.
*/ */
QBool *qbool_from_int(int value) QBool *qbool_from_bool(bool value)
{ {
QBool *qb; QBool *qb;
@ -39,9 +39,9 @@ QBool *qbool_from_int(int value)
} }
/** /**
* qbool_get_int(): Get the stored int * qbool_get_bool(): Get the stored bool
*/ */
int qbool_get_int(const QBool *qb) bool qbool_get_bool(const QBool *qb)
{ {
return qb->value; return qb->value;
} }

View File

@ -244,7 +244,7 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)
int qdict_get_bool(const QDict *qdict, const char *key) int qdict_get_bool(const QDict *qdict, const char *key)
{ {
QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL); QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL);
return qbool_get_int(qobject_to_qbool(obj)); return qbool_get_bool(qobject_to_qbool(obj));
} }
/** /**
@ -322,7 +322,7 @@ int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value)
if (!obj || qobject_type(obj) != QTYPE_QBOOL) if (!obj || qobject_type(obj) != QTYPE_QBOOL)
return def_value; return def_value;
return qbool_get_int(qobject_to_qbool(obj)); return qbool_get_bool(qobject_to_qbool(obj));
} }
/** /**

View File

@ -254,7 +254,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
case QTYPE_QBOOL: { case QTYPE_QBOOL: {
QBool *val = qobject_to_qbool(obj); QBool *val = qobject_to_qbool(obj);
if (qbool_get_int(val)) { if (qbool_get_bool(val)) {
qstring_append(str, "true"); qstring_append(str, "true");
} else { } else {
qstring_append(str, "false"); qstring_append(str, "false");

View File

@ -1010,7 +1010,7 @@ Object *object_property_get_link(Object *obj, const char *name,
void object_property_set_bool(Object *obj, bool value, void object_property_set_bool(Object *obj, bool value,
const char *name, Error **errp) const char *name, Error **errp)
{ {
QBool *qbool = qbool_from_int(value); QBool *qbool = qbool_from_bool(value);
object_property_set_qobject(obj, QOBJECT(qbool), name, errp); object_property_set_qobject(obj, QOBJECT(qbool), name, errp);
QDECREF(qbool); QDECREF(qbool);
@ -1031,7 +1031,7 @@ bool object_property_get_bool(Object *obj, const char *name,
error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean");
retval = false; retval = false;
} else { } else {
retval = qbool_get_int(qbool); retval = qbool_get_bool(qbool);
} }
QDECREF(qbool); QDECREF(qbool);

View File

@ -1013,7 +1013,7 @@ static void keyword_literal(void)
g_assert(qobject_type(obj) == QTYPE_QBOOL); g_assert(qobject_type(obj) == QTYPE_QBOOL);
qbool = qobject_to_qbool(obj); qbool = qobject_to_qbool(obj);
g_assert(qbool_get_int(qbool) != 0); g_assert(qbool_get_bool(qbool) == true);
str = qobject_to_json(obj); str = qobject_to_json(obj);
g_assert(strcmp(qstring_get_str(str), "true") == 0); g_assert(strcmp(qstring_get_str(str), "true") == 0);
@ -1026,7 +1026,7 @@ static void keyword_literal(void)
g_assert(qobject_type(obj) == QTYPE_QBOOL); g_assert(qobject_type(obj) == QTYPE_QBOOL);
qbool = qobject_to_qbool(obj); qbool = qobject_to_qbool(obj);
g_assert(qbool_get_int(qbool) == 0); g_assert(qbool_get_bool(qbool) == false);
str = qobject_to_json(obj); str = qobject_to_json(obj);
g_assert(strcmp(qstring_get_str(str), "false") == 0); g_assert(strcmp(qstring_get_str(str), "false") == 0);
@ -1039,16 +1039,17 @@ static void keyword_literal(void)
g_assert(qobject_type(obj) == QTYPE_QBOOL); g_assert(qobject_type(obj) == QTYPE_QBOOL);
qbool = qobject_to_qbool(obj); qbool = qobject_to_qbool(obj);
g_assert(qbool_get_int(qbool) == 0); g_assert(qbool_get_bool(qbool) == false);
QDECREF(qbool); QDECREF(qbool);
obj = qobject_from_jsonf("%i", true); /* Test that non-zero values other than 1 get collapsed to true */
obj = qobject_from_jsonf("%i", 2);
g_assert(obj != NULL); g_assert(obj != NULL);
g_assert(qobject_type(obj) == QTYPE_QBOOL); g_assert(qobject_type(obj) == QTYPE_QBOOL);
qbool = qobject_to_qbool(obj); qbool = qobject_to_qbool(obj);
g_assert(qbool_get_int(qbool) != 0); g_assert(qbool_get_bool(qbool) == true);
QDECREF(qbool); QDECREF(qbool);

View File

@ -60,8 +60,8 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque)
switch (qobject_type(obj1)) { switch (qobject_type(obj1)) {
case QTYPE_QBOOL: case QTYPE_QBOOL:
d->result = (qbool_get_int(qobject_to_qbool(obj1)) == d->result = (qbool_get_bool(qobject_to_qbool(obj1)) ==
qbool_get_int(qobject_to_qbool(obj2))); qbool_get_bool(qobject_to_qbool(obj2)));
return; return;
case QTYPE_QINT: case QTYPE_QINT:
d->result = (qint_get_int(qobject_to_qint(obj1)) == d->result = (qint_get_int(qobject_to_qint(obj1)) ==

View File

@ -72,7 +72,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *data,
obj = qmp_output_get_qobject(data->qov); obj = qmp_output_get_qobject(data->qov);
g_assert(obj != NULL); g_assert(obj != NULL);
g_assert(qobject_type(obj) == QTYPE_QBOOL); g_assert(qobject_type(obj) == QTYPE_QBOOL);
g_assert(qbool_get_int(qobject_to_qbool(obj)) == value); g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
qobject_decref(obj); qobject_decref(obj);
} }
@ -662,7 +662,7 @@ static void check_native_list(QObject *qobj,
tmp = qlist_peek(qlist); tmp = qlist_peek(qlist);
g_assert(tmp); g_assert(tmp);
qvalue = qobject_to_qbool(tmp); qvalue = qobject_to_qbool(tmp);
g_assert_cmpint(qbool_get_int(qvalue), ==, (i % 3 == 0) ? 1 : 0); g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
qobject_decref(qlist_pop(qlist)); qobject_decref(qlist_pop(qlist));
} }
break; break;

View File

@ -927,7 +927,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
break; break;
case QTYPE_QBOOL: case QTYPE_QBOOL:
pstrcpy(buf, sizeof(buf), pstrcpy(buf, sizeof(buf),
qbool_get_int(qobject_to_qbool(obj)) ? "on" : "off"); qbool_get_bool(qobject_to_qbool(obj)) ? "on" : "off");
value = buf; value = buf;
break; break;
default: default: