summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_algebraic.py
diff options
context:
space:
mode:
authorMathieu Bridon <[email protected]>2018-08-09 10:27:21 +0200
committerDylan Baker <[email protected]>2018-08-09 16:49:19 -0700
commit14f1ab998fcdcd8fec43c3da8ef03af4af2d3966 (patch)
treeb4352953eaabf0f58cec1a1f3b5474a1735e9211 /src/compiler/nir/nir_algebraic.py
parentc644b2d7a7602e929b92dd2c52ed2765928e02b1 (diff)
python: Do not mix bytes and unicode strings
Mixing the two is a long-standing recipe for errors in Python 2, so much so that Python 3 now completely separates them. This commit stops treating both as if they were the same, and in the process makes the script compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_algebraic.py')
-rw-r--r--src/compiler/nir/nir_algebraic.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index a84c41a78f9..5baeea88afe 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -35,6 +35,12 @@ import traceback
from nir_opcodes import opcodes
+if sys.version_info < (3, 0):
+ string_type = unicode
+
+else:
+ string_type = str
+
_type_re = re.compile(r"(?P<type>int|uint|bool|float)?(?P<bits>\d+)?")
def type_bits(type_str):
@@ -66,11 +72,14 @@ class VarSet(object):
class Value(object):
@staticmethod
def create(val, name_base, varset):
+ if isinstance(val, bytes):
+ val = val.decode('utf-8')
+
if isinstance(val, tuple):
return Expression(val, name_base, varset)
elif isinstance(val, Expression):
return val
- elif isinstance(val, (str, unicode)):
+ elif isinstance(val, string_type):
return Variable(val, name_base, varset)
elif isinstance(val, (bool, int, long, float)):
return Constant(val, name_base)