From d544d8334814cc6d1bfd5788c42e09c0fbdeff4c Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 13 Feb 2018 17:13:24 -0500 Subject: [PATCH] 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. Backports commit fc48ffc39ed1060856475e4320d5896f26c945e8 from qemu --- qemu/include/qapi/qmp/qbool.h | 6 +++--- qemu/qapi/qmp-input-visitor.c | 2 +- qemu/qapi/qmp-output-visitor.c | 2 +- qemu/qobject/qbool.c | 8 ++++---- qemu/qobject/qdict.c | 4 ++-- qemu/qom/object.c | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/qemu/include/qapi/qmp/qbool.h b/qemu/include/qapi/qmp/qbool.h index 5304dc5e..31677d04 100644 --- a/qemu/include/qapi/qmp/qbool.h +++ b/qemu/include/qapi/qmp/qbool.h @@ -19,11 +19,11 @@ typedef struct QBool { QObject_HEAD; - int value; + bool value; } QBool; -QBool *qbool_from_int(int value); -int qbool_get_int(const QBool *qb); +QBool *qbool_from_bool(bool value); +bool qbool_get_bool(const QBool *qb); QBool *qobject_to_qbool(const QObject *obj); #endif /* QBOOL_H */ diff --git a/qemu/qapi/qmp-input-visitor.c b/qemu/qapi/qmp-input-visitor.c index 33dd754b..070be5c5 100644 --- a/qemu/qapi/qmp-input-visitor.c +++ b/qemu/qapi/qmp-input-visitor.c @@ -248,7 +248,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name, 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, diff --git a/qemu/qapi/qmp-output-visitor.c b/qemu/qapi/qmp-output-visitor.c index 96b33846..7e0f7ce1 100644 --- a/qemu/qapi/qmp-output-visitor.c +++ b/qemu/qapi/qmp-output-visitor.c @@ -166,7 +166,7 @@ static void qmp_output_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { 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, diff --git a/qemu/qobject/qbool.c b/qemu/qobject/qbool.c index df4a23b7..8173073e 100644 --- a/qemu/qobject/qbool.c +++ b/qemu/qobject/qbool.c @@ -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. */ -QBool *qbool_from_int(int value) +QBool *qbool_from_bool(bool value) { 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; } diff --git a/qemu/qobject/qdict.c b/qemu/qobject/qdict.c index e1a96a42..6f0effe1 100644 --- a/qemu/qobject/qdict.c +++ b/qemu/qobject/qdict.c @@ -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) { 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) return def_value; - return qbool_get_int(qobject_to_qbool(obj)); + return qbool_get_bool(qobject_to_qbool(obj)); } /** diff --git a/qemu/qom/object.c b/qemu/qom/object.c index 6db01ec4..6ccbcbf5 100644 --- a/qemu/qom/object.c +++ b/qemu/qom/object.c @@ -893,7 +893,7 @@ Object *object_property_get_link(struct uc_struct *uc, Object *obj, const char * void object_property_set_bool(struct uc_struct *uc, Object *obj, bool value, const char *name, Error **errp) { - QBool *qbool = qbool_from_int(value); + QBool *qbool = qbool_from_bool(value); object_property_set_qobject(uc, obj, QOBJECT(qbool), name, errp); QDECREF(qbool); @@ -914,7 +914,7 @@ bool object_property_get_bool(struct uc_struct *uc, Object *obj, const char *nam error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); retval = false; } else { - retval = qbool_get_int(qbool); + retval = qbool_get_bool(qbool); } QDECREF(qbool);