Skip to content

Commit 03c35f2

Browse files
Merge master into fix/register-state-dump-keyerror (resolve conflict with #94)
2 parents 1c349c8 + c4c0c58 commit 03c35f2

24 files changed

Lines changed: 260 additions & 54 deletions

.github/workflows/format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
name: Format
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v6
16-
- uses: actions/setup-python@v6
15+
- uses: actions/checkout@v7
16+
- uses: actions/setup-python@v7
1717
with:
1818
python-version: "3.x"
1919
- uses: pre-commit/action@v3.0.1

.github/workflows/python-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
runs-on: ubuntu-latest
2121

2222
steps:
23-
- uses: actions/checkout@v6
23+
- uses: actions/checkout@v7
2424

25-
- uses: actions/setup-python@v6
25+
- uses: actions/setup-python@v7
2626
with:
2727
python-version: "3.x"
2828

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ test:
1010
pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier"
1111

1212
test-cov:
13-
pytest tests/ -v --tb=short -m "not verifier" \
13+
pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier" \
1414
--cov=pythonbpf --cov-report=term-missing --cov-report=html
1515

1616
test-verifier:
17-
@echo "NOTE: verifier tests require sudo and bpftool. Uses sudo .venv/bin/python3."
18-
pytest tests/test_verifier.py -v --tb=short -m verifier
17+
@echo "NOTE: verifier tests shell out to 'sudo bpftool'; run 'sudo -v' first so"
18+
@echo " the timestamp does not lapse mid-run. bpftool must be installed."
19+
pytest tests/test_verifier.py -W ignore::DeprecationWarning -v --tb=short -m verifier
1920

2021
all: clean install
2122

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ This architecture eliminates the need for embedding C code in Python, allowing f
222222

223223
---
224224

225-
## Resources
225+
## Resources and Talks
226226

227+
* [Linux Plumbers Conference 2025](https://www.youtube.com/watch?v=eFVhLnWFxtE)
227228
* [Video demonstration](https://youtu.be/eMyLW8iWbks)
228-
* [Slide deck](https://docs.google.com/presentation/d/1DsWDIVrpJhM4RgOETO9VWqUtEHo3-c7XIWmNpi6sTSo/edit?usp=sharing)
229+
* [More Demos](https://www.youtube.com/watch?v=GN17VBZYdCY)
230+
* [FOSDEM 2026](https://mirrors.dotsrc.org/fosdem/2026/h1308/T9D8ZR-pythonbpf.mp4)
229231

230232
---
231233

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
project = "PythonBPF"
1616
copyright = "2026, Pragyansh Chaturvedi, Varun Mallya"
1717
author = "Pragyansh Chaturvedi, Varun Mallya"
18-
release = "0.1.8"
19-
version = "0.1.8"
18+
release = "0.1.9"
19+
version = "0.1.9"
2020

2121
# -- General configuration ---------------------------------------------------
2222
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pythonbpf"
7-
version = "0.1.8"
7+
version = "0.1.9"
88
description = "Reduced Python frontend for eBPF"
99
authors = [
1010
{ name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" },

pythonbpf/allocation_pass.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ def _allocate_for_attribute(
340340

341341
struct_type: type = local_sym_tab[struct_var].metadata
342342
if not struct_type or struct_type not in structs_sym_tab:
343-
if VmlinuxHandlerRegistry.is_vmlinux_struct(struct_type.__name__):
343+
# `metadata` only names a struct for struct-typed symbols. For anything
344+
# else (None, an IR type, or a plain ctypes class such as a `c_void_p`
345+
# context parameter) there is no vmlinux struct name to look up, so guard
346+
# the attribute access instead of blowing up with an AttributeError.
347+
vmlinux_struct_name = getattr(struct_type, "__name__", None)
348+
if vmlinux_struct_name and VmlinuxHandlerRegistry.is_vmlinux_struct(
349+
vmlinux_struct_name
350+
):
344351
# Handle vmlinux struct field access
345-
vmlinux_struct_name = struct_type.__name__
346352
# Same discriminator handle_vmlinux_struct_field uses: a context
347353
# argument has no alloca of its own.
348354
is_context_field = local_sym_tab[struct_var].var is None

pythonbpf/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
logger: Logger = logging.getLogger(__name__)
2828

29-
VERSION = "v0.1.8"
29+
VERSION = "v0.1.9"
3030

3131

3232
def finalize_module(original_str):

pythonbpf/expr/ir_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def deref_to_depth(func, builder, val, target_depth):
1111
cur_type = val.type
1212

1313
for depth in range(target_depth):
14-
if not isinstance(val.type, ir.PointerType):
14+
if not isinstance(cur_type, ir.PointerType):
1515
logger.error("Cannot dereference further, non-pointer type")
1616
return None
1717

pythonbpf/functions/functions_pass.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from llvmlite import ir
22
import ast
3+
import ctypes
34
import logging
45

56
from pythonbpf.helper import (
67
HelperHandlerRegistry,
78
)
8-
from pythonbpf.type_deducer import ctypes_to_ir
9+
from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes
910
from pythonbpf.expr import (
1011
eval_expr,
1112
handle_expr,
@@ -325,13 +326,28 @@ def process_func_body(
325326
f"Unsupported annotation type: {ast.dump(context_arg.annotation)}"
326327
)
327328

329+
# NOTE: `var` is None for the context parameter. It is the sentinel
330+
# that tells consumers the symbol is an incoming function argument
331+
# (`func.args[0]`) rather than a stack slot they can load from.
328332
if VmlinuxHandlerRegistry.is_vmlinux_struct(context_type_name):
329333
resolved_type = VmlinuxHandlerRegistry.get_struct_type(
330334
context_type_name
331335
)
332336
context_type = LocalSymbol(None, None, resolved_type)
333337
local_sym_tab[context_name] = context_type
334338
logger.info(f"Added argument '{context_name}' to local symbol table")
339+
elif is_ctypes(context_type_name):
340+
# Plain ctypes annotation, e.g. `ctx: c_void_p`. Register it so
341+
# helpers that take the raw context (probe_read, ...) can resolve
342+
# the name. Metadata is the annotated Python type, mirroring the
343+
# vmlinux branch above.
344+
context_type = LocalSymbol(
345+
None,
346+
ir.PointerType(),
347+
getattr(ctypes, context_type_name, None),
348+
)
349+
local_sym_tab[context_name] = context_type
350+
logger.info(f"Added argument '{context_name}' to local symbol table")
335351

336352
# pre-allocate dynamic variables
337353
local_sym_tab = allocate_mem(

0 commit comments

Comments
 (0)