X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/448293961f889d635295ad5b1ecc57ce267801ba..c537d79cc523f6fa29f70a7055a93e2c128beb20:/error.c diff --git a/error.c b/error.c index 867eec2c1a..a52b7710d2 100644 --- a/error.c +++ b/error.c @@ -9,11 +9,13 @@ * This work is licensed under the terms of the GNU LGPL, version 2. See * the COPYING.LIB file in the top-level directory. */ + +#include "qemu-common.h" #include "error.h" +#include "qjson.h" +#include "qdict.h" #include "error_int.h" -#include "qemu-objects.h" #include "qerror.h" -#include struct Error { @@ -31,7 +33,7 @@ void error_set(Error **errp, const char *fmt, ...) return; } - err = qemu_mallocz(sizeof(*err)); + err = g_malloc0(sizeof(*err)); va_start(ap, fmt); err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap)); @@ -41,6 +43,19 @@ void error_set(Error **errp, const char *fmt, ...) *errp = err; } +Error *error_copy(const Error *err) +{ + Error *err_new; + + err_new = g_malloc0(sizeof(*err)); + err_new->msg = g_strdup(err->msg); + err_new->fmt = err->fmt; + err_new->obj = err->obj; + QINCREF(err_new->obj); + + return err_new; +} + bool error_is_set(Error **errp) { return (errp && *errp); @@ -51,7 +66,7 @@ const char *error_get_pretty(Error *err) if (err->msg == NULL) { QString *str; str = qerror_format(err->fmt, err->obj); - err->msg = qemu_strdup(qstring_get_str(str)); + err->msg = g_strdup(qstring_get_str(str)); QDECREF(str); } @@ -78,15 +93,15 @@ QDict *error_get_data(Error *err) void error_set_field(Error *err, const char *field, const char *value) { QDict *dict = qdict_get_qdict(err->obj, "data"); - return qdict_put(dict, field, qstring_from_str(value)); + qdict_put(dict, field, qstring_from_str(value)); } void error_free(Error *err) { if (err) { QDECREF(err->obj); - qemu_free(err->msg); - qemu_free(err); + g_free(err->msg); + g_free(err); } } @@ -96,6 +111,10 @@ bool error_is_type(Error *err, const char *fmt) char *ptr; char *end; + if (!err) { + return false; + } + ptr = strstr(fmt, "'class': '"); assert(ptr != NULL); ptr += strlen("'class': '"); @@ -132,7 +151,7 @@ void error_set_qobject(Error **errp, QObject *obj) if (errp == NULL) { return; } - err = qemu_mallocz(sizeof(*err)); + err = g_malloc0(sizeof(*err)); err->obj = qobject_to_qdict(obj); qobject_incref(obj);