[Spice-devel,v3,39/51] Allows to have two type with different size to point to same field name

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

Details

Message ID 1437497181-26929-40-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.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 python_modules/dissector.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index c88118f..554f59c 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -45,17 +45,14 @@  class HF:
         hf_writer.variable_def("static int", "%s = -1" % self.hf_name)
 
     def create(self):
-        other = self.fields.get(self.ws_name)
+        other = self.fields.get(self.hf_name)
         if other:
-            for f in 'hf_name desc ws_name base vals mask'.split():
+            for f in 'hf_name desc ws_name f_type base vals mask'.split():
                 if other.__dict__[f] != self.__dict__[f]:
                     raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
-            if other.f_type != self.f_type:
-                if other.f_type[:7] != 'FT_UINT' or self.f_type[:7] != 'FT_UINT':
-                    raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
             return
 
-        self.fields[self.ws_name] = self
+        self.fields[self.hf_name] = self
 
         self.add_wireshark_field()
 
@@ -297,6 +294,8 @@  def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
 
     assert(member and container)
 
+    size_name = ''
+
     # compute proper type
     f_type = 'FT_NONE'
     base = 'BASE_NONE'
@@ -305,6 +304,7 @@  def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
         assert(t.is_primitive())
         base = 'BASE_DEC'
         f_type = get_primitive_ft_type(t)
+        size_name = str(t.get_fixed_nw_size() * 8)
         if isinstance(t, ptypes.FlagsType):
             # show flag as hexadecimal for now
             base = 'BASE_HEX'
@@ -342,7 +342,7 @@  def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
         hf_name = member_hf_name(container, member)
         ws_name = 'auto.' + hf_name[3:]
     else:
-        hf_name = 'hf_%s' % ws_name.replace('.', '_')
+        hf_name = 'hf_%s%s' % (ws_name.replace('.', '_'), size_name)
 
     writer.statement("%sproto_tree_add_item(%s, %s, glb->tvb, offset, %s, %s)" %
             (prefix, tree, hf_name, size, encoding))

Comments

Can you add a short "why ?" explanation to the commit log ?


On Tue, Jul 21, 2015 at 05:46:09PM +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  python_modules/dissector.py | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/python_modules/dissector.py b/python_modules/dissector.py
> index c88118f..554f59c 100644
> --- a/python_modules/dissector.py
> +++ b/python_modules/dissector.py
> @@ -45,17 +45,14 @@ class HF:
>          hf_writer.variable_def("static int", "%s = -1" % self.hf_name)
>  
>      def create(self):
> -        other = self.fields.get(self.ws_name)
> +        other = self.fields.get(self.hf_name)
>          if other:
> -            for f in 'hf_name desc ws_name base vals mask'.split():
> +            for f in 'hf_name desc ws_name f_type base vals mask'.split():
>                  if other.__dict__[f] != self.__dict__[f]:
>                      raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
> -            if other.f_type != self.f_type:
> -                if other.f_type[:7] != 'FT_UINT' or self.f_type[:7] != 'FT_UINT':
> -                    raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
>              return
>  
> -        self.fields[self.ws_name] = self
> +        self.fields[self.hf_name] = self
>  
>          self.add_wireshark_field()
>  
> @@ -297,6 +294,8 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
>  
>      assert(member and container)
>  
> +    size_name = ''
> +
>      # compute proper type
>      f_type = 'FT_NONE'
>      base = 'BASE_NONE'
> @@ -305,6 +304,7 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
>          assert(t.is_primitive())
>          base = 'BASE_DEC'
>          f_type = get_primitive_ft_type(t)
> +        size_name = str(t.get_fixed_nw_size() * 8)
>          if isinstance(t, ptypes.FlagsType):
>              # show flag as hexadecimal for now
>              base = 'BASE_HEX'
> @@ -342,7 +342,7 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
>          hf_name = member_hf_name(container, member)
>          ws_name = 'auto.' + hf_name[3:]
>      else:
> -        hf_name = 'hf_%s' % ws_name.replace('.', '_')
> +        hf_name = 'hf_%s%s' % (ws_name.replace('.', '_'), size_name)
>  
>      writer.statement("%sproto_tree_add_item(%s, %s, glb->tvb, offset, %s, %s)" %
>              (prefix, tree, hf_name, size, encoding))
> -- 
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel