Skip to content

Commit 4f433d0

Browse files
committed
Add Boolean return support
1 parent 6cf5115 commit 4f433d0

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pythonbpf/expr_pass.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ def _handle_name_expr(expr: ast.Name, local_sym_tab: Dict, builder: ir.IRBuilder
2222

2323
def _handle_constant_expr(expr: ast.Constant):
2424
"""Handle ast.Constant expressions."""
25-
if isinstance(expr.value, int):
26-
return ir.Constant(ir.IntType(64), expr.value), ir.IntType(64)
27-
elif isinstance(expr.value, bool):
28-
return ir.Constant(ir.IntType(1), int(expr.value)), ir.IntType(1)
25+
logger.info("We the best")
26+
if isinstance(expr.value, int) or isinstance(expr.value, bool):
27+
return ir.Constant(ir.IntType(64), int(expr.value)), ir.IntType(64)
2928
else:
30-
logger.info("Unsupported constant type")
29+
logger.error("Unsupported constant type")
3130
return None
3231

3332

tests/passing_tests/return/bool.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
return True
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()

0 commit comments

Comments
 (0)