[][src]Function ffi_support::rust_string_from_c

pub unsafe fn rust_string_from_c(c_string: *const c_char) -> String
Deprecated since 0.3.0:

Please use FfiStr::into_string instead

Convert a null-terminated C into an owned rust string, replacing invalid UTF-8 with the unicode replacement character.

Safety

This is unsafe because we dereference a raw pointer, which may or may not be valid.

We also assume c_string is a null terminated string, and have no way of knowing if that's actually true. If it's not, we'll read arbitrary memory from the heap until we see a '\0', which can result in a enormous number of problems.

Panics

Panics if it's argument is null. See also opt_rust_string_from_c, which returns None instead.

Note: This means it's forbidden to call this outside of a call_with_result (or something else that uses std::panic::catch_unwind), as it is UB to panic across the FFI boundary.