[Spice-devel] [PATCH] change marshalling macros to consider alignment of types
Frediano Ziglio
fziglio at redhat.com
Fri Dec 11 05:36:41 PST 2015
---
python_modules/demarshal.py | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 209eafc..743b0d8 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -40,20 +40,34 @@ def write_parser_helpers(writer):
writer = writer.function_helper()
+ for sign in ["", "u"]:
+ type = "%sint8" % sign
+ writer.macro("read_%s" % type, "ptr", "(*((%s_t *)(ptr)))" % type)
+ writer.macro("write_%s" % type, "ptr, val", "(*((%s_t *)(ptr))) = val" % type)
writer.writeln("#ifdef WORDS_BIGENDIAN")
- for size in [8, 16, 32, 64]:
+ for size in [16, 32, 64]:
for sign in ["", "u"]:
utype = "uint%d" % (size)
type = "%sint%d" % (sign, size)
swap = "SPICE_BYTESWAP%d" % size
- if size == 8:
- writer.macro("read_%s" % type, "ptr", "(*((%s_t *)(ptr)))" % type)
- writer.macro("write_%s" % type, "ptr, val", "*(%s_t *)(ptr) = val" % (type))
- else:
- writer.macro("read_%s" % type, "ptr", "((%s_t)%s(*((%s_t *)(ptr))))" % (type, swap, utype))
- writer.macro("write_%s" % type, "ptr, val", "*(%s_t *)(ptr) = %s((%s_t)val)" % (utype, swap, utype))
+ writer.macro("read_%s" % type, "ptr", "((%s_t)%s(*((%s_t *)(ptr))))" % (type, swap, utype))
+ writer.macro("write_%s" % type, "ptr, val", "*(%s_t *)(ptr) = %s((%s_t)val)" % (utype, swap, utype))
+ writer.writeln("#elif __GNUC__ > 3")
+ struct = "pkg_struct"
+ writer.begin_block("typedef union __attribute__ ((__packed__))")
+ for size in [16, 32, 64]:
+ for sign in ["", "u"]:
+ type = "%sint%d" % (sign, size)
+ writer.variable_def("%s_t" % type, type)
+ writer.unindent()
+ writer.writeln("} %s;" % struct)
+ for size in [16, 32, 64]:
+ for sign in ["", "u"]:
+ type = "%sint%d" % (sign, size)
+ writer.macro("read_%s" % type, "ptr", "(((%s *)(ptr))->%s)" % (struct, type))
+ writer.macro("write_%s" % type, "ptr, val", "((%s *)(ptr))->%s = val" % (struct, type))
writer.writeln("#else")
- for size in [8, 16, 32, 64]:
+ for size in [16, 32, 64]:
for sign in ["", "u"]:
type = "%sint%d" % (sign, size)
writer.macro("read_%s" % type, "ptr", "(*((%s_t *)(ptr)))" % type)
--
2.4.3
More information about the Spice-devel
mailing list