patch_seq_string_to_cstring

Function patch_seq_string_to_cstring 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn patch_seq_string_to_cstring( stack: Stack, _out: *mut u8, ) -> *mut u8
Expand description

Convert a Seq String on the stack to a null-terminated C string.

The returned pointer must be freed by the caller using free(). This peeks the string from the stack (caller pops after use).

Stack effect: ( String – ) returns ptr to C string

§Memory Safety

The returned C string is a completely independent copy allocated via malloc(). It has no connection to Seq’s memory management:

  • The Seq String on the stack remains valid and unchanged
  • The returned pointer is owned by the C world and must be freed with free()
  • Even if the Seq String is garbage collected, the C string remains valid
  • Multiple calls with the same Seq String produce independent C strings

This design ensures FFI calls cannot cause use-after-free or double-free bugs between Seq and C code.

§Safety

Stack must have a String value on top. The unused second argument exists for future extension (passing output buffer).