Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More python 2/3 issues #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions runtime/ccsp/utils/make-header.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import sys, os, re
import sys, os, re, functools

prog_name = "make-header.py"

Expand Down Expand Up @@ -83,13 +83,12 @@ def die(*s):
warn(*s)
sys.exit(1)

def safe_sorted(list, cmp):
def safe_sorted(lst, comp):
try:
return sorted(list, cmp)
return sorted(lst, key=functools.cmp_to_key(comp))
except NameError:
list = list[:]
list.sort(cmp)
return list
lst = list(lst)
return sorted(lst, key=functools.cmp_to_key(comp))

def load_defines(defines, fn):
define_re = re.compile(r'^#define\s+(\S+)')
Expand Down Expand Up @@ -148,12 +147,12 @@ def test_symbol_requirements(defines, calls, symbols):
for name, symbol in symbols.items():
unsupported = False

if symbol.has_key("DEPEND"):
if "DEPENDS" in symbol:
for define in symbol["DEPEND"]:
unsupported = unsupported or (not defines.has_key(define))
if symbol.has_key("INCOMPATIBLE"):
unsupported = unsupported or (not define in defines)
if "INCOMPATIBLE" in symbol:
for define in symbol["INCOMPATIBLE"]:
unsupported = unsupported or defines.has_key(define)
unsupported = unsupported or (define in defines)
if unsupported:
for call in symbol["handles"]:
calls[call] = symbols["Y_unsupported"]
Expand All @@ -164,9 +163,9 @@ def compare_symbols(a, b):
prio_a = int(symbols[a].get("PRIO", 0))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do with some help converting this one into a keys= statement.

prio_b = int(symbols[b].get("PRIO", 0))
if prio_a == prio_b:
return cmp(a, b)
return (a > b) - (a < b)
else:
return cmp(prio_b, prio_a)
return (prio_b > prio_a) - (prio_b < prio_a)

i = 0
for symbol in safe_sorted(symbols.keys(), compare_symbols):
Expand Down Expand Up @@ -527,18 +526,18 @@ def gen_sparc_cif_stub(f, symbol, inputs, outputs):
f.line("/* sparc unsupported */")

def output_cif(defines, symbol_list, symbols, fn):
if defines.has_key("TARGET_CPU_386"):
if "TARGET_CPU_386" in defines:
arch_header = gen_i386_header
arch_generator = gen_i386_cif_stub
elif defines.has_key("TARGET_CPU_MIPS"):
elif "TARGET_CPU_MIPS" in defines:
warn("generating CIF stubs for unsupported architecture...")
arch_header = gen_mips_header
arch_generator = gen_mips_cif_stub
elif defines.has_key("TARGET_CPU_PPC64"):
elif "TARGET_CPU_PPC64" in defines:
warn("generating CIF stubs for unsupported architecture...")
arch_header = gen_ppc_header
arch_generator = gen_ppc64_cif_stub
elif defines.has_key("TARGET_CPU_SPARC"):
elif "TARGET_CPU_SPARC" in defines:
warn("generating CIF stubs for unsupported architecture...")
arch_header = gen_sparc_header
arch_generator = gen_sparc_cif_stub
Expand Down Expand Up @@ -577,8 +576,8 @@ def main(args):
enumerate_symbols(symbols)

symbol_list = safe_sorted(
symbols.keys(),
lambda a, b: cmp(symbols[a]["offset"], symbols[b]["offset"])
symbols.keys(),
lambda a, b: (symbols[a]["offset"] > symbols[b]["offset"]) - (symbols[a]["offset"] < symbols[b]["offset"])
)

if type == "--kitable":
Expand Down
4 changes: 2 additions & 2 deletions tools/kroc/occbuild.in
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def run_command(cmd):

def safe_sorted(l):
"""Like sorted(), but returns a mutable list."""
l = l[:]
l = list(l)
l.sort()
return l

Expand Down Expand Up @@ -488,7 +488,7 @@ class KRoCToolchain(Toolchain):
need_mods.append("forall")

# Look for all the other modules we need.
full_path = search_path + capture(programs["kroc"] + ["--incpath"]).strip().split(":")
full_path = search_path + capture(programs["kroc"] + ["--incpath"]).strip().split(b":")
lib_opts = []
for need in need_mods:
fn = find_in_path("%s.module" % need, full_path)
Expand Down