From 3b68db126a9ddbf61d4c8c8f28e69942ca2487db Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Fri, 13 Nov 2026 00:20:35 +0100 Subject: gen_class: Fix class reference resolution There is no dependency order in the constant table, a class reference may reference a name with a higher index for example. --- tools/gen_class.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/gen_class.py b/tools/gen_class.py index ba0a92f..866576c 100755 --- a/tools/gen_class.py +++ b/tools/gen_class.py @@ -93,7 +93,7 @@ def parse_class(data): cp_count, = struct.unpack_from(">H", data, o) o += 2 utf8 = {} # cp idx -> utf8 string - cls_names = {} # cp idx -> internal name (for Class constants) + cls_ref = {} # cp idx -> utf8 idx (Class constants) i = 1 while i < cp_count: tag = data[o] @@ -111,7 +111,7 @@ def parse_class(data): elif tag == 7: # Class idx, = struct.unpack_from(">H", data, o) o += 2 - cls_names[i] = utf8.get(idx, "") + cls_ref[i] = idx # resolve name after full pass elif tag in (8, 16, 19, 20): # String/MethodType/Module/Package o += 2 elif tag == 12: # NameAndType (2 indexes = 4 bytes) @@ -127,6 +127,10 @@ def parse_class(data): i += 1 access, this, sup = struct.unpack_from(">HHH", data, o) o += 6 + # A Class constant's name may sit at a HIGHER pool index than the + # constant itself (the pool is not dependency-ordered), so resolve the + # names only after the whole pool has been read. + cls_names = {ix: utf8.get(r, "") for ix, r in cls_ref.items()} # Every class named anywhere in the file (this/super/interfaces and # every method/field/annotation target) is a Class constant, so the # set of tag-7 names is the complete reference set for the closure. -- cgit v1.3.1