Extract a &str from a *const StringHeader pointer (Perry string format).
(ptr: *const u8)
| 23 | |
| 24 | /// Extract a &str from a *const StringHeader pointer (Perry string format). |
| 25 | pub fn str_from_header(ptr: *const u8) -> &'static str { |
| 26 | if ptr.is_null() || (ptr as usize) < 0x1000 { |
| 27 | return ""; |
| 28 | } |
| 29 | unsafe { |
| 30 | let header = ptr as *const StringHeader; |
| 31 | let len = (*header).byte_len as usize; |
| 32 | let data = ptr.add(std::mem::size_of::<StringHeader>()); |
| 33 | std::str::from_utf8_unchecked(std::slice::from_raw_parts(data, len)) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /// Allocate a Perry 0.5.x heap string suitable for returning across the |
| 38 | /// FFI boundary (declared as `returns: "string"` in package.json). Layout |
no outgoing calls
no test coverage detected