From 4f433d00cc849db94be530f3c991cf07b8849f9c Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 6 Oct 2025 23:04:45 +0530 Subject: [PATCH] Add Boolean return support --- pythonbpf/expr_pass.py | 9 ++++----- tests/passing_tests/return/bool.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/passing_tests/return/bool.py diff --git a/pythonbpf/expr_pass.py b/pythonbpf/expr_pass.py index fd673df..b037cc3 100644 --- a/pythonbpf/expr_pass.py +++ b/pythonbpf/expr_pass.py @@ -22,12 +22,11 @@ def _handle_name_expr(expr: ast.Name, local_sym_tab: Dict, builder: ir.IRBuilder def _handle_constant_expr(expr: ast.Constant): """Handle ast.Constant expressions.""" - if isinstance(expr.value, int): - return ir.Constant(ir.IntType(64), expr.value), ir.IntType(64) - elif isinstance(expr.value, bool): - return ir.Constant(ir.IntType(1), int(expr.value)), ir.IntType(1) + logger.info("We the best") + if isinstance(expr.value, int) or isinstance(expr.value, bool): + return ir.Constant(ir.IntType(64), int(expr.value)), ir.IntType(64) else: - logger.info("Unsupported constant type") + logger.error("Unsupported constant type") return None diff --git a/tests/passing_tests/return/bool.py b/tests/passing_tests/return/bool.py new file mode 100644 index 0000000..b5627a6 --- /dev/null +++ b/tests/passing_tests/return/bool.py @@ -0,0 +1,18 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + return True + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile()