1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Owned-out-string allocation. Every C-ABI function that hands a
//! string back to the caller goes through [`alloc_c_string`] (which
//! returns a `*const c_char` the caller MUST free via
//! [`kglite_free_string`]).
//!
//! Convention: there is exactly ONE `kglite_free_string`. We never
//! ship per-context variants — bindings learn the single freer and
//! reach for it for every owned string from any kglite function.
use ;
/// Allocate a C-owned, null-terminated UTF-8 string. The caller is
/// responsible for freeing the returned pointer via
/// [`kglite_free_string`]. Returns a null pointer if the input
/// contains an embedded NUL byte (`'\0'`) — `CString` would reject
/// it. Callers that hit this should sanitize their input.
pub
/// Free a string previously returned by any `kglite_*` function.
///
/// Safety: `s` must be either null or a pointer previously returned
/// by a `kglite_*` function (these all flow through
/// [`alloc_c_string`]). Calling twice on the same pointer is UB.
/// Calling with a pointer to a string allocated by the C caller's
/// own `malloc` is UB.
///
/// Passing null is safe (treated as a no-op).
///
/// # Examples
///
/// ```c
/// const char* col_json = kglite_cypher_result_columns_json(result);
/// printf("%s\n", col_json);
/// kglite_free_string(col_json);
/// ```
pub unsafe extern "C"