From 8ab47ba8a4099f84456ceb83052a1af7ee595de3 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 10 Oct 2025 11:43:39 -0700 Subject: [PATCH] More python3 modified: scripts/brandelf.py modified: scripts/gpp_inc.py modified: src/arch/i086/cleanasm.py --- src/stub/scripts/brandelf.py | 14 +++++++------- src/stub/scripts/gpp_inc.py | 14 +++++++------- src/stub/src/arch/i086/cleanasm.py | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/stub/scripts/brandelf.py b/src/stub/scripts/brandelf.py index 7b2169d1..78000892 100644 --- a/src/stub/scripts/brandelf.py +++ b/src/stub/scripts/brandelf.py @@ -54,32 +54,32 @@ def do_file(fn): def write(s): if not opts.dry_run: - fp.write(s) + fp.write(s.encode()) def brand_arm(s): - if e_ident[4:7] != s: + if e_ident[4:7] != s.encode(): raise Exception("%s is not %s" % (fn, opts.bfdname)) write("\x61") # ELFOSABI_ARM def brand_freebsd(s): - if e_ident[4:7] != s: + if e_ident[4:7] != s.encode(): raise Exception("%s is not %s" % (fn, opts.bfdname)) write("\x09") def brand_linux(s): - if e_ident[4:7] != s: + if e_ident[4:7] != s.encode(): raise Exception("%s is not %s" % (fn, opts.bfdname)) ##write("\x00Linux\x00\x00\x00") write("\x00" * 9) def brand_netbsd(s): - if e_ident[4:7] != s: + if e_ident[4:7] != s.encode(): raise Exception("%s is not %s" % (fn, opts.bfdname)) write("\x02") def brand_openbsd(s): - if e_ident[4:7] != s: + if e_ident[4:7] != s.encode(): raise Exception("%s is not %s" % (fn, opts.bfdname)) write("\x0c") if opts.bfdname[:3] == "elf": - if e_ident[:4] != "\x7f\x45\x4c\x46": + if e_ident[:4] != "\x7f\x45\x4c\x46".encode(): raise Exception("%s is not %s" % (fn, "ELF")) fp.seek(7, 0) if opts.bfdname == "elf32-bigarm" and opts.elfosabi == "arm": diff --git a/src/stub/scripts/gpp_inc.py b/src/stub/scripts/gpp_inc.py index 815ae178..514b00d2 100644 --- a/src/stub/scripts/gpp_inc.py +++ b/src/stub/scripts/gpp_inc.py @@ -83,7 +83,7 @@ def parse_comment(state, l, comment): def handle_inc_c(state, l, ofp): - m = re.search(r"^\s*\#\s*include\s+([\"\<])(.+?)([\"\>])(.*)$", l) + m = re.search(r"^\s*\#\s*include\s+([\"\<])(.+?)([\"\>])(.*)$", l.decode()) if not m: return l q1, inc, q2, comment = m.groups() @@ -93,7 +93,7 @@ def handle_inc_c(state, l, ofp): elif q1 == '"' and q2 == '"': dirs = [state[1]] + opts.includes else: - raise Exception("syntax error: include line " + l) + raise Exception("syntax error: include line " + l.decode()) for dir in dirs: fn = os.path.join(dir, inc) if os.path.isfile(fn): @@ -130,13 +130,13 @@ def handle_file(ifn, ofp, parent_state=None): ifp = open(ifn, "rb") for l in ifp.readlines(): state[2] += 1 # line counter - l = l.rstrip("\n") + l = l.rstrip("\n".encode()) if opts.mode == "c": l = handle_inc_c(state, l, ofp) elif opts.mode == "nasm": l = handle_inc_nasm(state, l, ofp) if l is not None: - ofp.write(l + "\n") + ofp.write(l + "\n".encode()) def main(argv): @@ -179,12 +179,12 @@ def main(argv): os.unlink(fn) if files_mmd: fp = open(fn, "wb") - fp.write("%s : \\\n" % opts.target_mmd) + fp.write(("%s : \\\n" % opts.target_mmd).encode()) for i, f in enumerate(files_mmd): if i < len(files_mmd) - 1: - fp.write(" %s \\\n" % f) + fp.write((" %s \\\n" % f).encode()) else: - fp.write(" %s\n" % f) + fp.write((" %s\n" % f).encode()) fp.close() diff --git a/src/stub/src/arch/i086/cleanasm.py b/src/stub/src/arch/i086/cleanasm.py index 1061ef7c..f5a830c9 100644 --- a/src/stub/src/arch/i086/cleanasm.py +++ b/src/stub/src/arch/i086/cleanasm.py @@ -99,11 +99,11 @@ def main(argv): k, v = m.group(1).strip(), [0, 0, None, 0] assert k and v, (inst, args) v[2] = k # new name - if labels.has_key(k): + if k in labels: assert labels[k][:2] == v[:2] return k, v def add_label(k, v): - if labels.has_key(k): + if k in labels: assert labels[k][:2] == v[:2] else: labels[k] = v @@ -449,7 +449,7 @@ def main(argv): ofp = open(ofile, "wb") current_label = None for label, inst, args, args_label in olines: - if labels.has_key(label): + if label in labels: current_label = labels[label][2] if opts.verbose: ofp.write("%s: /* %d */\n" % (labels[label][2], labels[label][3]))