diff mbox series

[RFC,v2,2/9] qapi/error: add (Error **errp) cleaning APIs

Message ID 20190923161231.22028-3-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series error: auto propagated local_err | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 23, 2019, 4:12 p.m. UTC
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/qapi/error.h | 22 ++++++++++++++++++++++
 util/error.c         |  6 +++---
 2 files changed, 25 insertions(+), 3 deletions(-)

Comments

Eric Blake Sept. 23, 2019, 6:39 p.m. UTC | #1
On 9/23/19 11:12 AM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---

A "why" as the commit message body wouldn't hurt.

>  include/qapi/error.h | 22 ++++++++++++++++++++++
>  util/error.c         |  6 +++---
>  2 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/include/qapi/error.h b/include/qapi/error.h
> index f6f4fa0fac..551385aa91 100644
> --- a/include/qapi/error.h
> +++ b/include/qapi/error.h
> @@ -297,6 +297,28 @@ void warn_report_err(Error *err);
>   */
>  void error_report_err(Error *err);
>  
> +/*
> + * Functions to clean Error **errp: call corresponding Error *err cleaning
> + * function an set pointer to NULL

s/an/and/

> + */
> +static inline void error_free_errp(Error **errp)
> +{
> +    error_free(*errp_in);

Fails to compile.  Did you mean for this to come after 3/9?

> +    *errp_in = NULL;
> +}
> +
> +static inline void error_report_errp(Error **errp)
> +{
> +    error_report_err(*errp_in);
> +    *errp_in = NULL;
> +}
> +
> +static inline void warn_report_errp(Error **errp)
> +{
> +    warn_report_err(*errp_in);
> +    *errp_in = NULL;
> +}
> +
>  /*
>   * Convenience function to error_prepend(), warn_report() and free @err.
>   */
> diff --git a/util/error.c b/util/error.c
> index d4532ce318..dfba091757 100644
> --- a/util/error.c
> +++ b/util/error.c
> @@ -273,9 +273,9 @@ void error_free(Error *err)
>  
>  void error_free_or_abort(Error **errp)
>  {
> -    assert(errp && *errp);
> -    error_free(*errp);
> -    *errp = NULL;
> +    assert(errp_in && *errp_in);
> +    error_free(*errp_in);
> +    *errp_in = NULL;

Did you mean to use error_free_errp() instead of these last two lines?

>  }
>  
>  void error_propagate(Error **dst_errp, Error *local_err)
>
diff mbox series

Patch

diff --git a/include/qapi/error.h b/include/qapi/error.h
index f6f4fa0fac..551385aa91 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -297,6 +297,28 @@  void warn_report_err(Error *err);
  */
 void error_report_err(Error *err);
 
+/*
+ * Functions to clean Error **errp: call corresponding Error *err cleaning
+ * function an set pointer to NULL
+ */
+static inline void error_free_errp(Error **errp)
+{
+    error_free(*errp_in);
+    *errp_in = NULL;
+}
+
+static inline void error_report_errp(Error **errp)
+{
+    error_report_err(*errp_in);
+    *errp_in = NULL;
+}
+
+static inline void warn_report_errp(Error **errp)
+{
+    warn_report_err(*errp_in);
+    *errp_in = NULL;
+}
+
 /*
  * Convenience function to error_prepend(), warn_report() and free @err.
  */
diff --git a/util/error.c b/util/error.c
index d4532ce318..dfba091757 100644
--- a/util/error.c
+++ b/util/error.c
@@ -273,9 +273,9 @@  void error_free(Error *err)
 
 void error_free_or_abort(Error **errp)
 {
-    assert(errp && *errp);
-    error_free(*errp);
-    *errp = NULL;
+    assert(errp_in && *errp_in);
+    error_free(*errp_in);
+    *errp_in = NULL;
 }
 
 void error_propagate(Error **dst_errp, Error *local_err)