Skip to content

Commit 2268862

Browse files
committed
fix: save last result in PARSED_STRUCTS
1 parent 304044a commit 2268862

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

libdestruct/c/struct_parser.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from libdestruct.common.obj import obj
2323

2424

25-
PARSED_STRUCT = {}
25+
PARSED_STRUCTS = {}
2626
"""A cache for parsed struct definitions, indexed by name."""
2727

2828
TYPEDEFS = {}
@@ -53,12 +53,16 @@ def definition_to_type(definition: str) -> type[obj]:
5353
struct_node = decl.type
5454

5555
if struct_node.name:
56-
PARSED_STRUCT[struct_node.name] = struct_to_type(struct_node)
56+
PARSED_STRUCTS[struct_node.name] = struct_to_type(struct_node)
5757
elif isinstance(decl, c_ast.Typedef):
5858
name, definition = typedef_to_pair(decl)
5959
TYPEDEFS[name] = definition
6060

61-
return struct_to_type(root)
61+
result = struct_to_type(root)
62+
63+
PARSED_STRUCTS[root.name] = result
64+
65+
return result
6266

6367

6468
def struct_to_type(struct_node: c_ast.Struct) -> type[struct]:
@@ -68,9 +72,9 @@ def struct_to_type(struct_node: c_ast.Struct) -> type[struct]:
6872

6973
fields = {}
7074

71-
if not struct_node.decls and struct_node.name in PARSED_STRUCT:
75+
if not struct_node.decls and struct_node.name in PARSED_STRUCTS:
7276
# We can check if the struct is already parsed.
73-
return PARSED_STRUCT[struct_node.name]
77+
return PARSED_STRUCTS[struct_node.name]
7478
elif not struct_node.decls:
7579
raise ValueError("Struct must have fields.")
7680

0 commit comments

Comments
 (0)