Decode a Perry-side string pointer (i64 on this ABI) into a borrowed &str. Returns "" for null / too-small pointers to keep the FFI boundary robust.
(ptr: i64)
| 38 | /// Decode a Perry-side string pointer (i64 on this ABI) into a borrowed &str. |
| 39 | /// Returns "" for null / too-small pointers to keep the FFI boundary robust. |
| 40 | fn perry_str<'a>(ptr: i64) -> &'a str { |
| 41 | if ptr == 0 { return ""; } |
| 42 | let p = ptr as *const u8; |
| 43 | if (p as usize) < 0x1000 { return ""; } |
| 44 | unsafe { |
| 45 | let header = p as *const StringHeader; |
| 46 | let len = (*header).byte_len as usize; |
| 47 | let data = p.add(std::mem::size_of::<StringHeader>()); |
| 48 | std::str::from_utf8_unchecked(std::slice::from_raw_parts(data, len)) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /// Allocate a Perry-side heap string (StringHeader + UTF-8 payload) and return |
| 53 | /// its pointer as the i64 the FFI boundary expects. Mirrors `perry_str`'s |
no outgoing calls
no test coverage detected