Re: [PATCH] Make spice_codegen.py work on both Python 2 and 3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

On Thu, Mar 26, 2015 at 10:56:53AM -0500, Alexander Wauck wrote:
> This *should* be enough to make spice_codegen.py work on both Python 2
> and Python 3.  I have not tested with Python 2.5 or 2.6, though, nor
> have I done particularly thorough testing in general.  I would
> appreciate getting some more knowledgeable eyes on this.

From a quick glance, the changes look sane to me (split patch would have
been even more straightforward to review ;)

> 
> (Sorry for the long diff, but I had to use six.py for the
>  2/3 compatibility.  Should that be something the user is
>  required to install instead of us bundling it?)

First time I hear about six.py, so I don't know about that :(
One comment below:

> diff --git a/python_modules/codegen.py b/python_modules/codegen.py
> index 009cf95..4ff4c55 100644
> --- a/python_modules/codegen.py
> +++ b/python_modules/codegen.py
> @@ -119,21 +120,24 @@ class CodeWriter:
>          return writer
>  
>      def write(self, s):
> -        # Ensure its a string
> -        s = str(s)
> +        # Ensure its a unicode string
> +        if six.PY2:
> +            s = unicode(s)
> +        else:
> +            s = str(s)

Why do we need a unicode string here?

I also had to use this patch or the file generation would first error
out, and then would contain some *ptr += 1.0; rather than *ptr += 1;
With these changes, the files are the same when generated with python2
or python3 on my system (python3-3.4.2-4.fc22.x86_64)

diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index f6047b0..8afd9f5 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -68,7 +68,7 @@ def write_parser_helpers(writer):
             scope = writer.function("SPICE_GNUC_UNUSED consume_%s" % type, ctype, "uint8_t **ptr", True)
             scope.variable_def(ctype, "val")
             writer.assign("val", "read_%s(*ptr)" % type)
-            writer.increment("*ptr", size / 8)
+            writer.increment("*ptr", int(size / 8))
             writer.statement("return val")
             writer.end_block()
 
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 7ddc72a..1608485 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -168,7 +168,7 @@ class IntegerType(Type):
         return self.name + "_t"
 
     def get_fixed_nw_size(self):
-        return self.bits / 8
+        return int(self.bits / 8)
 
     def is_primitive(self):
         return True
@@ -245,7 +245,7 @@ class EnumBaseType(Type):
         return True
 
     def get_fixed_nw_size(self):
-        return self.bits / 8
+        return int(self.bits / 8)
 
     # generates a value-name table suitable for use with the wireshark protocol
     # dissector

Christophe

Attachment: pgpjLHgC0o9JP.pgp
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]