Skip to content

Commit

Permalink
qobject: Use 'bool' inside qdict
Browse files Browse the repository at this point in the history
Now that qbool is fixed, let's fix getting and setting a bool
value to a qdict member to also use C99 bool rather than int.

I audited all callers to ensure that the changed return type
will not cause any changed semantics.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
ebblake authored and Markus Armbruster committed Jun 22, 2015
1 parent fc48ffc commit 34acbc9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
40 changes: 20 additions & 20 deletions hmp.c
Expand Up @@ -438,8 +438,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
BlockInfoList *block_list, *info;
BlockDeviceInfoList *blockdev_list, *blockdev;
const char *device = qdict_get_try_str(qdict, "device");
bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
bool verbose = qdict_get_try_bool(qdict, "verbose", false);
bool nodes = qdict_get_try_bool(qdict, "nodes", false);
bool printed = false;

/* Print BlockBackend information */
Expand Down Expand Up @@ -995,7 +995,7 @@ void hmp_nmi(Monitor *mon, const QDict *qdict)
void hmp_set_link(Monitor *mon, const QDict *qdict)
{
const char *name = qdict_get_str(qdict, "name");
int up = qdict_get_bool(qdict, "up");
bool up = qdict_get_bool(qdict, "up");
Error *err = NULL;

qmp_set_link(name, up, &err);
Expand Down Expand Up @@ -1039,8 +1039,8 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_str(qdict, "device");
const char *filename = qdict_get_str(qdict, "target");
const char *format = qdict_get_try_str(qdict, "format");
int reuse = qdict_get_try_bool(qdict, "reuse", 0);
int full = qdict_get_try_bool(qdict, "full", 0);
bool reuse = qdict_get_try_bool(qdict, "reuse", false);
bool full = qdict_get_try_bool(qdict, "full", false);
enum NewImageMode mode;
Error *err = NULL;

Expand Down Expand Up @@ -1069,8 +1069,8 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_str(qdict, "device");
const char *filename = qdict_get_str(qdict, "target");
const char *format = qdict_get_try_str(qdict, "format");
int reuse = qdict_get_try_bool(qdict, "reuse", 0);
int full = qdict_get_try_bool(qdict, "full", 0);
bool reuse = qdict_get_try_bool(qdict, "reuse", false);
bool full = qdict_get_try_bool(qdict, "full", false);
enum NewImageMode mode;
Error *err = NULL;

Expand Down Expand Up @@ -1098,7 +1098,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_str(qdict, "device");
const char *filename = qdict_get_try_str(qdict, "snapshot-file");
const char *format = qdict_get_try_str(qdict, "format");
int reuse = qdict_get_try_bool(qdict, "reuse", 0);
bool reuse = qdict_get_try_bool(qdict, "reuse", false);
enum NewImageMode mode;
Error *err = NULL;

Expand Down Expand Up @@ -1294,7 +1294,7 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)

void hmp_eject(Monitor *mon, const QDict *qdict)
{
int force = qdict_get_try_bool(qdict, "force", 0);
bool force = qdict_get_try_bool(qdict, "force", false);
const char *device = qdict_get_str(qdict, "device");
Error *err = NULL;

Expand Down Expand Up @@ -1394,7 +1394,7 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
{
Error *error = NULL;
const char *device = qdict_get_str(qdict, "device");
bool force = qdict_get_try_bool(qdict, "force", 0);
bool force = qdict_get_try_bool(qdict, "force", false);

qmp_block_job_cancel(device, true, force, &error);

Expand Down Expand Up @@ -1474,9 +1474,9 @@ static void hmp_migrate_status_cb(void *opaque)

void hmp_migrate(Monitor *mon, const QDict *qdict)
{
int detach = qdict_get_try_bool(qdict, "detach", 0);
int blk = qdict_get_try_bool(qdict, "blk", 0);
int inc = qdict_get_try_bool(qdict, "inc", 0);
bool detach = qdict_get_try_bool(qdict, "detach", false);
bool blk = qdict_get_try_bool(qdict, "blk", false);
bool inc = qdict_get_try_bool(qdict, "inc", false);
const char *uri = qdict_get_str(qdict, "uri");
Error *err = NULL;

Expand Down Expand Up @@ -1522,10 +1522,10 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
int paging = qdict_get_try_bool(qdict, "paging", 0);
int zlib = qdict_get_try_bool(qdict, "zlib", 0);
int lzo = qdict_get_try_bool(qdict, "lzo", 0);
int snappy = qdict_get_try_bool(qdict, "snappy", 0);
bool paging = qdict_get_try_bool(qdict, "paging", false);
bool zlib = qdict_get_try_bool(qdict, "zlib", false);
bool lzo = qdict_get_try_bool(qdict, "lzo", false);
bool snappy = qdict_get_try_bool(qdict, "snappy", false);
const char *file = qdict_get_str(qdict, "filename");
bool has_begin = qdict_haskey(qdict, "begin");
bool has_length = qdict_haskey(qdict, "length");
Expand Down Expand Up @@ -1751,8 +1751,8 @@ void hmp_screendump(Monitor *mon, const QDict *qdict)
void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
{
const char *uri = qdict_get_str(qdict, "uri");
int writable = qdict_get_try_bool(qdict, "writable", 0);
int all = qdict_get_try_bool(qdict, "all", 0);
bool writable = qdict_get_try_bool(qdict, "writable", false);
bool all = qdict_get_try_bool(qdict, "all", false);
Error *local_err = NULL;
BlockInfoList *block_list, *info;
SocketAddress *addr;
Expand Down Expand Up @@ -1805,7 +1805,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
{
const char *device = qdict_get_str(qdict, "device");
int writable = qdict_get_try_bool(qdict, "writable", 0);
bool writable = qdict_get_try_bool(qdict, "writable", false);
Error *local_err = NULL;

qmp_nbd_server_add(device, true, writable, &local_err);
Expand Down
4 changes: 2 additions & 2 deletions hw/pci/pcie_aer.c
Expand Up @@ -975,7 +975,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
if (pcie_aer_parse_error_string(error_name, &error_status, &correctable)) {
char *e = NULL;
error_status = strtoul(error_name, &e, 0);
correctable = qdict_get_try_bool(qdict, "correctable", 0);
correctable = qdict_get_try_bool(qdict, "correctable", false);
if (!e || *e != '\0') {
monitor_printf(mon, "invalid error status value. \"%s\"",
error_name);
Expand All @@ -989,7 +989,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
if (correctable) {
err.flags |= PCIE_AER_ERR_IS_CORRECTABLE;
}
if (qdict_get_try_bool(qdict, "advisory_non_fatal", 0)) {
if (qdict_get_try_bool(qdict, "advisory_non_fatal", false)) {
err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY;
}
if (qdict_haskey(qdict, "header0")) {
Expand Down
4 changes: 2 additions & 2 deletions include/qapi/qmp/qdict.h
Expand Up @@ -56,13 +56,13 @@ const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
/* High level helpers */
double qdict_get_double(const QDict *qdict, const char *key);
int64_t qdict_get_int(const QDict *qdict, const char *key);
int qdict_get_bool(const QDict *qdict, const char *key);
bool qdict_get_bool(const QDict *qdict, const char *key);
QList *qdict_get_qlist(const QDict *qdict, const char *key);
QDict *qdict_get_qdict(const QDict *qdict, const char *key);
const char *qdict_get_str(const QDict *qdict, const char *key);
int64_t qdict_get_try_int(const QDict *qdict, const char *key,
int64_t def_value);
int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value);
bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value);
const char *qdict_get_try_str(const QDict *qdict, const char *key);

void qdict_copy_default(QDict *dst, QDict *src, const char *key);
Expand Down
2 changes: 1 addition & 1 deletion monitor.c
Expand Up @@ -2091,7 +2091,7 @@ static void hmp_mce(Monitor *mon, const QDict *qdict)
uint64_t misc = qdict_get_int(qdict, "misc");
int flags = MCE_INJECT_UNCOND_AO;

if (qdict_get_try_bool(qdict, "broadcast", 0)) {
if (qdict_get_try_bool(qdict, "broadcast", false)) {
flags |= MCE_INJECT_BROADCAST;
}
cs = qemu_get_cpu(cpu_index);
Expand Down
4 changes: 2 additions & 2 deletions qobject/qdict.c
Expand Up @@ -241,7 +241,7 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)
*
* Return bool mapped by 'key'.
*/
int qdict_get_bool(const QDict *qdict, const char *key)
bool qdict_get_bool(const QDict *qdict, const char *key)
{
QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL);
return qbool_get_bool(qobject_to_qbool(obj));
Expand Down Expand Up @@ -314,7 +314,7 @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key,
* dictionary or if the stored object is not of QBool type
* 'def_value' will be returned.
*/
int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value)
bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value)
{
QObject *obj;

Expand Down
2 changes: 1 addition & 1 deletion tests/test-qmp-output-visitor.c
Expand Up @@ -223,7 +223,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data,
qdict = qobject_to_qdict(obj);
g_assert_cmpint(qdict_size(qdict), ==, 3);
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, 0);
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");

QDECREF(qdict);
Expand Down

0 comments on commit 34acbc9

Please sign in to comment.