Skip to content

Commit 9cd8e10

Browse files
r41k0uclaude
andcommitted
Core: Review nits on the signedness branch
- A global's descriptor is built from the loaded value, not from None. - get_operand_value, the [0] wrapper over get_typed_operand, had no callers left; removed with its export. - infer_int_type's map branch names the map's declared value type for what it is (value_ctype), says that the key argument plays no part, and applies only to lookup: update and delete return a status, not a value of the map's type. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 532dc0f commit 9cd8e10

4 files changed

Lines changed: 17 additions & 19 deletions

File tree

‎pythonbpf/expr/__init__.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .expr_pass import eval_expr, handle_expr, get_operand_value, get_typed_operand
1+
from .expr_pass import eval_expr, handle_expr, get_typed_operand
22
from .type_normalization import (
33
convert_to_bool,
44
get_base_type_and_depth,
@@ -25,7 +25,6 @@
2525
"deref_to_depth",
2626
"apply_binop",
2727
"access_struct_field",
28-
"get_operand_value",
2928
"CallHandlerRegistry",
3029
"VmlinuxHandlerRegistry",
3130
]

‎pythonbpf/expr/expr_pass.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ def get_typed_operand(func, compilation_context, operand, builder, local_sym_tab
237237
)
238238
elif operand.id in compilation_context.bpf_globals:
239239
sym = compilation_context.bpf_globals[operand.id]
240-
return builder.load(sym.var), _descriptor(None, sym.ir_type)
240+
val = builder.load(sym.var)
241+
return val, _descriptor(val, sym.ir_type)
241242
else:
242243
vmlinux_result = VmlinuxHandlerRegistry.handle_name(operand.id)
243244
if vmlinux_result is not None:
@@ -265,13 +266,6 @@ def get_typed_operand(func, compilation_context, operand, builder, local_sym_tab
265266
raise TypeError(f"Unsupported operand type: {type(operand)}")
266267

267268

268-
def get_operand_value(func, compilation_context, operand, builder, local_sym_tab):
269-
"""Extract the value from an operand, handling variables and constants."""
270-
return get_typed_operand(
271-
func, compilation_context, operand, builder, local_sym_tab
272-
)[0]
273-
274-
275269
def _handle_binary_op_impl(func, compilation_context, rval, builder, local_sym_tab):
276270
"""A binary operation, typed per node the way C types it: the operation is
277271
performed in the type given by the usual arithmetic conversions of its two

‎pythonbpf/expr/type_inference.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,21 @@ def infer_int_type(expr, local_sym_tab, compilation_context):
6666
return _as_intty(HelperHandlerRegistry.get_return_type(name))
6767
return None
6868

69-
if isinstance(expr, ast.Call) and isinstance(expr.func, ast.Attribute):
70-
# map.lookup(k) used as a value: the map's declared value type
69+
if (
70+
isinstance(expr, ast.Call)
71+
and isinstance(expr.func, ast.Attribute)
72+
and expr.func.attr == "lookup"
73+
):
74+
# m.lookup(...) used as a value has the type the map declares for its
75+
# values, whatever the key argument looks like. The declaration is a
76+
# ctypes name for a scalar map and a struct name otherwise, which is
77+
# not an integer, so None.
7178
map_name = getattr(expr.func.value, "id", None)
7279
sym = compilation_context.map_sym_tab.get(map_name)
73-
value = (sym.params or {}).get("value") if sym else None
74-
return (
75-
_as_intty(ctypes_to_ir(value))
76-
if isinstance(value, str) and is_ctypes(value)
77-
else None
78-
)
80+
value_ctype = (sym.params or {}).get("value") if sym else None
81+
if isinstance(value_ctype, str) and is_ctypes(value_ctype):
82+
return _as_intty(ctypes_to_ir(value_ctype))
83+
return None
7984

8085
if isinstance(expr, ast.Attribute) and isinstance(expr.value, ast.Name):
8186
base = local_sym_tab.get(expr.value.id)

‎pythonbpf/functions/functions_pass.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def handle_aug_assign(func, compilation_context, builder, stmt, local_sym_tab):
203203
compiler walks the tree the user wrote, and nodes invented mid-codegen are
204204
invisible to the passes that already ran and carry no source locations.
205205
Semantic agreement with `x = x op v` comes from sharing the value-level
206-
helpers instead — the RHS goes through get_operand_value like any other
206+
helpers instead — the RHS goes through get_typed_operand like any other
207207
read, and the operator table is apply_binop, the same one binary-op
208208
evaluation uses.
209209
"""

0 commit comments

Comments
 (0)