Compare commits

...

10 Commits

Author SHA1 Message Date
5311a16c21 Bump version to 0.1.9 2026-06-05 22:19:18 +05:30
8c5069f424 Merge pull request #85 from pythonbpf/fix/comprehensive-store-type-mismatch
Fix comprehensive test
2026-06-01 12:09:55 +05:30
5a9c77f016 janitorial 2026-06-01 12:09:06 +05:30
d0f7a9dcec Add DEBUG log in case of no expected type or target is not a pointer 2026-06-01 12:06:33 +05:30
0dea1836df Pass expected_type to bpf_map_delete_elem key arg
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-31 15:32:03 +05:30
7cdb9cb2f5 Add null-safety check after deref_to_depth in helper_utils
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-31 15:31:53 +05:30
0482aa2be9 Fix deref_to_depth loop type check to use cur_type
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-31 15:31:43 +05:30
d4f1b5a9b4 Handle nested map lookup helper args
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-31 12:46:11 +05:30
c2de7dad96 Temporarily ignore deprecation warnings for vmlinux.py 2026-05-27 14:53:54 +05:30
d1bb0191c9 Merge pull request #84 from pythonbpf/testing-framework
Automated testing framework which will give us regression and coverage reports, meant to run in a GH Action and locally
2026-04-25 23:02:00 +05:30
7 changed files with 44 additions and 10 deletions

View File

@ -7,7 +7,7 @@ clean:
rm -rf htmlcov .coverage rm -rf htmlcov .coverage
test: test:
pytest tests/ -v --tb=short -m "not verifier" pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier"
test-cov: test-cov:
pytest tests/ -v --tb=short -m "not verifier" \ pytest tests/ -v --tb=short -m "not verifier" \

View File

@ -15,8 +15,8 @@ sys.path.insert(0, os.path.abspath(".."))
project = "PythonBPF" project = "PythonBPF"
copyright = "2026, Pragyansh Chaturvedi, Varun Mallya" copyright = "2026, Pragyansh Chaturvedi, Varun Mallya"
author = "Pragyansh Chaturvedi, Varun Mallya" author = "Pragyansh Chaturvedi, Varun Mallya"
release = "0.1.8" release = "0.1.9"
version = "0.1.8" version = "0.1.9"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "pythonbpf" name = "pythonbpf"
version = "0.1.8" version = "0.1.9"
description = "Reduced Python frontend for eBPF" description = "Reduced Python frontend for eBPF"
authors = [ authors = [
{ name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" }, { name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" },

View File

@ -26,7 +26,7 @@ import re
logger: Logger = logging.getLogger(__name__) logger: Logger = logging.getLogger(__name__)
VERSION = "v0.1.8" VERSION = "v0.1.9"
def finalize_module(original_str): def finalize_module(original_str):

View File

@ -11,7 +11,7 @@ def deref_to_depth(func, builder, val, target_depth):
cur_type = val.type cur_type = val.type
for depth in range(target_depth): for depth in range(target_depth):
if not isinstance(val.type, ir.PointerType): if not isinstance(cur_type, ir.PointerType):
logger.error("Cannot dereference further, non-pointer type") logger.error("Cannot dereference further, non-pointer type")
return None return None

View File

@ -113,7 +113,12 @@ def bpf_map_lookup_elem_emitter(
f"Map lookup expects exactly one argument (key), got {len(call.args)}" f"Map lookup expects exactly one argument (key), got {len(call.args)}"
) )
key_ptr = get_or_create_ptr_from_arg( key_ptr = get_or_create_ptr_from_arg(
func, compilation_context, call.args[0], builder, local_sym_tab func,
compilation_context,
call.args[0],
builder,
local_sym_tab,
expected_type=ir.IntType(64),
) )
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType()) map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
@ -215,10 +220,20 @@ def bpf_map_update_elem_emitter(
flags_arg = call.args[2] if len(call.args) > 2 else None flags_arg = call.args[2] if len(call.args) > 2 else None
key_ptr = get_or_create_ptr_from_arg( key_ptr = get_or_create_ptr_from_arg(
func, compilation_context, key_arg, builder, local_sym_tab func,
compilation_context,
key_arg,
builder,
local_sym_tab,
expected_type=ir.IntType(64),
) )
value_ptr = get_or_create_ptr_from_arg( value_ptr = get_or_create_ptr_from_arg(
func, compilation_context, value_arg, builder, local_sym_tab func,
compilation_context,
value_arg,
builder,
local_sym_tab,
expected_type=ir.IntType(64),
) )
flags_val = get_flags_val(flags_arg, builder, local_sym_tab) flags_val = get_flags_val(flags_arg, builder, local_sym_tab)
@ -267,7 +282,12 @@ def bpf_map_delete_elem_emitter(
f"Map delete expects exactly one argument (key), got {len(call.args)}" f"Map delete expects exactly one argument (key), got {len(call.args)}"
) )
key_ptr = get_or_create_ptr_from_arg( key_ptr = get_or_create_ptr_from_arg(
func, compilation_context, call.args[0], builder, local_sym_tab func,
compilation_context,
call.args[0],
builder,
local_sym_tab,
expected_type=ir.IntType(64),
) )
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType()) map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())

View File

@ -6,6 +6,8 @@ from pythonbpf.expr import (
eval_expr, eval_expr,
access_struct_field, access_struct_field,
) )
from pythonbpf.expr.ir_ops import deref_to_depth
from pythonbpf.expr.type_normalization import get_base_type_and_depth
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -104,6 +106,18 @@ def get_or_create_ptr_from_arg(
if val is None: if val is None:
raise ValueError("Failed to evaluate expression for helper arg.") raise ValueError("Failed to evaluate expression for helper arg.")
if expected_type and isinstance(val.type, ir.PointerType):
_, val_depth = get_base_type_and_depth(val.type)
_, expected_depth = get_base_type_and_depth(expected_type)
if val_depth > expected_depth:
val = deref_to_depth(func, builder, val, val_depth - expected_depth)
if val is None:
raise ValueError("Failed to dereference pointer to expected depth")
else:
logger.debug(
"Expected Type not known / Not a pointer, skipping dereference"
)
ptr, temp_name = compilation_context.scratch_pool.get_next_temp( ptr, temp_name = compilation_context.scratch_pool.get_next_temp(
local_sym_tab, expected_type local_sym_tab, expected_type
) )