summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-01-24 23:32:43 +0200
committerMarc-André Lureau <marcandre.lureau@gmail.com>2012-03-20 15:25:50 +0100
commit3a6de6d6fb0362df9e78fa64942a45c02bdabe53 (patch)
treec6ac424a3eec4a7c240e78d1958091877482a23d
parentd6f198b3f433100a7a212be03b059876ed33e598 (diff)
downloadspice-protocol-3a6de6d6fb0362df9e78fa64942a45c02bdabe53.tar.gz
spice-protocol-3a6de6d6fb0362df9e78fa64942a45c02bdabe53.tar.xz
spice-protocol-3a6de6d6fb0362df9e78fa64942a45c02bdabe53.zip
demarshaller/marshaller fix gcc 4.6.0
python_modules/demarshal.py and marshal.py fixes for gcc 4.6.0 warning about set but unused variables. The fixes disable creating of variables mem_size when they are not used (demarshall) and declaring a src variable when the message doesn't use it (marshal). You need to touch *.proto after applying this (should add a Makefile dependency).
-rw-r--r--python_modules/demarshal.py22
-rw-r--r--python_modules/marshal.py8
2 files changed, 21 insertions, 9 deletions
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 48551c0..9d3b1e4 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -251,14 +251,18 @@ def write_validate_pointer_item(writer, container, item, scope, parent_scope, st
array_item = ItemInfo(target_type, "%s__array" % item.prefix, start)
scope.variable_def("uint32_t", array_item.nw_size())
- scope.variable_def("uint32_t", array_item.mem_size())
+ # don't create a variable that isn't used, fixes -Werror=unused-but-set-variable
+ need_mem_size = want_mem_size or (
+ want_extra_size and not item.member.has_attr("chunk")
+ and not target_type.is_cstring_length())
+ if need_mem_size:
+ scope.variable_def("uint32_t", array_item.mem_size())
if target_type.is_cstring_length():
writer.assign(array_item.nw_size(), "spice_strnlen((char *)message_start + %s, message_end - (message_start + %s))" % (v, v))
writer.error_check("*(message_start + %s + %s) != 0" % (v, array_item.nw_size()))
- writer.assign(array_item.mem_size(), array_item.nw_size())
else:
write_validate_array_item(writer, container, array_item, scope, parent_scope, start,
- True, True, False)
+ True, want_mem_size=need_mem_size, want_extra_size=False)
writer.error_check("message_start + %s + %s > message_end" % (v, array_item.nw_size()))
if want_extra_size:
@@ -524,7 +528,7 @@ def write_validate_member(writer, container, member, parent_scope, start,
def write_validate_container(writer, prefix, container, start, parent_scope, want_nw_size, want_mem_size, want_extra_size):
for m in container.members:
sub_want_nw_size = want_nw_size and not m.is_fixed_nw_size()
- sub_want_mem_size = m.is_extra_size()
+ sub_want_mem_size = m.is_extra_size() and want_mem_size
sub_want_extra_size = not m.is_extra_size() and m.contains_extra_size()
defs = ["size_t"]
@@ -1007,6 +1011,9 @@ def write_msg_parser(writer, message):
msg_type = message.c_type()
msg_sizeof = message.sizeof()
+ want_mem_size = (len(message.members) != 1 or message.members[0].is_fixed_nw_size()
+ or not message.members[0].is_array())
+
writer.newline()
parent_scope = writer.function(function_name,
"uint8_t *",
@@ -1014,7 +1021,9 @@ def write_msg_parser(writer, message):
parent_scope.variable_def("SPICE_GNUC_UNUSED uint8_t *", "pos");
parent_scope.variable_def("uint8_t *", "start = message_start");
parent_scope.variable_def("uint8_t *", "data = NULL");
- parent_scope.variable_def("size_t", "mem_size", "nw_size");
+ parent_scope.variable_def("size_t", "nw_size")
+ if want_mem_size:
+ parent_scope.variable_def("size_t", "mem_size")
if not message.has_attr("nocopy"):
parent_scope.variable_def("uint8_t *", "in", "end");
num_pointers = message.get_num_pointers()
@@ -1026,7 +1035,8 @@ def write_msg_parser(writer, message):
write_parser_helpers(writer)
- write_validate_container(writer, None, message, "start", parent_scope, True, True, False)
+ write_validate_container(writer, None, message, "start", parent_scope, True,
+ want_mem_size=want_mem_size, want_extra_size=False)
writer.newline()
diff --git a/python_modules/marshal.py b/python_modules/marshal.py
index a82df98..5b4dfdd 100644
--- a/python_modules/marshal.py
+++ b/python_modules/marshal.py
@@ -356,10 +356,12 @@ def write_message_marshaller(writer, message, is_server, private):
for n in names:
writer.assign("*%s_out" % n, "NULL")
- src = RootMarshallingSource(None, message.c_type(), message.sizeof(), "msg")
- src.reuse_scope = scope
+ # fix warnings about unused variables by not creating body if no members to parse
+ if any(x.is_fixed_nw_size() for x in message.members):
+ src = RootMarshallingSource(None, message.c_type(), message.sizeof(), "msg")
+ src.reuse_scope = scope
- write_container_marshaller(writer, message, src)
+ write_container_marshaller(writer, message, src)
writer.end_block()
writer.newline()