Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
meowjesty committed Jul 23, 2024
1 parent c604a85 commit 8319b38
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mirrord/layer/src/exec_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ pub(crate) mod hooks;
pub(crate) struct Argv(Vec<CString>);

impl Argv {
/// Turns this list of [`CString`] into a C list of pointers (null-terminated).
///
/// We leak the [`CString`]s, so that they may live in C-land.
pub(crate) fn leak(self) -> *const *const c_char {
// Leaks the strings.
let mut list = self
.0
.into_iter()
.map(|value| value.into_raw().cast_const())
.collect::<Vec<_>>();

// Null-terminated.
list.push(ptr::null());

// Leaks the list itself.
list.into_raw_parts().0.cast_const()
}

/// Convenience to [`Vec::push`] a new [`CString`].
pub(crate) fn push(&mut self, item: CString) {
self.0.push(item);
}
Expand Down

0 comments on commit 8319b38

Please sign in to comment.