[PATCH v3 29/44] qom: Make functions taking Error ** return bool, not 0/-1

Markus Armbruster posted 44 patches 5 years, 7 months ago
There is a newer version of this series
[PATCH v3 29/44] qom: Make functions taking Error ** return bool, not 0/-1
Posted by Markus Armbruster 5 years, 7 months ago
Just for consistency.  Also fix the example in object_set_props()'s
documentation.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 include/qom/object.h | 28 +++++++++++-----------------
 qom/object.c         | 14 +++++++-------
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 189f8ecbf6..04271ea5de 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -729,15 +729,13 @@ void object_apply_compat_props(Object *obj);
  *   Error *err = NULL;
  *   Object *obj = ...get / create object...;
  *
- *   obj = object_set_props(obj,
- *                          &err,
- *                          "share", "yes",
- *                          "mem-path", "/dev/shm/somefile",
- *                          "prealloc", "yes",
- *                          "size", "1048576",
- *                          NULL);
- *
- *   if (!obj) {
+ *   if (!object_set_props(obj,
+ *                         &err,
+ *                         "share", "yes",
+ *                         "mem-path", "/dev/shm/somefile",
+ *                         "prealloc", "yes",
+ *                         "size", "1048576",
+ *                         NULL)) {
  *     error_reportf_err(err, "Cannot set properties: ");
  *   }
  *   </programlisting>
@@ -746,11 +744,9 @@ void object_apply_compat_props(Object *obj);
  * The returned object will have one stable reference maintained
  * for as long as it is present in the object hierarchy.
  *
- * Returns: -1 on error, 0 on success
+ * Returns: %true on success, %false on error.
  */
-int object_set_props(Object *obj,
-                     Error **errp,
-                     ...) QEMU_SENTINEL;
+bool object_set_props(Object *obj, Error **errp, ...) QEMU_SENTINEL;
 
 /**
  * object_set_propv:
@@ -760,11 +756,9 @@ int object_set_props(Object *obj,
  *
  * See object_set_props() for documentation.
  *
- * Returns: -1 on error, 0 on success
+ * Returns: %true on success, %false on error.
  */
-int object_set_propv(Object *obj,
-                     Error **errp,
-                     va_list vargs);
+bool object_set_propv(Object *obj, Error **errp, va_list vargs);
 
 /**
  * object_initialize:
diff --git a/qom/object.c b/qom/object.c
index 25c5ddb78f..97c4e0af07 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -557,7 +557,7 @@ bool object_initialize_child_with_propsv(Object *parentobj,
     object_initialize(childobj, size, type);
     obj = OBJECT(childobj);
 
-    if (object_set_propv(obj, errp, vargs) < 0) {
+    if (!object_set_propv(obj, errp, vargs)) {
         goto out;
     }
 
@@ -752,7 +752,7 @@ Object *object_new_with_propv(const char *typename,
     }
     obj = object_new_with_type(klass->type);
 
-    if (object_set_propv(obj, errp, vargs) < 0) {
+    if (!object_set_propv(obj, errp, vargs)) {
         goto error;
     }
 
@@ -780,12 +780,12 @@ Object *object_new_with_propv(const char *typename,
 }
 
 
-int object_set_props(Object *obj,
+bool object_set_props(Object *obj,
                      Error **errp,
                      ...)
 {
     va_list vargs;
-    int ret;
+    bool ret;
 
     va_start(vargs, errp);
     ret = object_set_propv(obj, errp, vargs);
@@ -795,7 +795,7 @@ int object_set_props(Object *obj,
 }
 
 
-int object_set_propv(Object *obj,
+bool object_set_propv(Object *obj,
                      Error **errp,
                      va_list vargs)
 {
@@ -809,12 +809,12 @@ int object_set_propv(Object *obj,
         g_assert(value != NULL);
         if (!object_property_parse(obj, propname, value, &local_err)) {
             error_propagate(errp, local_err);
-            return -1;
+            return false;
         }
         propname = va_arg(vargs, char *);
     }
 
-    return 0;
+    return true;
 }
 
 
-- 
2.26.2


Re: [PATCH v3 29/44] qom: Make functions taking Error ** return bool, not 0/-1
Posted by Vladimir Sementsov-Ogievskiy 5 years, 7 months ago

On 06.07.2020 11:09, Markus Armbruster wrote:
> Just for consistency.  Also fix the example in object_set_props()'s
> documentation.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

Note, that object_set_props is unused and may be dropped.

> ---
>   include/qom/object.h | 28 +++++++++++-----------------
>   qom/object.c         | 14 +++++++-------
>   2 files changed, 18 insertions(+), 24 deletions(-)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 189f8ecbf6..04271ea5de 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -729,15 +729,13 @@ void object_apply_compat_props(Object *obj);
>    *   Error *err = NULL;
>    *   Object *obj = ...get / create object...;
>    *
> - *   obj = object_set_props(obj,
> - *                          &err,
> - *                          "share", "yes",
> - *                          "mem-path", "/dev/shm/somefile",
> - *                          "prealloc", "yes",
> - *                          "size", "1048576",
> - *                          NULL);
> - *
> - *   if (!obj) {
> + *   if (!object_set_props(obj,
> + *                         &err,
> + *                         "share", "yes",
> + *                         "mem-path", "/dev/shm/somefile",
> + *                         "prealloc", "yes",
> + *                         "size", "1048576",
> + *                         NULL)) {
>    *     error_reportf_err(err, "Cannot set properties: ");
>    *   }
>    *   </programlisting>
> @@ -746,11 +744,9 @@ void object_apply_compat_props(Object *obj);
>    * The returned object will have one stable reference maintained
>    * for as long as it is present in the object hierarchy.
>    *
> - * Returns: -1 on error, 0 on success
> + * Returns: %true on success, %false on error.
>    */
> -int object_set_props(Object *obj,
> -                     Error **errp,
> -                     ...) QEMU_SENTINEL;
> +bool object_set_props(Object *obj, Error **errp, ...) QEMU_SENTINEL;
>   
>   /**
>    * object_set_propv:
> @@ -760,11 +756,9 @@ int object_set_props(Object *obj,
>    *
>    * See object_set_props() for documentation.
>    *
> - * Returns: -1 on error, 0 on success
> + * Returns: %true on success, %false on error.
>    */
> -int object_set_propv(Object *obj,
> -                     Error **errp,
> -                     va_list vargs);
> +bool object_set_propv(Object *obj, Error **errp, va_list vargs);
>   
>   /**
>    * object_initialize:
> diff --git a/qom/object.c b/qom/object.c
> index 25c5ddb78f..97c4e0af07 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -557,7 +557,7 @@ bool object_initialize_child_with_propsv(Object *parentobj,
>       object_initialize(childobj, size, type);
>       obj = OBJECT(childobj);
>   
> -    if (object_set_propv(obj, errp, vargs) < 0) {
> +    if (!object_set_propv(obj, errp, vargs)) {
>           goto out;
>       }
>   
> @@ -752,7 +752,7 @@ Object *object_new_with_propv(const char *typename,
>       }
>       obj = object_new_with_type(klass->type);
>   
> -    if (object_set_propv(obj, errp, vargs) < 0) {
> +    if (!object_set_propv(obj, errp, vargs)) {
>           goto error;
>       }
>   
> @@ -780,12 +780,12 @@ Object *object_new_with_propv(const char *typename,
>   }
>   
>   
> -int object_set_props(Object *obj,
> +bool object_set_props(Object *obj,
>                        Error **errp,
>                        ...)
>   {
>       va_list vargs;
> -    int ret;
> +    bool ret;
>   
>       va_start(vargs, errp);
>       ret = object_set_propv(obj, errp, vargs);
> @@ -795,7 +795,7 @@ int object_set_props(Object *obj,
>   }
>   
>   
> -int object_set_propv(Object *obj,
> +bool object_set_propv(Object *obj,
>                        Error **errp,
>                        va_list vargs)
>   {
> @@ -809,12 +809,12 @@ int object_set_propv(Object *obj,
>           g_assert(value != NULL);
>           if (!object_property_parse(obj, propname, value, &local_err)) {
>               error_propagate(errp, local_err);
> -            return -1;
> +            return false;
>           }
>           propname = va_arg(vargs, char *);
>       }
>   
> -    return 0;
> +    return true;
>   }
>   
>   
> 

Re: [PATCH v3 29/44] qom: Make functions taking Error ** return bool, not 0/-1
Posted by Markus Armbruster 5 years, 7 months ago
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> On 06.07.2020 11:09, Markus Armbruster wrote:
>> Just for consistency.  Also fix the example in object_set_props()'s
>> documentation.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>
> Note, that object_set_props is unused and may be dropped.

True.  It's never been used.  It was added together with
object_set_propv(), probably out of habit to always have both a ... and
the va_list function.

Thanks!