Skip to content

Commit 83f2cb4

Browse files
committed
Update map access syntax in SPEC.md.
1 parent ab362f0 commit 83f2cb4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

SPEC.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,9 @@ var flow_map : hash<FlowKey, FlowData>(1024)
20362036
@helper
20372037
fn map_pointer_operations(flow_key: FlowKey) {
20382038
// Map lookup returns pointer to value
2039-
var flow_data: *FlowData = flow_map.lookup(flow_key)
2039+
var flow_data = flow_map[flow_key]
20402040
2041-
if (flow_data != null) {
2041+
if (flow_data != none) {
20422042
// Direct modification through pointer
20432043
flow_data->packet_count += 1
20442044
flow_data->byte_count += packet_size
@@ -3512,14 +3512,14 @@ var cache_map : hash<u32, DataCache>(1024)
35123512
35133513
@helper
35143514
fn map_lifetime_safety(key: u32) {
3515-
var cache_entry: *DataCache = cache_map.lookup(key)
3516-
if (cache_entry != null) {
3515+
var cache_entry = cache_map[key]
3516+
if (cache_entry != none) {
35173517
// Compiler tracks that cache_entry is valid here
35183518
cache_entry->access_count += 1
35193519
cache_entry->last_access = bpf_ktime_get_ns()
35203520
35213521
// Compiler warns/errors if cache_entry used after invalidating operations
3522-
cache_map.update(other_key, other_value) // Invalidates cache_entry
3522+
cache_map[other_key] = other_value // Invalidates cache_entry
35233523
35243524
// ❌ Compiler error: "Use of potentially invalidated map value pointer"
35253525
// cache_entry->access_count += 1
@@ -3568,8 +3568,8 @@ fn kernel_side_processing(ctx: *xdp_md) -> xdp_action {
35683568
var packet_data = ctx->data()
35693569
35703570
// Shared memory through maps - safe across contexts
3571-
var shared_buffer = shared_map.lookup(0)
3572-
if (shared_buffer != null) {
3571+
var shared_buffer = shared_map[0]
3572+
if (shared_buffer != none) {
35733573
shared_buffer->kernel_processed_count += 1
35743574
memory_copy(packet_data, shared_buffer->data, min(packet_len, 64))
35753575
}
@@ -3583,8 +3583,8 @@ fn userspace_processing() -> i32 {
35833583
// var packet_data = some_kernel_context.data() // Compilation error
35843584
35853585
// ✅ Access through shared maps
3586-
var shared_buffer = shared_map.lookup(0)
3587-
if (shared_buffer != null) {
3586+
var shared_buffer = shared_map[0]
3587+
if (shared_buffer != none) {
35883588
shared_buffer->userspace_processed_count += 1
35893589
process_shared_data(shared_buffer->data)
35903590
}

0 commit comments

Comments
 (0)