Skip to content

Commit

Permalink
fhdl.visit: fix nondeterminism in visit_Case.
Browse files Browse the repository at this point in the history
str(value) serializes to e.g. <Constant object at 0x7f3f94f346d8>,
which is randomized due to ASLR even with e.g. PYTHONHASHSEED set.
  • Loading branch information
whitequark committed Oct 9, 2018
1 parent 1e114c7 commit 076ec0d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions migen/fhdl/visit.py
Expand Up @@ -83,7 +83,7 @@ def visit_If(self, node):
def visit_Case(self, node):
self.visit(node.test)
for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0])):
key=lambda x: -1 if x[0] is "default" else x[0].duid):
self.visit(statements)

def visit_Fragment(self, node):
Expand Down Expand Up @@ -188,7 +188,7 @@ def visit_If(self, node):
def visit_Case(self, node):
cases = {v: self.visit(statements)
for v, statements in sorted(node.cases.items(),
key=lambda x: str(x[0]))}
key=lambda x: -1 if x[0] is "default" else x[0].duid)}
r = Case(self.visit(node.test), cases)
return r

Expand Down

0 comments on commit 076ec0d

Please sign in to comment.