diff options
author | Mathieu Bridon <[email protected]> | 2018-08-09 10:27:22 +0200 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2018-08-09 16:49:19 -0700 |
commit | 1e668ca111563b122b16be5506638983b31205b5 (patch) | |
tree | 0654f232c600cae9278cdf77437c7fceed94559e /src | |
parent | 14f1ab998fcdcd8fec43c3da8ef03af4af2d3966 (diff) |
python: Better check for integer types
Python 3 lost the long type: now everything is an int, with the right
size.
This commit makes the script compatible with Python 2 (where we check
for both int and long) and Python 3 (where we only check for int).
Signed-off-by: Mathieu Bridon <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/nir/nir_algebraic.py | 8 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_pack.py | 13 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 5baeea88afe..3055937029c 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -36,9 +36,11 @@ import traceback from nir_opcodes import opcodes if sys.version_info < (3, 0): + integer_types = (int, long) string_type = unicode else: + integer_types = (int, ) string_type = str _type_re = re.compile(r"(?P<type>int|uint|bool|float)?(?P<bits>\d+)?") @@ -81,7 +83,7 @@ class Value(object): return val elif isinstance(val, string_type): return Variable(val, name_base, varset) - elif isinstance(val, (bool, int, long, float)): + elif isinstance(val, (bool, float) + integer_types): return Constant(val, name_base) __template = mako.template.Template(""" @@ -145,7 +147,7 @@ class Constant(Value): def hex(self): if isinstance(self.value, (bool)): return 'NIR_TRUE' if self.value else 'NIR_FALSE' - if isinstance(self.value, (int, long)): + if isinstance(self.value, integer_types): return hex(self.value) elif isinstance(self.value, float): i = struct.unpack('Q', struct.pack('d', self.value))[0] @@ -164,7 +166,7 @@ class Constant(Value): def type(self): if isinstance(self.value, (bool)): return "nir_type_bool32" - elif isinstance(self.value, (int, long)): + elif isinstance(self.value, integer_types): return "nir_type_int" elif isinstance(self.value, float): return "nir_type_float" diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index ad2e49281fb..c1307d30c2f 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -38,9 +38,18 @@ from __future__ import division, print_function +import sys + from u_format_parse import * +if sys.version_info < (3, 0): + integer_types = (int, long) + +else: + integer_types = (int, ) + + def inv_swizzles(swizzles): '''Return an array[4] of inverse swizzle terms''' '''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha''' @@ -212,7 +221,7 @@ def truncate_mantissa(x, bits): '''Truncate an integer so it can be represented exactly with a floating point mantissa''' - assert isinstance(x, (int, long)) + assert isinstance(x, integer_types) s = 1 if x < 0: @@ -236,7 +245,7 @@ def value_to_native(type, value): '''Get the value of unity for this type.''' if type.type == FLOAT: if type.size <= 32 \ - and isinstance(value, (int, long)): + and isinstance(value, integer_types): return truncate_mantissa(value, 23) return value if type.type == FIXED: |