qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PULL v2 02/11] error: New convenience function error_repor


From: Markus Armbruster
Subject: [Qemu-devel] [PULL v2 02/11] error: New convenience function error_report_err()
Date: Wed, 18 Feb 2015 12:10:32 +0100

I've typed error_report("%s", error_get_pretty(ERR)) too many times
already, and I've fixed too many instances of qerror_report_err(ERR)
to error_report("%s", error_get_pretty(ERR)) as well.  Capture the
pattern in a convenience function.

Since it's almost invariably followed by error_free(), stuff that into
the convenience function as well.

The next patch will put it to use.

Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
 include/qapi/error.h | 5 +++++
 util/error.c         | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index d712089..f44c451 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -83,6 +83,11 @@ Error *error_copy(const Error *err);
 const char *error_get_pretty(Error *err);
 
 /**
+ * Convenience function to error_report() and free an error object.
+ */
+void error_report_err(Error *);
+
+/**
  * Propagate an error to an indirect pointer to an error.  This function will
  * always transfer ownership of the error reference and handles the case where
  * dst_err is NULL correctly.  Errors after the first are discarded.
diff --git a/util/error.c b/util/error.c
index 2ace0d8..1ff6ae5 100644
--- a/util/error.c
+++ b/util/error.c
@@ -152,6 +152,12 @@ const char *error_get_pretty(Error *err)
     return err->msg;
 }
 
+void error_report_err(Error *err)
+{
+    error_report("%s", error_get_pretty(err));
+    error_free(err);
+}
+
 void error_free(Error *err)
 {
     if (err) {
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]