mirror of https://gitee.com/openkylin/qemu.git
qobject: Use 'bool' inside qdict
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>
This commit is contained in:
parent
fc48ffc39e
commit
34acbc9522
40
hmp.c
40
hmp.c
|
@ -438,8 +438,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
|
||||||
BlockInfoList *block_list, *info;
|
BlockInfoList *block_list, *info;
|
||||||
BlockDeviceInfoList *blockdev_list, *blockdev;
|
BlockDeviceInfoList *blockdev_list, *blockdev;
|
||||||
const char *device = qdict_get_try_str(qdict, "device");
|
const char *device = qdict_get_try_str(qdict, "device");
|
||||||
bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
|
bool verbose = qdict_get_try_bool(qdict, "verbose", false);
|
||||||
bool nodes = qdict_get_try_bool(qdict, "nodes", 0);
|
bool nodes = qdict_get_try_bool(qdict, "nodes", false);
|
||||||
bool printed = false;
|
bool printed = false;
|
||||||
|
|
||||||
/* Print BlockBackend information */
|
/* Print BlockBackend information */
|
||||||
|
@ -995,7 +995,7 @@ void hmp_nmi(Monitor *mon, const QDict *qdict)
|
||||||
void hmp_set_link(Monitor *mon, const QDict *qdict)
|
void hmp_set_link(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
const char *name = qdict_get_str(qdict, "name");
|
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;
|
Error *err = NULL;
|
||||||
|
|
||||||
qmp_set_link(name, up, &err);
|
qmp_set_link(name, up, &err);
|
||||||
|
@ -1039,8 +1039,8 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
const char *filename = qdict_get_str(qdict, "target");
|
const char *filename = qdict_get_str(qdict, "target");
|
||||||
const char *format = qdict_get_try_str(qdict, "format");
|
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);
|
||||||
int full = qdict_get_try_bool(qdict, "full", 0);
|
bool full = qdict_get_try_bool(qdict, "full", false);
|
||||||
enum NewImageMode mode;
|
enum NewImageMode mode;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
|
@ -1069,8 +1069,8 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
const char *filename = qdict_get_str(qdict, "target");
|
const char *filename = qdict_get_str(qdict, "target");
|
||||||
const char *format = qdict_get_try_str(qdict, "format");
|
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);
|
||||||
int full = qdict_get_try_bool(qdict, "full", 0);
|
bool full = qdict_get_try_bool(qdict, "full", false);
|
||||||
enum NewImageMode mode;
|
enum NewImageMode mode;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
|
@ -1098,7 +1098,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
const char *filename = qdict_get_try_str(qdict, "snapshot-file");
|
const char *filename = qdict_get_try_str(qdict, "snapshot-file");
|
||||||
const char *format = qdict_get_try_str(qdict, "format");
|
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;
|
enum NewImageMode mode;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
|
@ -1294,7 +1294,7 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)
|
||||||
|
|
||||||
void hmp_eject(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");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
|
@ -1394,7 +1394,7 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
Error *error = NULL;
|
Error *error = NULL;
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
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);
|
qmp_block_job_cancel(device, true, force, &error);
|
||||||
|
|
||||||
|
@ -1474,9 +1474,9 @@ static void hmp_migrate_status_cb(void *opaque)
|
||||||
|
|
||||||
void hmp_migrate(Monitor *mon, const QDict *qdict)
|
void hmp_migrate(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
int detach = qdict_get_try_bool(qdict, "detach", 0);
|
bool detach = qdict_get_try_bool(qdict, "detach", false);
|
||||||
int blk = qdict_get_try_bool(qdict, "blk", 0);
|
bool blk = qdict_get_try_bool(qdict, "blk", false);
|
||||||
int inc = qdict_get_try_bool(qdict, "inc", 0);
|
bool inc = qdict_get_try_bool(qdict, "inc", false);
|
||||||
const char *uri = qdict_get_str(qdict, "uri");
|
const char *uri = qdict_get_str(qdict, "uri");
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
|
||||||
|
@ -1522,10 +1522,10 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
|
||||||
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
|
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
int paging = qdict_get_try_bool(qdict, "paging", 0);
|
bool paging = qdict_get_try_bool(qdict, "paging", false);
|
||||||
int zlib = qdict_get_try_bool(qdict, "zlib", 0);
|
bool zlib = qdict_get_try_bool(qdict, "zlib", false);
|
||||||
int lzo = qdict_get_try_bool(qdict, "lzo", 0);
|
bool lzo = qdict_get_try_bool(qdict, "lzo", false);
|
||||||
int snappy = qdict_get_try_bool(qdict, "snappy", 0);
|
bool snappy = qdict_get_try_bool(qdict, "snappy", false);
|
||||||
const char *file = qdict_get_str(qdict, "filename");
|
const char *file = qdict_get_str(qdict, "filename");
|
||||||
bool has_begin = qdict_haskey(qdict, "begin");
|
bool has_begin = qdict_haskey(qdict, "begin");
|
||||||
bool has_length = qdict_haskey(qdict, "length");
|
bool has_length = qdict_haskey(qdict, "length");
|
||||||
|
@ -1751,8 +1751,8 @@ void hmp_screendump(Monitor *mon, const QDict *qdict)
|
||||||
void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
const char *uri = qdict_get_str(qdict, "uri");
|
const char *uri = qdict_get_str(qdict, "uri");
|
||||||
int writable = qdict_get_try_bool(qdict, "writable", 0);
|
bool writable = qdict_get_try_bool(qdict, "writable", false);
|
||||||
int all = qdict_get_try_bool(qdict, "all", 0);
|
bool all = qdict_get_try_bool(qdict, "all", false);
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
BlockInfoList *block_list, *info;
|
BlockInfoList *block_list, *info;
|
||||||
SocketAddress *addr;
|
SocketAddress *addr;
|
||||||
|
@ -1805,7 +1805,7 @@ exit:
|
||||||
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
|
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
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;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
qmp_nbd_server_add(device, true, writable, &local_err);
|
qmp_nbd_server_add(device, true, writable, &local_err);
|
||||||
|
|
|
@ -975,7 +975,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
|
||||||
if (pcie_aer_parse_error_string(error_name, &error_status, &correctable)) {
|
if (pcie_aer_parse_error_string(error_name, &error_status, &correctable)) {
|
||||||
char *e = NULL;
|
char *e = NULL;
|
||||||
error_status = strtoul(error_name, &e, 0);
|
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') {
|
if (!e || *e != '\0') {
|
||||||
monitor_printf(mon, "invalid error status value. \"%s\"",
|
monitor_printf(mon, "invalid error status value. \"%s\"",
|
||||||
error_name);
|
error_name);
|
||||||
|
@ -989,7 +989,7 @@ static int do_pcie_aer_inject_error(Monitor *mon,
|
||||||
if (correctable) {
|
if (correctable) {
|
||||||
err.flags |= PCIE_AER_ERR_IS_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;
|
err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY;
|
||||||
}
|
}
|
||||||
if (qdict_haskey(qdict, "header0")) {
|
if (qdict_haskey(qdict, "header0")) {
|
||||||
|
|
|
@ -56,13 +56,13 @@ const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
|
||||||
/* High level helpers */
|
/* High level helpers */
|
||||||
double qdict_get_double(const QDict *qdict, const char *key);
|
double qdict_get_double(const QDict *qdict, const char *key);
|
||||||
int64_t qdict_get_int(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);
|
QList *qdict_get_qlist(const QDict *qdict, const char *key);
|
||||||
QDict *qdict_get_qdict(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);
|
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 qdict_get_try_int(const QDict *qdict, const char *key,
|
||||||
int64_t def_value);
|
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);
|
const char *qdict_get_try_str(const QDict *qdict, const char *key);
|
||||||
|
|
||||||
void qdict_copy_default(QDict *dst, QDict *src, const char *key);
|
void qdict_copy_default(QDict *dst, QDict *src, const char *key);
|
||||||
|
|
|
@ -2091,7 +2091,7 @@ static void hmp_mce(Monitor *mon, const QDict *qdict)
|
||||||
uint64_t misc = qdict_get_int(qdict, "misc");
|
uint64_t misc = qdict_get_int(qdict, "misc");
|
||||||
int flags = MCE_INJECT_UNCOND_AO;
|
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;
|
flags |= MCE_INJECT_BROADCAST;
|
||||||
}
|
}
|
||||||
cs = qemu_get_cpu(cpu_index);
|
cs = qemu_get_cpu(cpu_index);
|
||||||
|
|
|
@ -241,7 +241,7 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)
|
||||||
*
|
*
|
||||||
* Return bool mapped by '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);
|
QObject *obj = qdict_get_obj(qdict, key, QTYPE_QBOOL);
|
||||||
return qbool_get_bool(qobject_to_qbool(obj));
|
return qbool_get_bool(qobject_to_qbool(obj));
|
||||||
|
@ -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
|
* dictionary or if the stored object is not of QBool type
|
||||||
* 'def_value' will be returned.
|
* '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;
|
QObject *obj;
|
||||||
|
|
||||||
|
|
|
@ -223,7 +223,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data,
|
||||||
qdict = qobject_to_qdict(obj);
|
qdict = qobject_to_qdict(obj);
|
||||||
g_assert_cmpint(qdict_size(qdict), ==, 3);
|
g_assert_cmpint(qdict_size(qdict), ==, 3);
|
||||||
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
|
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");
|
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");
|
||||||
|
|
||||||
QDECREF(qdict);
|
QDECREF(qdict);
|
||||||
|
|
Loading…
Reference in New Issue