diff options
Diffstat (limited to 'qobject')
| -rw-r--r-- | qobject/Makefile.objs | 1 | ||||
| -rw-r--r-- | qobject/json-parser.c | 7 | ||||
| -rw-r--r-- | qobject/qbool.c | 8 | ||||
| -rw-r--r-- | qobject/qdict.c | 8 | ||||
| -rw-r--r-- | qobject/qerror.c | 148 | ||||
| -rw-r--r-- | qobject/qjson.c | 5 |
6 files changed, 12 insertions, 165 deletions
diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index f7595f56fe..0031e8b691 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,3 +1,2 @@ util-obj-y = qnull.o qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o util-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o -util-obj-y += qerror.o diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 717cb8fde7..ac991ba3cf 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -22,7 +22,6 @@ #include "qapi/qmp/qbool.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-lexer.h" -#include "qapi/qmp/qerror.h" typedef struct JSONParserContext { @@ -558,9 +557,9 @@ static QObject *parse_keyword(JSONParserContext *ctxt) } 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")) { - ret = QOBJECT(qbool_from_int(false)); + ret = QOBJECT(qbool_from_bool(false)); } else if (token_is_keyword(token, "null")) { ret = qnull(); } else { @@ -593,7 +592,7 @@ static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap) if (token_is_escape(token, "%p")) { obj = va_arg(*ap, QObject *); } 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")) { obj = QOBJECT(qint_from_int(va_arg(*ap, int))); } else if (token_is_escape(token, "%ld")) { diff --git a/qobject/qbool.c b/qobject/qbool.c index a3d2afa827..5ff69f0b2d 100644 --- a/qobject/qbool.c +++ b/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/qobject/qdict.c b/qobject/qdict.c index 190791becf..67b1a58abf 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -241,10 +241,10 @@ 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_int(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 * '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; @@ -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/qobject/qerror.c b/qobject/qerror.c deleted file mode 100644 index e3608e2402..0000000000 --- a/qobject/qerror.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * QError Module - * - * Copyright (C) 2009 Red Hat Inc. - * - * Authors: - * Luiz Capitulino <lcapitulino@redhat.com> - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - */ - -#include "monitor/monitor.h" -#include "qapi/qmp/qjson.h" -#include "qapi/qmp/qerror.h" -#include "qemu-common.h" - -static void qerror_destroy_obj(QObject *obj); - -static const QType qerror_type = { - .code = QTYPE_QERROR, - .destroy = qerror_destroy_obj, -}; - -/** - * qerror_new(): Create a new QError - * - * Return strong reference. - */ -static QError *qerror_new(void) -{ - QError *qerr; - - qerr = g_malloc0(sizeof(*qerr)); - QOBJECT_INIT(qerr, &qerror_type); - - return qerr; -} - -/** - * qerror_from_info(): Create a new QError from error information - * - * Return strong reference. - */ -static QError * GCC_FMT_ATTR(2, 0) -qerror_from_info(ErrorClass err_class, const char *fmt, va_list *va) -{ - QError *qerr; - - qerr = qerror_new(); - loc_save(&qerr->loc); - - qerr->err_msg = g_strdup_vprintf(fmt, *va); - qerr->err_class = err_class; - - return qerr; -} - -/** - * qerror_human(): Format QError data into human-readable string. - */ -QString *qerror_human(const QError *qerror) -{ - return qstring_from_str(qerror->err_msg); -} - -/** - * qerror_print(): Print QError data - * - * This function will print the member 'desc' of the specified QError object, - * it uses error_report() for this, so that the output is routed to the right - * place (ie. stderr or Monitor's device). - */ -static void qerror_print(QError *qerror) -{ - QString *qstring = qerror_human(qerror); - loc_push_restore(&qerror->loc); - error_report("%s", qstring_get_str(qstring)); - loc_pop(&qerror->loc); - QDECREF(qstring); -} - -void qerror_report(ErrorClass eclass, const char *fmt, ...) -{ - va_list va; - QError *qerror; - - va_start(va, fmt); - qerror = qerror_from_info(eclass, fmt, &va); - va_end(va); - - if (monitor_cur_is_qmp()) { - monitor_set_error(cur_mon, qerror); - } else { - qerror_print(qerror); - QDECREF(qerror); - } -} - -/* Evil... */ -struct Error -{ - char *msg; - ErrorClass err_class; -}; - -void qerror_report_err(Error *err) -{ - QError *qerr; - - qerr = qerror_new(); - loc_save(&qerr->loc); - qerr->err_msg = g_strdup(err->msg); - qerr->err_class = err->err_class; - - if (monitor_cur_is_qmp()) { - monitor_set_error(cur_mon, qerr); - } else { - qerror_print(qerr); - QDECREF(qerr); - } -} - -/** - * qobject_to_qerror(): Convert a QObject into a QError - */ -static QError *qobject_to_qerror(const QObject *obj) -{ - if (qobject_type(obj) != QTYPE_QERROR) { - return NULL; - } - - return container_of(obj, QError, base); -} - -/** - * qerror_destroy_obj(): Free all memory allocated by a QError - */ -static void qerror_destroy_obj(QObject *obj) -{ - QError *qerr; - - assert(obj != NULL); - qerr = qobject_to_qerror(obj); - - g_free(qerr->err_msg); - g_free(qerr); -} diff --git a/qobject/qjson.c b/qobject/qjson.c index 846733dafb..33f8ef530c 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -254,16 +254,13 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) case QTYPE_QBOOL: { QBool *val = qobject_to_qbool(obj); - if (qbool_get_int(val)) { + if (qbool_get_bool(val)) { qstring_append(str, "true"); } else { qstring_append(str, "false"); } break; } - case QTYPE_QERROR: - /* XXX: should QError be emitted? */ - break; default: abort(); } |