misc: Text vs Byte string in python3
Python 3 uses the concepts of two different types: text and binary strings. Those cannot be implicilty combined (as it was happening in python2) and in order to be used together one of them must be converted to the other type: * Text can be encoded into Bytes via the encode() method * Bytes can be decoded to Text using the decode() method By default encode/decode will assume UTF-8 format JIRA: https://gem5.atlassian.net/browse/GEM5-345 Change-Id: I1bdf7db17b49cc109239fd5f44791769370853f8 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26250 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
@@ -1013,7 +1013,7 @@ export_vars += ['USE_FENV', 'TARGET_ISA', 'TARGET_GPU_ISA', 'CP_ANNOTATE',
|
||||
# operands are the name of the variable and a Value node containing the
|
||||
# value of the variable.
|
||||
def build_config_file(target, source, env):
|
||||
(variable, value) = [s.get_contents() for s in source]
|
||||
(variable, value) = [s.get_contents().decode('utf-8') for s in source]
|
||||
with open(str(target[0]), 'w') as f:
|
||||
print('#define', variable, value, file=f)
|
||||
return None
|
||||
|
||||
@@ -621,7 +621,7 @@ for opt in export_vars:
|
||||
env.ConfigFile(opt)
|
||||
|
||||
def makeTheISA(source, target, env):
|
||||
isas = [ src.get_contents() for src in source ]
|
||||
isas = [ src.get_contents().decode('utf-8') for src in source ]
|
||||
target_isa = env['TARGET_ISA']
|
||||
def define(isa):
|
||||
return isa.upper() + '_ISA'
|
||||
@@ -823,7 +823,7 @@ depends.sort(key = lambda x: x.name)
|
||||
# Generate Python file containing a dict specifying the current
|
||||
# buildEnv flags.
|
||||
def makeDefinesPyFile(target, source, env):
|
||||
build_env = source[0].get_contents()
|
||||
build_env = source[0].get_contents().decode('utf-8')
|
||||
|
||||
code = code_formatter()
|
||||
code("""
|
||||
@@ -882,7 +882,7 @@ def createSimObjectCxxConfig(is_header):
|
||||
def body(target, source, env):
|
||||
assert len(target) == 1 and len(source) == 1
|
||||
|
||||
name = str(source[0].get_contents())
|
||||
name = source[0].get_contents().decode('utf-8')
|
||||
obj = sim_objects[name]
|
||||
|
||||
code = code_formatter()
|
||||
|
||||
@@ -43,6 +43,8 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from six import string_types
|
||||
|
||||
from . import convert
|
||||
from . import jobfile
|
||||
|
||||
@@ -122,7 +124,7 @@ def compareVersions(v1, v2):
|
||||
def make_version_list(v):
|
||||
if isinstance(v, (list,tuple)):
|
||||
return v
|
||||
elif isinstance(v, str):
|
||||
elif isinstance(v, string_types):
|
||||
return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
|
||||
else:
|
||||
raise TypeError()
|
||||
@@ -196,7 +198,7 @@ def readCommand(cmd, **kwargs):
|
||||
return exception
|
||||
raise
|
||||
|
||||
return subp.communicate()[0]
|
||||
return subp.communicate()[0].decode('utf-8')
|
||||
|
||||
def makeDir(path):
|
||||
"""Make a directory if it doesn't exist. If the path does exist,
|
||||
|
||||
Reference in New Issue
Block a user