Skip to content

Commit

Permalink
Merge pull request #989 from ehuss/fix-tree-walk-cb
Browse files Browse the repository at this point in the history
Don't pretend that TreeWalkCbData is transparent.
  • Loading branch information
ehuss authored Sep 18, 2023
2 parents 67fcacc + 6008651 commit a66496a
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit a66496a

Please sign in to comment.