From 762e25addedf720f094c5fb8961116605940209e Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Wed, 12 Jan 2022 16:25:01 +0100 Subject: [PATCH] More Python 3 corrections. * Change: In unicorn/python/unicornInit.py, when iterating over all the loaded modules, now we have "namespace" that have a __file__ attribute which is set to None. Skip them. * Change: In stratus1/st_net.py, "is" must be replaced by "==" when doing string comparison. * Change: In stratus1/st_parser.py, open file in "rb" mode instead of "r" (so we get a bytestream as now required by Python). --- stratus1/src/stratus/st_net.py | 10 +++++----- stratus1/src/stratus/st_parser.py | 2 +- unicorn/python/unicornInit.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stratus1/src/stratus/st_net.py b/stratus1/src/stratus/st_net.py index 83464674..4cfb24cb 100644 --- a/stratus1/src/stratus/st_net.py +++ b/stratus1/src/stratus/st_net.py @@ -457,13 +457,13 @@ class net : cell._TAB_NETS_OUT += [Signal ( "sh_o%d" % num_net, inputNet._arity )] # Initialisation of shiftType - if direction is "left" : - if type is "logical" : shiftType = 0x12 - elif type is "arith" : shiftType = 0xa + if direction == "left" : + if type == "logical" : shiftType = 0x12 + elif type == "arith" : shiftType = 0xa else : shiftType = 0x6 else : - if type is "logical" : shiftType = 0x11 - elif type is "arith" : shiftType = 0x9 + if type == "logical" : shiftType = 0x11 + elif type == "arith" : shiftType = 0x9 else : shiftType = 0x5 inst_name = self._st_cell._shift.lower() diff --git a/stratus1/src/stratus/st_parser.py b/stratus1/src/stratus/st_parser.py index 3360fc0e..3ff0adf0 100644 --- a/stratus1/src/stratus/st_parser.py +++ b/stratus1/src/stratus/st_parser.py @@ -115,7 +115,7 @@ class Parser : # Parsing a file ################ def Parse ( self, nameFile ) : - self._p.ParseFile ( open ( nameFile, "r" ) ) + self._p.ParseFile ( open ( nameFile, "rb" ) ) ################## class InitParser : diff --git a/unicorn/python/unicornInit.py b/unicorn/python/unicornInit.py index f11beded..fc1616fc 100644 --- a/unicorn/python/unicornInit.py +++ b/unicorn/python/unicornInit.py @@ -73,6 +73,7 @@ def unicornConfigure ( **kw ): if not 'unicornHook' in module.__dict__: if module.__name__.endswith( '.__pycache__' ): continue if not '__file__' in module.__dict__: continue + if module.__file__ is None: continue elements = module.__file__.split( os.sep ) if elements[-1] == 'plugins': print( WarningMessage( 'Plugin "{}" do not provides the unicornHook() method, skipped.' \