mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
A struct-field test with a non-add operator and a sub-64-bit field (the narrow-on-store path), and a strict expected failure for counter += 1 without a global statement, which now fails as loudly as plain assignment does. Ruff flags that line as F823 (referenced before assignment) -- the same UnboundLocalError Python itself would raise, which is exactly the semantics the global statement requirement mirrors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
36 lines
711 B
Python
36 lines
711 B
Python
# Augmented assignment to a struct field: one GEP, load, op, store. Also a
|
|
# non-add operator and a sub-64-bit field, which exercises the narrow-on-store
|
|
# path of the direct lowering.
|
|
from pythonbpf import bpf, section, bpfglobal, compile, struct
|
|
from ctypes import c_void_p, c_int64, c_uint64, c_uint32
|
|
|
|
|
|
@bpf
|
|
@struct
|
|
class data_t:
|
|
pid: c_uint64
|
|
hits: c_uint32
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/raw_syscalls/sys_enter")
|
|
def prog(ctx: c_void_p) -> c_int64:
|
|
x = 5
|
|
x -= 1
|
|
dat = data_t()
|
|
dat.pid = 10
|
|
dat.pid += x
|
|
dat.hits = 1
|
|
dat.hits <<= 2
|
|
print(f"pid {dat.pid} hits {dat.hits} x {x}")
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|