diff --git a/pythonbpf/structs/struct_type.py b/pythonbpf/structs/struct_type.py index 129066f..5e1698b 100644 --- a/pythonbpf/structs/struct_type.py +++ b/pythonbpf/structs/struct_type.py @@ -8,7 +8,7 @@ class StructType: self.size = size def field_idx(self, field_name): - return self.fields.keys().index(field_name) + return list(self.fields.keys()).index(field_name) def field_type(self, field_name): return self.fields[field_name] diff --git a/pythonbpf/structs/structs_pass.py b/pythonbpf/structs/structs_pass.py index 6557e68..cccc119 100644 --- a/pythonbpf/structs/structs_pass.py +++ b/pythonbpf/structs/structs_pass.py @@ -2,6 +2,7 @@ import ast import logging from llvmlite import ir from .type_deducer import ctypes_to_ir +from .struct_type import StructType logger = logging.getLogger(__name__) @@ -35,14 +36,11 @@ def process_bpf_struct(cls_node, module): """ Process a single BPF struct definition """ fields = parse_struct_fields(cls_node) - total_size = calc_struct_size(fields.values()) - struct_type = ir.LiteralStructType(fields.values()) + field_types = list(fields.values()) + total_size = calc_struct_size(field_types) + struct_type = ir.LiteralStructType(field_types) logger.info(f"Created struct {cls_node.name} with fields {fields.keys()}") - return { - "type": struct_type, - "fields": fields, - "size": total_size, - } + return StructType(struct_type, fields, total_size) def parse_struct_fields(cls_node):