diff mbox

[08/14] qlit: add QLIT_QNULL and QLIT_BOOL

Message ID 20170824103350.16400-9-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Aug. 24, 2017, 10:33 a.m. UTC
As they are going to be used in the following patches.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qapi/qmp/qlit.h | 5 +++++
 qobject/qlit.c          | 4 ++++
 2 files changed, 9 insertions(+)

Comments

Markus Armbruster Aug. 25, 2017, 6:57 a.m. UTC | #1
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> As they are going to be used in the following patches.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 8882016199..7118fc9e32 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -23,6 +23,7 @@  typedef struct QLitObject QLitObject;
 struct QLitObject {
     int type;
     union {
+        bool qbool;
         int64_t qnum;
         const char *qstr;
         QLitDictEntry *qdict;
@@ -35,6 +36,10 @@  struct QLitDictEntry {
     QLitObject value;
 };
 
+#define QLIT_QNULL \
+    { .type = QTYPE_QNULL }
+#define QLIT_QBOOL(val) \
+    { .type = QTYPE_QBOOL, .value.qbool = (val) }
 #define QLIT_QNUM(val) \
     { .type = QTYPE_QNUM, .value.qnum = (val) }
 #define QLIT_QSTR(val) \
diff --git a/qobject/qlit.c b/qobject/qlit.c
index ae2787ef35..07ad6b05e8 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -50,6 +50,8 @@  bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
     }
 
     switch (lhs->type) {
+    case QTYPE_QBOOL:
+        return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
     case QTYPE_QNUM:
         g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
         return lhs->value.qnum == val;
@@ -81,6 +83,8 @@  bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 
         return helper.result;
     }
+    case QTYPE_QNULL:
+        return true;
     default:
         break;
     }