Skip to content

Don't pretend that TreeWalkCbData is transparent. #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ impl<'repo> Tree<'repo> {
C: FnMut(&str, &TreeEntry<'_>) -> T,
T: Into<i32>,
{
#[allow(unused)]
struct TreeWalkCbData<'a, T> {
pub callback: &'a mut TreeWalkCb<'a, T>,
}
unsafe {
let mut data = TreeWalkCbData {
callback: &mut callback,
Expand Down Expand Up @@ -209,6 +205,10 @@ impl<'repo> Tree<'repo> {

type TreeWalkCb<'a, T> = dyn FnMut(&str, &TreeEntry<'_>) -> T + 'a;

struct TreeWalkCbData<'a, T> {
callback: &'a mut TreeWalkCb<'a, T>,
}

extern "C" fn treewalk_cb<T: Into<i32>>(
root: *const c_char,
entry: *const raw::git_tree_entry,
Expand All @@ -220,8 +220,9 @@ extern "C" fn treewalk_cb<T: Into<i32>>(
_ => return -1,
};
let entry = entry_from_raw_const(entry);
let payload = payload as *mut &mut TreeWalkCb<'_, T>;
(*payload)(root, &entry).into()
let payload = &mut *(payload as *mut TreeWalkCbData<'_, T>);
let callback = &mut payload.callback;
callback(root, &entry).into()
}) {
Some(value) => value,
None => -1,
Expand Down