Skip to content

Commit 3396d84

Browse files
committed
Core: Fix incompatible logic in helper/helper_utils
1 parent c22911d commit 3396d84

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

pythonbpf/helper/helper_utils.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,6 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13-
# NOTE: ScratchPoolManager is now in context.py
14-
15-
16-
def get_ptr_from_arg(arg, compilation_context, builder, local_sym_tab):
17-
"""Helper to get a pointer value from an argument."""
18-
# This is a bit duplicative of logic in eval_expr but simplified for helpers
19-
# We might need to handle more cases here or defer to eval_expr
20-
21-
# Simple check for name
22-
if isinstance(arg, ast.Name):
23-
if arg.id in local_sym_tab:
24-
sym = local_sym_tab[arg.id]
25-
if isinstance(sym.ir_type, ir.PointerType):
26-
return builder.load(sym.var)
27-
# If it's an array/struct we might need GEP depending on how it was allocated
28-
# For now assume load returns the pointer/value
29-
return builder.load(sym.var)
30-
31-
# Use eval_expr for general case
32-
val = eval_expr(None, compilation_context, builder, arg, local_sym_tab)
33-
if val and isinstance(val[0].type, ir.PointerType):
34-
return val[0]
35-
36-
return None
37-
38-
3913
# ============================================================================
4014
# Argument Preparation
4115
# ============================================================================
@@ -77,10 +51,7 @@ def get_or_create_ptr_from_arg(
7751
sz = None
7852
if isinstance(arg, ast.Name):
7953
# Stack space is already allocated
80-
if arg.id in local_sym_tab:
81-
ptr = local_sym_tab[arg.id].var
82-
else:
83-
raise ValueError(f"Variable '{arg.id}' not found")
54+
ptr = get_var_ptr_from_name(arg.id, local_sym_tab)
8455
elif isinstance(arg, ast.Constant) and isinstance(arg.value, int):
8556
int_width = 64 # Default to i64
8657
if expected_type and isinstance(expected_type, ir.IntType):
@@ -337,6 +308,22 @@ def _is_char_array(ir_type):
337308
)
338309

339310

311+
def get_ptr_from_arg(arg, func, compilation_context, builder, local_sym_tab):
312+
"""Evaluate argument and return pointer value"""
313+
314+
result = eval_expr(func, compilation_context, builder, arg, local_sym_tab)
315+
316+
if not result:
317+
raise ValueError("Failed to evaluate argument")
318+
319+
val, val_type = result
320+
321+
if not isinstance(val_type, ir.PointerType):
322+
raise ValueError(f"Expected pointer type, got {val_type}")
323+
324+
return val, val_type
325+
326+
340327
def get_int_value_from_arg(arg, func, compilation_context, builder, local_sym_tab):
341328
"""Evaluate argument and return integer value"""
342329

0 commit comments

Comments
 (0)