Skip to content

Commit 8da50b7

Browse files
float assignments to class_handler.py
1 parent e636fca commit 8da50b7

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

pythonbpf/vmlinux_parser/assignment_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum, auto
2-
from typing import Any, Callable, Dict, List, Optional, TypedDict
2+
from typing import Any, Dict, List, Optional, TypedDict
33
from dataclasses import dataclass
44

55
from pythonbpf.vmlinux_parser.dependency_node import Field
@@ -13,6 +13,7 @@ class AssignmentType(Enum):
1313
FUNCTION_POINTER = auto()
1414
POINTER = auto() # again, probably won't be used
1515

16+
1617
@dataclass
1718
class FunctionSignature(TypedDict):
1819
return_type: str

pythonbpf/vmlinux_parser/class_handler.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
from functools import lru_cache
33
import importlib
4+
5+
from .assignment_info import AssignmentInfo
46
from .dependency_handler import DependencyHandler
57
from .dependency_node import DependencyNode
68
import ctypes
@@ -15,17 +17,26 @@ def get_module_symbols(module_name: str):
1517
return [name for name in dir(imported_module)], imported_module
1618

1719

18-
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
20+
def process_vmlinux_class(
21+
node,
22+
llvm_module,
23+
handler: DependencyHandler,
24+
assignments: dict[str, AssignmentInfo],
25+
):
1926
symbols_in_module, imported_module = get_module_symbols("vmlinux")
2027
if node.name in symbols_in_module:
2128
vmlinux_type = getattr(imported_module, node.name)
22-
process_vmlinux_post_ast(vmlinux_type, llvm_module, handler)
29+
process_vmlinux_post_ast(vmlinux_type, llvm_module, handler, assignments)
2330
else:
2431
raise ImportError(f"{node.name} not in vmlinux")
2532

2633

2734
def process_vmlinux_post_ast(
28-
elem_type_class, llvm_handler, handler: DependencyHandler, processing_stack=None
35+
elem_type_class,
36+
llvm_handler,
37+
handler: DependencyHandler,
38+
assignments: dict[str, AssignmentInfo],
39+
processing_stack=None,
2940
):
3041
# Initialize processing stack on first call
3142
if processing_stack is None:
@@ -46,7 +57,7 @@ def process_vmlinux_post_ast(
4657
logger.debug(f"Node {current_symbol_name} already processed and ready")
4758
return True
4859

49-
# XXX:Check it's use. It's probably not being used.
60+
# XXX:Check its use. It's probably not being used.
5061
if current_symbol_name in processing_stack:
5162
logger.debug(
5263
f"Dependency already in processing stack for {current_symbol_name}, skipping"

pythonbpf/vmlinux_parser/import_detector.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ast
22
import logging
3-
from typing import List, Tuple, Any
43
import importlib
54
import inspect
65

@@ -12,7 +11,7 @@
1211
logger = logging.getLogger(__name__)
1312

1413

15-
def detect_import_statement(tree: ast.AST) -> List[Tuple[str, ast.ImportFrom]]:
14+
def detect_import_statement(tree: ast.AST) -> list[tuple[str, ast.ImportFrom]]:
1615
"""
1716
Parse AST and detect import statements from vmlinux.
1817
@@ -113,7 +112,7 @@ def vmlinux_proc(tree: ast.AST, module):
113112
isinstance(mod_node, ast.ClassDef)
114113
and mod_node.name == imported_name
115114
):
116-
process_vmlinux_class(mod_node, module, handler)
115+
process_vmlinux_class(mod_node, module, handler, assignments)
117116
found = True
118117
break
119118
if isinstance(mod_node, ast.Assign):
@@ -148,7 +147,7 @@ def process_vmlinux_assign(node, module, assignments: dict[str, AssignmentInfo])
148147
value=node.value.value,
149148
pointer_level=None,
150149
signature=None,
151-
members=None
150+
members=None,
152151
)
153152
logger.info(
154153
f"Added assignment: {target_name} = {node.value.value!r} of type {type(node.value.value)}"

tests/passing_tests/vmlinux/simple_struct_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile
1+
from pythonbpf import bpf, section, bpfglobal, compile_to_ir
22
from vmlinux import TASK_COMM_LEN # noqa: F401
33
from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
44

0 commit comments

Comments
 (0)