Skip to content

Commit a21ff56

Browse files
committed
Add _handle_none_return
1 parent f96a6b9 commit a21ff56

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pythonbpf.binary_ops import handle_binary_op
1010
from pythonbpf.expr_pass import eval_expr, handle_expr
1111

12+
from .return_utils import _handle_none_return
13+
1214

1315
logger = logging.getLogger(__name__)
1416

@@ -353,8 +355,7 @@ def handle_if(
353355

354356
def handle_return(builder, stmt, local_sym_tab, ret_type):
355357
if stmt.value is None:
356-
builder.ret(ir.Constant(ir.IntType(64), 0))
357-
return True
358+
return _handle_none_return(builder)
358359
elif (
359360
isinstance(stmt.value, ast.Call)
360361
and isinstance(stmt.value.func, ast.Name)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging
2+
import ir
3+
4+
logger: logging.Logger = logging.getLogger(__name__)
5+
6+
7+
def _handle_none_return(builder) -> bool:
8+
"""Handle return or return None -> returns 0."""
9+
builder.ret(ir.Constant(ir.IntType(64), 0))
10+
logger.debug("Generated default return: 0")
11+
return True

0 commit comments

Comments
 (0)