X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=error.c;h=d3455ab9e6dbb214d8e86ced200255540e5e2acc;hb=a70c99c6140bd4b0d0bc3ddc7c5fc09a773921c6;hp=867eec2c1af8e5cf555d5068086729e66d1484b2;hpb=d5ec4f27c387c3b3200abb8656343b2519ea3047;p=qemu.git diff --git a/error.c b/error.c index 867eec2c1..d3455ab9e 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); } @@ -85,8 +100,8 @@ 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);