* [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value
2020-09-17 12:55 [PATCH 0/2] qpm: Minor error value corrections Markus Armbruster
@ 2020-09-17 12:55 ` Markus Armbruster
2020-09-17 12:59 ` Daniel P. Berrangé
2020-09-17 13:25 ` Greg Kurz
2020-09-17 12:55 ` [PATCH 2/2] qom: Correct error values in two contracts Markus Armbruster
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Markus Armbruster @ 2020-09-17 12:55 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, berrange, ehabkost, groug
object_property_get_enum() is the only object_property_FOO() that is
documented to return an undefined value on error. It does no such
thing, actually: it returns 0 on some errors, and -1 on others.
Needlessly complicated. Always return -1 on error, and adjust the
contract.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
include/qom/object.h | 6 +++---
qom/object.c | 6 +++---
tests/check-qom-proplist.c | 2 ++
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 056f67ab3b..f75547a3fe 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1687,9 +1687,9 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
* @typename: the name of the enum data type
* @errp: returns an error if this function fails
*
- * Returns: the value of the property, converted to an integer, or
- * undefined if an error occurs (including when the property value is not
- * an enum).
+ * Returns: the value of the property, converted to an integer (which
+ * can't be negative), or -1 on error (including when the property
+ * value is not an enum).
*/
int object_property_get_enum(Object *obj, const char *name,
const char *typename, Error **errp);
diff --git a/qom/object.c b/qom/object.c
index 387efb25eb..cecad35b99 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1564,21 +1564,21 @@ int object_property_get_enum(Object *obj, const char *name,
EnumProperty *enumprop;
if (prop == NULL) {
- return 0;
+ return -1;
}
if (!g_str_equal(prop->type, typename)) {
error_setg(errp, "Property %s on %s is not '%s' enum type",
name, object_class_get_name(
object_get_class(obj)), typename);
- return 0;
+ return -1;
}
enumprop = prop->opaque;
str = object_property_get_str(obj, name, errp);
if (!str) {
- return 0;
+ return -1;
}
ret = qapi_enum_parse(enumprop->lookup, str, -1, errp);
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 1571606c1c..1b76581980 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -491,6 +491,7 @@ static void test_dummy_getenum(void)
"av",
"BadAnimal",
&err);
+ g_assert(val == -1);
error_free_or_abort(&err);
/* A non-enum property name */
@@ -498,6 +499,7 @@ static void test_dummy_getenum(void)
"iv",
"DummyAnimal",
&err);
+ g_assert(val == -1);
error_free_or_abort(&err);
object_unparent(OBJECT(dobj));
--
2.26.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value
2020-09-17 12:55 ` [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value Markus Armbruster
@ 2020-09-17 12:59 ` Daniel P. Berrangé
2020-09-17 13:25 ` Greg Kurz
1 sibling, 0 replies; 10+ messages in thread
From: Daniel P. Berrangé @ 2020-09-17 12:59 UTC (permalink / raw)
To: Markus Armbruster; +Cc: pbonzini, groug, qemu-devel, ehabkost
On Thu, Sep 17, 2020 at 02:55:39PM +0200, Markus Armbruster wrote:
> object_property_get_enum() is the only object_property_FOO() that is
> documented to return an undefined value on error. It does no such
> thing, actually: it returns 0 on some errors, and -1 on others.
>
> Needlessly complicated. Always return -1 on error, and adjust the
> contract.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> include/qom/object.h | 6 +++---
> qom/object.c | 6 +++---
> tests/check-qom-proplist.c | 2 ++
> 3 files changed, 8 insertions(+), 6 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value
2020-09-17 12:55 ` [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value Markus Armbruster
2020-09-17 12:59 ` Daniel P. Berrangé
@ 2020-09-17 13:25 ` Greg Kurz
1 sibling, 0 replies; 10+ messages in thread
From: Greg Kurz @ 2020-09-17 13:25 UTC (permalink / raw)
To: Markus Armbruster; +Cc: pbonzini, berrange, qemu-devel, ehabkost
On Thu, 17 Sep 2020 14:55:39 +0200
Markus Armbruster <armbru@redhat.com> wrote:
> object_property_get_enum() is the only object_property_FOO() that is
> documented to return an undefined value on error. It does no such
> thing, actually: it returns 0 on some errors, and -1 on others.
>
> Needlessly complicated. Always return -1 on error, and adjust the
> contract.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> include/qom/object.h | 6 +++---
> qom/object.c | 6 +++---
> tests/check-qom-proplist.c | 2 ++
> 3 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 056f67ab3b..f75547a3fe 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1687,9 +1687,9 @@ uint64_t object_property_get_uint(Object *obj, const char *name,
> * @typename: the name of the enum data type
> * @errp: returns an error if this function fails
> *
> - * Returns: the value of the property, converted to an integer, or
> - * undefined if an error occurs (including when the property value is not
> - * an enum).
> + * Returns: the value of the property, converted to an integer (which
> + * can't be negative), or -1 on error (including when the property
> + * value is not an enum).
> */
> int object_property_get_enum(Object *obj, const char *name,
> const char *typename, Error **errp);
> diff --git a/qom/object.c b/qom/object.c
> index 387efb25eb..cecad35b99 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1564,21 +1564,21 @@ int object_property_get_enum(Object *obj, const char *name,
> EnumProperty *enumprop;
>
> if (prop == NULL) {
> - return 0;
> + return -1;
> }
>
> if (!g_str_equal(prop->type, typename)) {
> error_setg(errp, "Property %s on %s is not '%s' enum type",
> name, object_class_get_name(
> object_get_class(obj)), typename);
> - return 0;
> + return -1;
> }
>
> enumprop = prop->opaque;
>
> str = object_property_get_str(obj, name, errp);
> if (!str) {
> - return 0;
> + return -1;
> }
>
> ret = qapi_enum_parse(enumprop->lookup, str, -1, errp);
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index 1571606c1c..1b76581980 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -491,6 +491,7 @@ static void test_dummy_getenum(void)
> "av",
> "BadAnimal",
> &err);
> + g_assert(val == -1);
> error_free_or_abort(&err);
>
> /* A non-enum property name */
> @@ -498,6 +499,7 @@ static void test_dummy_getenum(void)
> "iv",
> "DummyAnimal",
> &err);
> + g_assert(val == -1);
> error_free_or_abort(&err);
>
> object_unparent(OBJECT(dobj));
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] qom: Correct error values in two contracts
2020-09-17 12:55 [PATCH 0/2] qpm: Minor error value corrections Markus Armbruster
2020-09-17 12:55 ` [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value Markus Armbruster
@ 2020-09-17 12:55 ` Markus Armbruster
2020-09-17 12:59 ` Daniel P. Berrangé
2020-09-17 13:31 ` Greg Kurz
2020-09-17 13:03 ` [PATCH 0/2] qpm: Minor error value corrections no-reply
` (2 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Markus Armbruster @ 2020-09-17 12:55 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, berrange, ehabkost, groug
object_property_get_bool()'s contract claims it returns NULL on error.
Pasto; it returns false.
object_property_get_int()'s contract claims it returns "negative". It
actually returns -1. All the other object_property_get_FOO()
contracts specify the exact error value, so do the same here.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
include/qom/object.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index f75547a3fe..d0a3332c1f 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1624,7 +1624,7 @@ bool object_property_set_bool(Object *obj, const char *name,
* @name: the name of the property
* @errp: returns an error if this function fails
*
- * Returns: the value of the property, converted to a boolean, or NULL if
+ * Returns: the value of the property, converted to a boolean, or false if
* an error occurs (including when the property value is not a bool).
*/
bool object_property_get_bool(Object *obj, const char *name,
@@ -1649,7 +1649,7 @@ bool object_property_set_int(Object *obj, const char *name,
* @name: the name of the property
* @errp: returns an error if this function fails
*
- * Returns: the value of the property, converted to an integer, or negative if
+ * Returns: the value of the property, converted to an integer, or -1 if
* an error occurs (including when the property value is not an integer).
*/
int64_t object_property_get_int(Object *obj, const char *name,
--
2.26.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qom: Correct error values in two contracts
2020-09-17 12:55 ` [PATCH 2/2] qom: Correct error values in two contracts Markus Armbruster
@ 2020-09-17 12:59 ` Daniel P. Berrangé
2020-09-17 13:31 ` Greg Kurz
1 sibling, 0 replies; 10+ messages in thread
From: Daniel P. Berrangé @ 2020-09-17 12:59 UTC (permalink / raw)
To: Markus Armbruster; +Cc: pbonzini, groug, qemu-devel, ehabkost
On Thu, Sep 17, 2020 at 02:55:40PM +0200, Markus Armbruster wrote:
> object_property_get_bool()'s contract claims it returns NULL on error.
> Pasto; it returns false.
>
> object_property_get_int()'s contract claims it returns "negative". It
> actually returns -1. All the other object_property_get_FOO()
> contracts specify the exact error value, so do the same here.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> include/qom/object.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qom: Correct error values in two contracts
2020-09-17 12:55 ` [PATCH 2/2] qom: Correct error values in two contracts Markus Armbruster
2020-09-17 12:59 ` Daniel P. Berrangé
@ 2020-09-17 13:31 ` Greg Kurz
1 sibling, 0 replies; 10+ messages in thread
From: Greg Kurz @ 2020-09-17 13:31 UTC (permalink / raw)
To: Markus Armbruster; +Cc: pbonzini, berrange, qemu-devel, ehabkost
On Thu, 17 Sep 2020 14:55:40 +0200
Markus Armbruster <armbru@redhat.com> wrote:
> object_property_get_bool()'s contract claims it returns NULL on error.
> Pasto; it returns false.
>
> object_property_get_int()'s contract claims it returns "negative". It
> actually returns -1. All the other object_property_get_FOO()
> contracts specify the exact error value, so do the same here.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
Reviewed-by: Greg Kurz <groug@kaod.org>
> include/qom/object.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index f75547a3fe..d0a3332c1f 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1624,7 +1624,7 @@ bool object_property_set_bool(Object *obj, const char *name,
> * @name: the name of the property
> * @errp: returns an error if this function fails
> *
> - * Returns: the value of the property, converted to a boolean, or NULL if
> + * Returns: the value of the property, converted to a boolean, or false if
> * an error occurs (including when the property value is not a bool).
> */
> bool object_property_get_bool(Object *obj, const char *name,
> @@ -1649,7 +1649,7 @@ bool object_property_set_int(Object *obj, const char *name,
> * @name: the name of the property
> * @errp: returns an error if this function fails
> *
> - * Returns: the value of the property, converted to an integer, or negative if
> + * Returns: the value of the property, converted to an integer, or -1 if
> * an error occurs (including when the property value is not an integer).
> */
> int64_t object_property_get_int(Object *obj, const char *name,
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] qpm: Minor error value corrections
2020-09-17 12:55 [PATCH 0/2] qpm: Minor error value corrections Markus Armbruster
2020-09-17 12:55 ` [PATCH 1/2] qom: Clean up object_property_get_enum()'s error value Markus Armbruster
2020-09-17 12:55 ` [PATCH 2/2] qom: Correct error values in two contracts Markus Armbruster
@ 2020-09-17 13:03 ` no-reply
2020-09-17 13:06 ` no-reply
2020-09-17 17:28 ` Eduardo Habkost
4 siblings, 0 replies; 10+ messages in thread
From: no-reply @ 2020-09-17 13:03 UTC (permalink / raw)
To: armbru; +Cc: pbonzini, groug, berrange, qemu-devel, ehabkost
Patchew URL: https://patchew.org/QEMU/20200917125540.597786-1-armbru@redhat.com/
Hi,
This series failed build test on FreeBSD host. Please find the details below.
The full log is available at
http://patchew.org/logs/20200917125540.597786-1-armbru@redhat.com/testing.FreeBSD/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] qpm: Minor error value corrections
2020-09-17 12:55 [PATCH 0/2] qpm: Minor error value corrections Markus Armbruster
` (2 preceding siblings ...)
2020-09-17 13:03 ` [PATCH 0/2] qpm: Minor error value corrections no-reply
@ 2020-09-17 13:06 ` no-reply
2020-09-17 17:28 ` Eduardo Habkost
4 siblings, 0 replies; 10+ messages in thread
From: no-reply @ 2020-09-17 13:06 UTC (permalink / raw)
To: armbru; +Cc: pbonzini, groug, berrange, qemu-devel, ehabkost
Patchew URL: https://patchew.org/QEMU/20200917125540.597786-1-armbru@redhat.com/
Hi,
This series seems to have some coding style problems. See output below for
more information:
N/A. Internal error while reading log file
The full log is available at
http://patchew.org/logs/20200917125540.597786-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] qpm: Minor error value corrections
2020-09-17 12:55 [PATCH 0/2] qpm: Minor error value corrections Markus Armbruster
` (3 preceding siblings ...)
2020-09-17 13:06 ` no-reply
@ 2020-09-17 17:28 ` Eduardo Habkost
4 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2020-09-17 17:28 UTC (permalink / raw)
To: Markus Armbruster; +Cc: pbonzini, berrange, qemu-devel, groug
On Thu, Sep 17, 2020 at 02:55:38PM +0200, Markus Armbruster wrote:
> Markus Armbruster (2):
> qom: Clean up object_property_get_enum()'s error value
> qom: Correct error values in two contracts
Queued, thanks!
--
Eduardo
^ permalink raw reply [flat|nested] 10+ messages in thread