MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / safe_bytes

Function safe_bytes

compiler/src/main/mod.rs:139–142  ·  view source on GitHub ↗

Builds a `&[u8]` from an FFI `(ptr, len)`, empty on null or zero length, `from_raw_parts` would UB on either. */

(ptr: *const u8, len: u32)

Source from the content-addressed store, hash-verified

137
138/* Builds a `&[u8]` from an FFI `(ptr, len)`, empty on null or zero length, `from_raw_parts` would UB on either. */
139pub(super) unsafe fn safe_bytes<'a>(ptr: *const u8, len: u32) -> &'a [u8] {
140 if ptr.is_null() || len == 0 { return &[]; }
141 unsafe { core::slice::from_raw_parts(ptr, len as usize) }
142}
143
144/* Same for `&[u32]` argv arrays. */
145pub(super) unsafe fn safe_handles<'a>(ptr: *const u32, len: u32) -> &'a [u32] {

Callers 4

safe_str_ownedFunction · 0.85
register_native_moduleFunction · 0.85
run_push_eventFunction · 0.85
host_edge_encodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected