From 0042280ff1e27e56e049c2aeba4ff5e58a09aad9 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 13 Oct 2025 04:23:58 +0530 Subject: [PATCH] Rename public API and remove deadcode in return_utils --- pythonbpf/functions/functions_pass.py | 8 ++++---- pythonbpf/functions/return_utils.py | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 45d7b0a..f706a84 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -14,7 +14,7 @@ from pythonbpf.assign_pass import ( ) from pythonbpf.allocation_pass import handle_assign_allocation, allocate_temp_pool -from .return_utils import _handle_none_return, _handle_xdp_return, _is_xdp_name +from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name logger = logging.getLogger(__name__) @@ -146,9 +146,9 @@ def handle_if( 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) and _is_xdp_name(stmt.value.id): - return _handle_xdp_return(stmt, builder, ret_type) + return handle_none_return(builder) + elif isinstance(stmt.value, ast.Name) and is_xdp_name(stmt.value.id): + return handle_xdp_return(stmt, builder, ret_type) else: val = eval_expr( func=None, diff --git a/pythonbpf/functions/return_utils.py b/pythonbpf/functions/return_utils.py index c69e416..a05c704 100644 --- a/pythonbpf/functions/return_utils.py +++ b/pythonbpf/functions/return_utils.py @@ -14,19 +14,19 @@ XDP_ACTIONS = { } -def _handle_none_return(builder) -> bool: +def handle_none_return(builder) -> bool: """Handle return or return None -> returns 0.""" builder.ret(ir.Constant(ir.IntType(64), 0)) logger.debug("Generated default return: 0") return True -def _is_xdp_name(name: str) -> bool: +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: +def handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool: """Handle XDP returns""" if not isinstance(stmt.value, ast.Name): return False @@ -37,7 +37,6 @@ def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool: raise ValueError( f"Unknown XDP action: {action_name}. Available: {XDP_ACTIONS.keys()}" ) - return False value = XDP_ACTIONS[action_name] builder.ret(ir.Constant(ret_type, value))