[Spice-devel,v3,33/51] Implement ws_inline attribute

Submitted by Frediano Ziglio on July 21, 2015, 4:46 p.m.

Details

Message ID 1437497181-26929-34-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 21, 2015, 4:46 p.m.
This attribute allow structure to be aligned instead of be contained
in a separate function.
This is helpful as variable are declared in the function so allows
other member to reference to a nested structure.

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

Patch hide | download patch | download mbox

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index b204c61..3d822cc 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -378,9 +378,14 @@  def write_struct_func(writer, t, func_name, index):
 def write_struct(writer, member, t, index, dest, scope):
     assert(t.is_struct())
 
-    func_name = 'dissect_spice_struct_' + t.name
-    write_struct_func(writer, t, func_name, index)
-    writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
+    if member.has_attr('ws_inline'):
+        dest = dest.child_sub(member.name, scope)
+        with writer.block() as scope:
+            write_container_parser(writer, t, dest)
+    else:
+        func_name = 'dissect_spice_struct_' + t.name
+        write_struct_func(writer, t, func_name, index)
+        writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
 
 def write_member_primitive(writer, container, member, t, dest, scope):
     assert(t.is_primitive())

Comments

On Tue, Jul 21, 2015 at 05:46:03PM +0100, Frediano Ziglio wrote:
> This attribute allow structure to be aligned instead of be contained

'allows the structure parsing code to be inlined instead of being
contained ...' ?


> in a separate function.

> This is helpful as variable are declared in the function so allows
> other member to reference to a nested structure.

This second sentence is a bit more obscure :-/
"This is helpful as variables are declared in the function, so this
allows other members to access a nested structure" ? I think I get the
general idea, a small example as to when this is needed could be nice I
think.

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  python_modules/dissector.py | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/python_modules/dissector.py b/python_modules/dissector.py
> index b204c61..3d822cc 100644
> --- a/python_modules/dissector.py
> +++ b/python_modules/dissector.py
> @@ -378,9 +378,14 @@ def write_struct_func(writer, t, func_name, index):
>  def write_struct(writer, member, t, index, dest, scope):
>      assert(t.is_struct())
>  
> -    func_name = 'dissect_spice_struct_' + t.name
> -    write_struct_func(writer, t, func_name, index)
> -    writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
> +    if member.has_attr('ws_inline'):
> +        dest = dest.child_sub(member.name, scope)
> +        with writer.block() as scope:
> +            write_container_parser(writer, t, dest)
> +    else:
> +        func_name = 'dissect_spice_struct_' + t.name
> +        write_struct_func(writer, t, func_name, index)
> +        writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
>  
>  def write_member_primitive(writer, container, member, t, dest, scope):
>      assert(t.is_primitive())
> -- 
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel