From e1c6a92368d632af1e9dbf2ea64328273d50f928 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Mon, 9 Feb 2026 21:07:16 -0500 Subject: [PATCH] Fix Python 3 integer division in zmachine modules Python 2 `/` did integer division, Python 3 returns float. Changed to `//` in zobjectparser (attribute byte offset) and zmemory (address bounds checks). Zork 1 hit this on the first test_attr opcode. --- src/mudlib/zmachine/zmemory.py | 6 +++--- src/mudlib/zmachine/zobjectparser.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mudlib/zmachine/zmemory.py b/src/mudlib/zmachine/zmemory.py index 87c5d30..ade9adf 100644 --- a/src/mudlib/zmachine/zmemory.py +++ b/src/mudlib/zmachine/zmemory.py @@ -235,18 +235,18 @@ class ZMemory: def word_address(self, address): """Return the 'actual' address of word address ADDRESS.""" - if address < 0 or address > (self._total_size / 2): + if address < 0 or address > (self._total_size // 2): raise ZMemoryOutOfBounds return address * 2 def packed_address(self, address): """Return the 'actual' address of packed address ADDRESS.""" if 1 <= self.version <= 3: - if address < 0 or address > (self._total_size / 2): + if address < 0 or address > (self._total_size // 2): raise ZMemoryOutOfBounds return address * 2 elif 4 <= self.version <= 5: - if address < 0 or address > (self._total_size / 4): + if address < 0 or address > (self._total_size // 4): raise ZMemoryOutOfBounds return address * 4 else: diff --git a/src/mudlib/zmachine/zobjectparser.py b/src/mudlib/zmachine/zobjectparser.py index dfcecf2..c65f276 100644 --- a/src/mudlib/zmachine/zobjectparser.py +++ b/src/mudlib/zmachine/zobjectparser.py @@ -169,12 +169,12 @@ class ZObjectParser: if 1 <= self._memory.version <= 3: if not (0 <= attrnum <= 31): raise ZObjectIllegalAttributeNumber - bf = BitField(self._memory[object_addr + (attrnum / 8)]) + bf = BitField(self._memory[object_addr + (attrnum // 8)]) elif 4 <= self._memory.version <= 5: if not (0 <= attrnum <= 47): raise ZObjectIllegalAttributeNumber - bf = BitField(self._memory[object_addr + (attrnum / 8)]) + bf = BitField(self._memory[object_addr + (attrnum // 8)]) else: raise ZObjectIllegalVersion