diff mbox series

qom/object: add some interface asserts

Message ID 20180912125303.29158-1-marcandre.lureau@redhat.com
State New
Headers show
Series qom/object: add some interface asserts | expand

Commit Message

Marc-André Lureau Sept. 12, 2018, 12:53 p.m. UTC
An interface can't have any instance size or callback, or itself
implement other interfaces (this is unsupported).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qom/object.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini Sept. 18, 2018, 8:17 a.m. UTC | #1
On 12/09/2018 14:53, Marc-André Lureau wrote:
> An interface can't have any instance size or callback, or itself
> implement other interfaces (this is unsupported).
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qom/object.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 75d1d48944..9222b23172 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -286,7 +286,14 @@ static void type_initialize(TypeImpl *ti)
>      if (ti->instance_size == 0) {
>          ti->abstract = true;
>      }
> -
> +    if (type_is_ancestor(ti, type_interface)) {
> +        assert(ti->instance_size == 0);
> +        assert(ti->abstract);
> +        assert(!ti->instance_init);
> +        assert(!ti->instance_post_init);
> +        assert(!ti->instance_finalize);
> +        assert(!ti->num_interfaces);
> +    }
>      ti->class = g_malloc0(ti->class_size);
>  
>      parent = type_get_parent(ti);
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/qom/object.c b/qom/object.c
index 75d1d48944..9222b23172 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -286,7 +286,14 @@  static void type_initialize(TypeImpl *ti)
     if (ti->instance_size == 0) {
         ti->abstract = true;
     }
-
+    if (type_is_ancestor(ti, type_interface)) {
+        assert(ti->instance_size == 0);
+        assert(ti->abstract);
+        assert(!ti->instance_init);
+        assert(!ti->instance_post_init);
+        assert(!ti->instance_finalize);
+        assert(!ti->num_interfaces);
+    }
     ti->class = g_malloc0(ti->class_size);
 
     parent = type_get_parent(ti);