[Mesa-dev] [PATCH 25/26] python: Explicitly add the 'L' suffix on Python 3

Dylan Baker dylan at pnwbakers.com
Thu Jul 5 16:41:37 UTC 2018


Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

Quoting Mathieu Bridon (2018-07-05 06:17:56)
> Python 2 had two integer types: int and long. Python 3 dropped the
> latter, as it made the int type automatically support bigger numbers.
> 
> As a result, Python 3 lost the 'L' suffix on integer litterals.
> 
> This probably doesn't make much difference when compiling the generated
> C code, but adding it explicitly means that both Python 2 and 3 generate
> the exact same C code anyway, which makes it easier to compare and check
> for discrepencies when moving to Python 3.
> 
> Signed-off-by: Mathieu Bridon <bochecha at daitauha.fr>
> ---
>  src/compiler/nir/nir_algebraic.py | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
> index d53a9869de..2081c29034 100644
> --- a/src/compiler/nir/nir_algebraic.py
> +++ b/src/compiler/nir/nir_algebraic.py
> @@ -148,7 +148,16 @@ class Constant(Value):
>        if isinstance(self.value, integer_types):
>           return hex(self.value)
>        elif isinstance(self.value, float):
> -         return hex(struct.unpack('Q', struct.pack('d', self.value))[0])
> +         i = struct.unpack('Q', struct.pack('d', self.value))[0]
> +         h = hex(i)
> +
> +         # On Python 2 this 'L' suffix is automatically added, but not on Python 3
> +         # Adding it explicitly makes the generated file identical, regardless
> +         # of the Python version running this script.
> +         if h[-1] != 'L' and i > sys.maxsize:
> +            h += 'L'
> +
> +         return h
>        else:
>           assert False
>  
> -- 
> 2.17.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180705/e9adc992/attachment.sig>


More information about the mesa-dev mailing list