[spice-common,2/4] codegen: Add a check for C structure fields

Submitted by Frediano Ziglio on Aug. 13, 2019, 4:56 p.m.

Details

Message ID 20190813165608.32249-2-fziglio@redhat.com
State Accepted
Commit c392a7fee759c7f3bdfdb5fe30aa27112661f24b
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Aug. 13, 2019, 4:56 p.m.
This check make sure that output fields for member with @end (arrays)
are declared as empty arrays in output C structure.
This avoids output fields to be declared as pointer or other
invalid types.
The check is a compile time check so no code in object file
is generated.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 python_modules/demarshal.py | 3 +++
 1 file changed, 3 insertions(+)

Patch hide | download patch | download mbox

diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 6d8dbdd..acd4b6f 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -805,6 +805,9 @@  def write_array_parser(writer, member, nelements, array, dest, scope):
     if member:
         array_start = dest.get_ref(member.name)
         at_end = member.has_end_attr()
+        # the field is supposed to be a [0] array, check it
+        if at_end:
+            writer.statement('verify(sizeof(%s) == 0)' % array_start)
     else:
         array_start = "end"
         at_end = True

Comments

On 8/13/19 7:56 PM, Frediano Ziglio wrote:
> This check make sure that output fields for member with @end (arrays)
> are declared as empty arrays in output C structure.
> This avoids output fields to be declared as pointer or other
> invalid types.
> The check is a compile time check so no code in object file
> is generated.
> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Ack.

Uri

> ---
>   python_modules/demarshal.py | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
> index 6d8dbdd..acd4b6f 100644
> --- a/python_modules/demarshal.py
> +++ b/python_modules/demarshal.py
> @@ -805,6 +805,9 @@ def write_array_parser(writer, member, nelements, array, dest, scope):
>       if member:
>           array_start = dest.get_ref(member.name)
>           at_end = member.has_end_attr()
> +        # the field is supposed to be a [0] array, check it
> +        if at_end:
> +            writer.statement('verify(sizeof(%s) == 0)' % array_start)
>       else:
>           array_start = "end"
>           at_end = True
>