diff mbox series

[10/16] qapi/error: add g_autoptr(Error) support

Message ID 20220504173025.650167-11-marcandre.lureau@redhat.com (mailing list archive)
State New, archived
Headers show
Series Misc cleanups | expand

Commit Message

Marc-André Lureau May 4, 2022, 5:30 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Sometime, ERRP_GUARD() isn't what you are looking for, because the
function doesn't throw errors, yet auto-cleaning is nice to have.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qapi/error.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Paolo Bonzini May 5, 2022, 6:53 a.m. UTC | #1
This was rejected before on the grounds that propagating or printing the error is usually the right thing to do, and neither needs an autoptr:

https://patchew.org/QEMU/20210912124834.503032-1-pbonzini@redhat.com/

So while I do agree with the patch, for it to be accepted some Error* functions would have to be changed to accept Error** instead. This way they can NULL the variable containing their argument, and prevent the auto-error_free.

Paolo

Il 4 maggio 2022 19:30:19 CEST, marcandre.lureau@redhat.com ha scritto:
>From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>Sometime, ERRP_GUARD() isn't what you are looking for, because the
>function doesn't throw errors, yet auto-cleaning is nice to have.
>
>Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>---
> include/qapi/error.h | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/include/qapi/error.h b/include/qapi/error.h
>index d798faeec3e9..9482b6a58ae6 100644
>--- a/include/qapi/error.h
>+++ b/include/qapi/error.h
>@@ -519,6 +519,8 @@ static inline void error_propagator_cleanup(ErrorPropagator *prop)
> 
> G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
> 
>+G_DEFINE_AUTOPTR_CLEANUP_FUNC(Error, error_free);
>+
> /*
>  * Special error destination to abort on error.
>  * See error_setg() and error_propagate() for details.
diff mbox series

Patch

diff --git a/include/qapi/error.h b/include/qapi/error.h
index d798faeec3e9..9482b6a58ae6 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -519,6 +519,8 @@  static inline void error_propagator_cleanup(ErrorPropagator *prop)
 
 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(Error, error_free);
+
 /*
  * Special error destination to abort on error.
  * See error_setg() and error_propagate() for details.