[Spice-devel] [PATCH spice-common 4/4] Check for messages with duplicate values inside a channel

Frediano Ziglio fziglio at redhat.com
Mon May 14 22:18:54 UTC 2018


Make sure there are not 2 messages with the same value in the
same channel.

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

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 664dd1d..1b05cc6 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -1039,6 +1039,10 @@ class ChannelType(Type):
                     self.messages_byname = {}
                 self.count = 1
 
+                self.messages_byvalue = {}
+                for m in self.messages:
+                    self.messages_byvalue[m.value] = m
+
         server_info = MessagesInfo(self.base, True)
         client_info = MessagesInfo(self.base, False)
 
@@ -1059,6 +1063,10 @@ class ChannelType(Type):
                     raise Exception("Duplicated message name between %s and %s in channel %s" % (
                         info.messages_byname[m.name].name, m.name, self.name))
                 info.messages_byname[m.name] = m
+                if m.value in info.messages_byvalue:
+                    raise Exception("Duplicated message value %d between %s and %s in channel %s" % (
+                        m.value, info.messages_byvalue[m.value].name, m.name, self.name))
+                info.messages_byvalue[m.value] = m
 
         self.server_messages = server_info.messages
         self.server_messages_byname = server_info.messages_byname
-- 
2.17.0



More information about the Spice-devel mailing list