From e6e2a6950654ae8353a4f956e80a90447322e328 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 6 Oct 2025 03:02:08 +0530 Subject: [PATCH] Add _is_xdp_name --- pythonbpf/functions/functions_pass.py | 4 ++-- pythonbpf/functions/return_utils.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 63a6aed..16554f5 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -9,7 +9,7 @@ from pythonbpf.type_deducer import ctypes_to_ir from pythonbpf.binary_ops import handle_binary_op from pythonbpf.expr_pass import eval_expr, handle_expr -from .return_utils import _handle_none_return, _handle_xdp_return +from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name logger = logging.getLogger(__name__) @@ -357,7 +357,7 @@ def handle_return(builder, stmt, local_sym_tab, ret_type): logger.info(f"Handling return statement: {ast.dump(stmt)}") if stmt.value is None: return _handle_none_return(builder) - elif isinstance(stmt.value, ast.Name): + elif isinstance(stmt.value, ast.Name) and _is_xdp_name(stmt.value.id): return _handle_xdp_return(stmt, builder, ret_type) elif ( isinstance(stmt.value, ast.Call) diff --git a/pythonbpf/functions/return_utils.py b/pythonbpf/functions/return_utils.py index a3f08af..50f3a30 100644 --- a/pythonbpf/functions/return_utils.py +++ b/pythonbpf/functions/return_utils.py @@ -111,6 +111,11 @@ def _handle_wrapped_return(stmt: ast.Return, builder, ret_type, local_sym_tab) - raise ValueError(f"Unsupported return argument type: {type(arg).__name__}") +def _is_xdp_name(name: str) -> bool: + """Check if a name is an XDP action""" + return name in XDP_ACTIONS + + def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool: """Handle XDP returns""" if not isinstance(stmt.value, ast.Name):