From d7a763639a2f3eda4da2bdb7ade58c2c1327ab0f Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Fri, 7 Aug 2026 04:39:01 +0530 Subject: [PATCH] Core: Guard vmlinux struct lookup against non-class metadata _allocate_for_attribute reached for `metadata.__name__` whenever the base symbol was not a known user struct, but `metadata` is only a struct class for struct-typed symbols. For a symbol carrying None (any plainly typed local) or a ctypes class (a `c_void_p` context parameter), that raised AttributeError instead of reporting the unsupported access. Resolve the name via getattr and fall through to the existing "struct type not found" diagnostic when there is none. Co-Authored-By: Claude Opus 5 (1M context) --- pythonbpf/allocation_pass.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pythonbpf/allocation_pass.py b/pythonbpf/allocation_pass.py index 9aaaf19..293839d 100644 --- a/pythonbpf/allocation_pass.py +++ b/pythonbpf/allocation_pass.py @@ -340,9 +340,15 @@ def _allocate_for_attribute( struct_type: type = local_sym_tab[struct_var].metadata if not struct_type or struct_type not in structs_sym_tab: - if VmlinuxHandlerRegistry.is_vmlinux_struct(struct_type.__name__): + # `metadata` only names a struct for struct-typed symbols. For anything + # else (None, an IR type, or a plain ctypes class such as a `c_void_p` + # context parameter) there is no vmlinux struct name to look up, so guard + # the attribute access instead of blowing up with an AttributeError. + vmlinux_struct_name = getattr(struct_type, "__name__", None) + if vmlinux_struct_name and VmlinuxHandlerRegistry.is_vmlinux_struct( + vmlinux_struct_name + ): # Handle vmlinux struct field access - vmlinux_struct_name = struct_type.__name__ if not VmlinuxHandlerRegistry.has_field(vmlinux_struct_name, field_name): logger.error( f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'"