diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index f6e9c3201c..c6ac07fc8d 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -265,9 +265,9 @@ pub struct git_clone_options { pub bare: c_int, pub local: git_clone_local_t, pub checkout_branch: *const c_char, - pub repository_cb: Option, + pub repository_cb: git_repository_create_cb, pub repository_cb_payload: *mut c_void, - pub remote_cb: Option, + pub remote_cb: git_remote_create_cb, pub remote_cb_payload: *mut c_void, } @@ -289,9 +289,9 @@ pub struct git_checkout_options { pub file_mode: c_uint, pub file_open_flags: c_int, pub notify_flags: c_uint, - pub notify_cb: Option, + pub notify_cb: git_checkout_notify_cb, pub notify_payload: *mut c_void, - pub progress_cb: Option, + pub progress_cb: git_checkout_progress_cb, pub progress_payload: *mut c_void, pub paths: git_strarray, pub baseline: *mut git_tree, @@ -300,21 +300,25 @@ pub struct git_checkout_options { pub ancestor_label: *const c_char, pub our_label: *const c_char, pub their_label: *const c_char, - pub perfdata_cb: Option, + pub perfdata_cb: git_checkout_perfdata_cb, pub perfdata_payload: *mut c_void, } -pub type git_checkout_notify_cb = extern "C" fn( - git_checkout_notify_t, - *const c_char, - *const git_diff_file, - *const git_diff_file, - *const git_diff_file, - *mut c_void, -) -> c_int; -pub type git_checkout_progress_cb = extern "C" fn(*const c_char, size_t, size_t, *mut c_void); +pub type git_checkout_notify_cb = Option< + extern "C" fn( + git_checkout_notify_t, + *const c_char, + *const git_diff_file, + *const git_diff_file, + *const git_diff_file, + *mut c_void, + ) -> c_int, +>; +pub type git_checkout_progress_cb = + Option; -pub type git_checkout_perfdata_cb = extern "C" fn(*const git_checkout_perfdata, *mut c_void); +pub type git_checkout_perfdata_cb = + Option; #[repr(C)] pub struct git_checkout_perfdata { @@ -335,7 +339,8 @@ pub struct git_indexer_progress { pub received_bytes: size_t, } -pub type git_indexer_progress_cb = extern "C" fn(*const git_indexer_progress, *mut c_void) -> c_int; +pub type git_indexer_progress_cb = + Option c_int>; #[deprecated( since = "0.10.0", @@ -346,20 +351,20 @@ pub type git_transfer_progress = git_indexer_progress; #[repr(C)] pub struct git_remote_callbacks { pub version: c_uint, - pub sideband_progress: Option, + pub sideband_progress: git_transport_message_cb, pub completion: Option c_int>, - pub credentials: Option, - pub certificate_check: Option, - pub transfer_progress: Option, + pub credentials: git_cred_acquire_cb, + pub certificate_check: git_transport_certificate_check_cb, + pub transfer_progress: git_indexer_progress_cb, pub update_tips: Option c_int>, - pub pack_progress: Option, - pub push_transfer_progress: Option, - pub push_update_reference: Option, - pub push_negotiation: Option, - pub transport: Option, + pub pack_progress: git_packbuilder_progress, + pub push_transfer_progress: git_push_transfer_progress, + pub push_update_reference: git_push_update_reference_cb, + pub push_negotiation: git_push_negotiation, + pub transport: git_transport_cb, pub payload: *mut c_void, - pub resolve_url: Option, + pub resolve_url: git_url_resolve_cb, } #[repr(C)] @@ -398,23 +403,26 @@ git_enum! { } } -pub type git_transport_message_cb = extern "C" fn(*const c_char, c_int, *mut c_void) -> c_int; -pub type git_cred_acquire_cb = - extern "C" fn(*mut *mut git_cred, *const c_char, *const c_char, c_uint, *mut c_void) -> c_int; +pub type git_transport_message_cb = + Option c_int>; +pub type git_cred_acquire_cb = Option< + extern "C" fn(*mut *mut git_cred, *const c_char, *const c_char, c_uint, *mut c_void) -> c_int, +>; pub type git_transfer_progress_cb = - extern "C" fn(*const git_indexer_progress, *mut c_void) -> c_int; + Option c_int>; pub type git_packbuilder_progress = - extern "C" fn(git_packbuilder_stage_t, c_uint, c_uint, *mut c_void) -> c_int; -pub type git_push_transfer_progress = extern "C" fn(c_uint, c_uint, size_t, *mut c_void) -> c_int; + Option c_int>; +pub type git_push_transfer_progress = + Option c_int>; pub type git_transport_certificate_check_cb = - extern "C" fn(*mut git_cert, c_int, *const c_char, *mut c_void) -> c_int; + Option c_int>; pub type git_push_negotiation = - extern "C" fn(*mut *const git_push_update, size_t, *mut c_void) -> c_int; + Option c_int>; pub type git_push_update_reference_cb = - extern "C" fn(*const c_char, *const c_char, *mut c_void) -> c_int; + Option c_int>; pub type git_url_resolve_cb = - extern "C" fn(*mut git_buf, *const c_char, c_int, *mut c_void) -> c_int; + Option c_int>; #[repr(C)] pub struct git_push_update { @@ -482,14 +490,16 @@ pub struct git_diff_file { } pub type git_repository_create_cb = - extern "C" fn(*mut *mut git_repository, *const c_char, c_int, *mut c_void) -> c_int; -pub type git_remote_create_cb = extern "C" fn( - *mut *mut git_remote, - *mut git_repository, - *const c_char, - *const c_char, - *mut c_void, -) -> c_int; + Option c_int>; +pub type git_remote_create_cb = Option< + extern "C" fn( + *mut *mut git_remote, + *mut git_repository, + *const c_char, + *const c_char, + *mut c_void, + ) -> c_int, +>; git_enum! { pub enum git_checkout_notify_t { @@ -673,10 +683,11 @@ git_enum! { } pub type git_treewalk_cb = - extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; -pub type git_treebuilder_filter_cb = extern "C" fn(*const git_tree_entry, *mut c_void) -> c_int; + Option c_int>; +pub type git_treebuilder_filter_cb = + Option c_int>; -pub type git_revwalk_hide_cb = extern "C" fn(*const git_oid, *mut c_void) -> c_int; +pub type git_revwalk_hide_cb = Option c_int>; #[repr(C)] #[derive(Copy, Clone)] @@ -729,7 +740,7 @@ pub struct git_blame_hunk { } pub type git_index_matched_path_cb = - extern "C" fn(*const c_char, *const c_char, *mut c_void) -> c_int; + Option c_int>; git_enum! { pub enum git_index_entry_extended_flag_t { @@ -781,7 +792,7 @@ pub struct git_config_entry { pub value: *const c_char, pub include_depth: c_uint, pub level: git_config_level_t, - pub free: extern "C" fn(*mut git_config_entry), + pub free: Option, pub payload: *mut c_void, } @@ -818,7 +829,8 @@ git_enum! { } } -pub type git_submodule_cb = extern "C" fn(*mut git_submodule, *const c_char, *mut c_void) -> c_int; +pub type git_submodule_cb = + Option c_int>; #[repr(C)] pub struct git_submodule_update_options { @@ -830,9 +842,9 @@ pub struct git_submodule_update_options { #[repr(C)] pub struct git_writestream { - pub write: extern "C" fn(*mut git_writestream, *const c_char, size_t) -> c_int, - pub close: extern "C" fn(*mut git_writestream) -> c_int, - pub free: extern "C" fn(*mut git_writestream), + pub write: Option c_int>, + pub close: Option c_int>, + pub free: Option, } git_enum! { @@ -853,7 +865,7 @@ pub const GIT_ATTR_CHECK_INCLUDE_HEAD: u32 = 1 << 3; #[repr(C)] pub struct git_cred { pub credtype: git_credtype_t, - pub free: extern "C" fn(*mut git_cred), + pub free: Option, } git_enum! { @@ -868,25 +880,29 @@ git_enum! { } } -pub type git_cred_ssh_interactive_callback = extern "C" fn( - name: *const c_char, - name_len: c_int, - instruction: *const c_char, - instruction_len: c_int, - num_prompts: c_int, - prompts: *const LIBSSH2_USERAUTH_KBDINT_PROMPT, - responses: *mut LIBSSH2_USERAUTH_KBDINT_RESPONSE, - abstrakt: *mut *mut c_void, -); - -pub type git_cred_sign_callback = extern "C" fn( - session: *mut LIBSSH2_SESSION, - sig: *mut *mut c_uchar, - sig_len: *mut size_t, - data: *const c_uchar, - data_len: size_t, - abstrakt: *mut *mut c_void, -); +pub type git_cred_ssh_interactive_callback = Option< + extern "C" fn( + name: *const c_char, + name_len: c_int, + instruction: *const c_char, + instruction_len: c_int, + num_prompts: c_int, + prompts: *const LIBSSH2_USERAUTH_KBDINT_PROMPT, + responses: *mut LIBSSH2_USERAUTH_KBDINT_RESPONSE, + abstrakt: *mut *mut c_void, + ), +>; + +pub type git_cred_sign_callback = Option< + extern "C" fn( + session: *mut LIBSSH2_SESSION, + sig: *mut *mut c_uchar, + sig_len: *mut size_t, + data: *const c_uchar, + data_len: size_t, + abstrakt: *mut *mut c_void, + ), +>; pub enum LIBSSH2_SESSION {} pub enum LIBSSH2_USERAUTH_KBDINT_PROMPT {} @@ -902,7 +918,7 @@ pub struct git_push_options { } pub type git_tag_foreach_cb = - extern "C" fn(name: *const c_char, oid: *mut git_oid, payload: *mut c_void) -> c_int; + Option c_int>; git_enum! { pub enum git_index_add_option_t { @@ -1005,17 +1021,19 @@ git_enum! { } } -pub type git_diff_file_cb = extern "C" fn(*const git_diff_delta, f32, *mut c_void) -> c_int; +pub type git_diff_file_cb = Option c_int>; pub type git_diff_hunk_cb = - extern "C" fn(*const git_diff_delta, *const git_diff_hunk, *mut c_void) -> c_int; -pub type git_diff_line_cb = extern "C" fn( - *const git_diff_delta, - *const git_diff_hunk, - *const git_diff_line, - *mut c_void, -) -> c_int; + Option c_int>; +pub type git_diff_line_cb = Option< + extern "C" fn( + *const git_diff_delta, + *const git_diff_hunk, + *const git_diff_line, + *mut c_void, + ) -> c_int, +>; pub type git_diff_binary_cb = - extern "C" fn(*const git_diff_delta, *const git_diff_binary, *mut c_void) -> c_int; + Option c_int>; #[repr(C)] pub struct git_diff_hunk { @@ -1058,8 +1076,8 @@ pub struct git_diff_options { pub flags: u32, pub ignore_submodules: git_submodule_ignore_t, pub pathspec: git_strarray, - pub notify_cb: Option, - pub progress_cb: Option, + pub notify_cb: git_diff_notify_cb, + pub progress_cb: git_diff_progress_cb, pub payload: *mut c_void, pub context_lines: u32, pub interhunk_lines: u32, @@ -1090,11 +1108,12 @@ git_enum! { } } -pub type git_diff_notify_cb = - extern "C" fn(*const git_diff, *const git_diff_delta, *const c_char, *mut c_void) -> c_int; +pub type git_diff_notify_cb = Option< + extern "C" fn(*const git_diff, *const git_diff_delta, *const c_char, *mut c_void) -> c_int, +>; pub type git_diff_progress_cb = - extern "C" fn(*const git_diff, *const c_char, *const c_char, *mut c_void) -> c_int; + Option c_int>; pub type git_diff_option_t = i32; pub const GIT_DIFF_NORMAL: git_diff_option_t = 0; @@ -1141,17 +1160,21 @@ pub struct git_diff_find_options { #[repr(C)] pub struct git_diff_similarity_metric { - pub file_signature: + pub file_signature: Option< extern "C" fn(*mut *mut c_void, *const git_diff_file, *const c_char, *mut c_void) -> c_int, - pub buffer_signature: extern "C" fn( - *mut *mut c_void, - *const git_diff_file, - *const c_char, - size_t, - *mut c_void, - ) -> c_int, - pub free_signature: extern "C" fn(*mut c_void, *mut c_void), - pub similarity: extern "C" fn(*mut c_int, *mut c_void, *mut c_void, *mut c_void) -> c_int, + >, + pub buffer_signature: Option< + extern "C" fn( + *mut *mut c_void, + *const git_diff_file, + *const c_char, + size_t, + *mut c_void, + ) -> c_int, + >, + pub free_signature: Option, + pub similarity: + Option c_int>, pub payload: *mut c_void, } @@ -1260,11 +1283,13 @@ git_enum! { } } -pub type git_transport_cb = extern "C" fn( - out: *mut *mut git_transport, - owner: *mut git_remote, - param: *mut c_void, -) -> c_int; +pub type git_transport_cb = Option< + extern "C" fn( + out: *mut *mut git_transport, + owner: *mut git_remote, + param: *mut c_void, + ) -> c_int, +>; #[repr(C)] pub struct git_transport { @@ -1501,8 +1526,8 @@ pub struct git_proxy_options { pub version: c_uint, pub kind: git_proxy_t, pub url: *const c_char, - pub credentials: Option, - pub certificate_check: Option, + pub credentials: git_cred_acquire_cb, + pub certificate_check: git_transport_certificate_check_cb, pub payload: *mut c_void, } @@ -1526,34 +1551,40 @@ git_enum! { #[repr(C)] pub struct git_smart_subtransport_stream { pub subtransport: *mut git_smart_subtransport, - pub read: extern "C" fn( - *mut git_smart_subtransport_stream, - *mut c_char, - size_t, - *mut size_t, - ) -> c_int, - pub write: extern "C" fn(*mut git_smart_subtransport_stream, *const c_char, size_t) -> c_int, - pub free: extern "C" fn(*mut git_smart_subtransport_stream), + pub read: Option< + extern "C" fn( + *mut git_smart_subtransport_stream, + *mut c_char, + size_t, + *mut size_t, + ) -> c_int, + >, + pub write: + Option c_int>, + pub free: Option, } #[repr(C)] pub struct git_smart_subtransport { - pub action: extern "C" fn( - *mut *mut git_smart_subtransport_stream, - *mut git_smart_subtransport, - *const c_char, - git_smart_service_t, - ) -> c_int, - pub close: extern "C" fn(*mut git_smart_subtransport) -> c_int, - pub free: extern "C" fn(*mut git_smart_subtransport), + pub action: Option< + extern "C" fn( + *mut *mut git_smart_subtransport_stream, + *mut git_smart_subtransport, + *const c_char, + git_smart_service_t, + ) -> c_int, + >, + pub close: Option c_int>, + pub free: Option, } -pub type git_smart_subtransport_cb = - extern "C" fn(*mut *mut git_smart_subtransport, *mut git_transport, *mut c_void) -> c_int; +pub type git_smart_subtransport_cb = Option< + extern "C" fn(*mut *mut git_smart_subtransport, *mut git_transport, *mut c_void) -> c_int, +>; #[repr(C)] pub struct git_smart_subtransport_definition { - pub callback: Option, + pub callback: git_smart_subtransport_cb, pub rpc: c_uint, pub param: *mut c_void, } @@ -1625,30 +1656,36 @@ pub struct git_stash_apply_options { pub version: c_uint, pub flags: u32, pub checkout_options: git_checkout_options, - pub progress_cb: Option, + pub progress_cb: git_stash_apply_progress_cb, pub progress_payload: *mut c_void, } pub type git_stash_apply_progress_cb = - extern "C" fn(progress: git_stash_apply_progress_t, payload: *mut c_void) -> c_int; + Option c_int>; -pub type git_stash_cb = extern "C" fn( - index: size_t, - message: *const c_char, - stash_id: *const git_oid, - payload: *mut c_void, -) -> c_int; +pub type git_stash_cb = Option< + extern "C" fn( + index: size_t, + message: *const c_char, + stash_id: *const git_oid, + payload: *mut c_void, + ) -> c_int, +>; -pub type git_packbuilder_foreach_cb = extern "C" fn(*const c_void, size_t, *mut c_void) -> c_int; +pub type git_packbuilder_foreach_cb = + Option c_int>; -pub type git_odb_foreach_cb = extern "C" fn(id: *const git_oid, payload: *mut c_void) -> c_int; +pub type git_odb_foreach_cb = + Option c_int>; -pub type git_commit_signing_cb = extern "C" fn( - signature: *mut git_buf, - signature_field: *mut git_buf, - commit_content: *const c_char, - payload: *mut c_void, -) -> c_int; +pub type git_commit_signing_cb = Option< + extern "C" fn( + signature: *mut git_buf, + signature_field: *mut git_buf, + commit_content: *const c_char, + payload: *mut c_void, + ) -> c_int, +>; pub const GIT_REBASE_NO_OPERATION: usize = usize::max_value(); @@ -1660,7 +1697,7 @@ pub struct git_rebase_options { pub rewrite_notes_ref: *const c_char, pub merge_options: git_merge_options, pub checkout_options: git_checkout_options, - pub signing_cb: Option, + pub signing_cb: git_commit_signing_cb, pub payload: *mut c_void, } @@ -2509,7 +2546,7 @@ extern "C" { index: *mut git_index, pathspec: *const git_strarray, flags: c_uint, - callback: Option, + callback: git_index_matched_path_cb, payload: *mut c_void, ) -> c_int; pub fn git_index_add_bypath(index: *mut git_index, path: *const c_char) -> c_int; @@ -2566,7 +2603,7 @@ extern "C" { pub fn git_index_remove_all( index: *mut git_index, pathspec: *const git_strarray, - callback: Option, + callback: git_index_matched_path_cb, payload: *mut c_void, ) -> c_int; pub fn git_index_remove_bypath(index: *mut git_index, path: *const c_char) -> c_int; @@ -2578,7 +2615,7 @@ extern "C" { pub fn git_index_update_all( index: *mut git_index, pathspec: *const git_strarray, - callback: Option, + callback: git_index_matched_path_cb, payload: *mut c_void, ) -> c_int; pub fn git_index_write(index: *mut git_index) -> c_int; @@ -3081,9 +3118,9 @@ extern "C" { pub fn git_diff_foreach( diff: *mut git_diff, file_cb: git_diff_file_cb, - binary_cb: Option, - hunk_cb: Option, - line_cb: Option, + binary_cb: git_diff_binary_cb, + hunk_cb: git_diff_hunk_cb, + line_cb: git_diff_line_cb, payload: *mut c_void, ) -> c_int; pub fn git_diff_free(diff: *mut git_diff); @@ -3325,7 +3362,7 @@ extern "C" { pb: *mut git_packbuilder, path: *const c_char, mode: c_uint, - progress_cb: Option, + progress_cb: git_indexer_progress_cb, progress_cb_payload: *mut c_void, ) -> c_int; pub fn git_packbuilder_hash(pb: *mut git_packbuilder) -> *const git_oid; @@ -3338,7 +3375,7 @@ extern "C" { pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> size_t; pub fn git_packbuilder_set_callbacks( pb: *mut git_packbuilder, - progress_cb: Option, + progress_cb: git_packbuilder_progress, progress_cb_payload: *mut c_void, ) -> c_int; pub fn git_packbuilder_free(pb: *mut git_packbuilder); diff --git a/src/blob.rs b/src/blob.rs index 93159f68e3..ae7505a69e 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -124,7 +124,11 @@ impl<'repo> Drop for BlobWriter<'repo> { fn drop(&mut self) { // We need cleanup in case the stream has not been committed if self.need_cleanup { - unsafe { ((*self.raw).free)(self.raw) } + unsafe { + if let Some(f) = (*self.raw).free { + f(self.raw) + } + } } } } @@ -132,11 +136,15 @@ impl<'repo> Drop for BlobWriter<'repo> { impl<'repo> io::Write for BlobWriter<'repo> { fn write(&mut self, buf: &[u8]) -> io::Result { unsafe { - let res = ((*self.raw).write)(self.raw, buf.as_ptr() as *const _, buf.len()); - if res < 0 { - Err(io::Error::new(io::ErrorKind::Other, "Write error")) + if let Some(f) = (*self.raw).write { + let res = f(self.raw, buf.as_ptr() as *const _, buf.len()); + if res < 0 { + Err(io::Error::new(io::ErrorKind::Other, "Write error")) + } else { + Ok(buf.len()) + } } else { - Ok(buf.len()) + Err(io::Error::new(io::ErrorKind::Other, "no write callback")) } } } diff --git a/src/build.rs b/src/build.rs index 62f42f752e..e1b75bd43b 100644 --- a/src/build.rs +++ b/src/build.rs @@ -589,13 +589,11 @@ impl<'cb> CheckoutBuilder<'cb> { opts.their_label = c.as_ptr(); } if self.progress.is_some() { - let f: raw::git_checkout_progress_cb = progress_cb; - opts.progress_cb = Some(f); + opts.progress_cb = Some(progress_cb); opts.progress_payload = self as *mut _ as *mut _; } if self.notify.is_some() { - let f: raw::git_checkout_notify_cb = notify_cb; - opts.notify_cb = Some(f); + opts.notify_cb = Some(notify_cb); opts.notify_payload = self as *mut _ as *mut _; opts.notify_flags = self.notify_flags.bits() as c_uint; } diff --git a/src/cred.rs b/src/cred.rs index 3bc443746b..c3a49939a6 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -179,7 +179,11 @@ impl Binding for Cred { impl Drop for Cred { fn drop(&mut self) { if !self.raw.is_null() { - unsafe { ((*self.raw).free)(self.raw) } + unsafe { + if let Some(f) = (*self.raw).free { + f(self.raw) + } + } } } } diff --git a/src/diff.rs b/src/diff.rs index 4e959ac27c..4cedb77d2d 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -164,13 +164,9 @@ impl<'repo> Diff<'repo> { { let mut cb: &mut PrintCb<'_> = &mut cb; let ptr = &mut cb as *mut _; + let print: raw::git_diff_line_cb = Some(print_cb); unsafe { - try_call!(raw::git_diff_print( - self.raw, - format, - print_cb, - ptr as *mut _ - )); + try_call!(raw::git_diff_print(self.raw, format, print, ptr as *mut _)); Ok(()) } } @@ -194,24 +190,25 @@ impl<'repo> Diff<'repo> { }; let ptr = &mut cbs as *mut _; unsafe { - let binary_cb_c = if cbs.binary.is_some() { - Some(binary_cb_c as raw::git_diff_binary_cb) + let binary_cb_c: raw::git_diff_binary_cb = if cbs.binary.is_some() { + Some(binary_cb_c) } else { None }; - let hunk_cb_c = if cbs.hunk.is_some() { - Some(hunk_cb_c as raw::git_diff_hunk_cb) + let hunk_cb_c: raw::git_diff_hunk_cb = if cbs.hunk.is_some() { + Some(hunk_cb_c) } else { None }; - let line_cb_c = if cbs.line.is_some() { - Some(line_cb_c as raw::git_diff_line_cb) + let line_cb_c: raw::git_diff_line_cb = if cbs.line.is_some() { + Some(line_cb_c) } else { None }; + let file_cb: raw::git_diff_file_cb = Some(file_cb_c); try_call!(raw::git_diff_foreach( self.raw, - file_cb_c, + file_cb, binary_cb_c, hunk_cb_c, line_cb_c, diff --git a/src/index.rs b/src/index.rs index 4d537b64a6..797e6d8815 100644 --- a/src/index.rs +++ b/src/index.rs @@ -295,7 +295,7 @@ impl Index { let ptr = cb.as_mut(); let callback = ptr .as_ref() - .map(|_| index_matched_path_cb as raw::git_index_matched_path_cb); + .map(|_| index_matched_path_cb as extern "C" fn(_, _, _) -> _); unsafe { try_call!(raw::git_index_add_all( self.raw, @@ -473,7 +473,7 @@ impl Index { let ptr = cb.as_mut(); let callback = ptr .as_ref() - .map(|_| index_matched_path_cb as raw::git_index_matched_path_cb); + .map(|_| index_matched_path_cb as extern "C" fn(_, _, _) -> _); unsafe { try_call!(raw::git_index_remove_all( self.raw, @@ -511,7 +511,7 @@ impl Index { let ptr = cb.as_mut(); let callback = ptr .as_ref() - .map(|_| index_matched_path_cb as raw::git_index_matched_path_cb); + .map(|_| index_matched_path_cb as extern "C" fn(_, _, _) -> _); unsafe { try_call!(raw::git_index_update_all( self.raw, diff --git a/src/odb.rs b/src/odb.rs index a6b1bc5397..9ee034ac21 100644 --- a/src/odb.rs +++ b/src/odb.rs @@ -98,9 +98,10 @@ impl<'repo> Odb<'repo> { let mut data = ForeachCbData { callback: &mut callback, }; + let cb: raw::git_odb_foreach_cb = Some(foreach_cb); try_call!(raw::git_odb_foreach( self.raw(), - foreach_cb, + cb, &mut data as *mut _ as *mut _ )); Ok(()) @@ -155,7 +156,7 @@ impl<'repo> Odb<'repo> { pub fn packwriter(&self) -> Result, Error> { let mut out = ptr::null_mut(); let progress = MaybeUninit::uninit(); - let progress_cb = write_pack_progress_cb; + let progress_cb: raw::git_indexer_progress_cb = Some(write_pack_progress_cb); let progress_payload = Box::new(OdbPackwriterCb { cb: None }); let progress_payload_ptr = Box::into_raw(progress_payload); diff --git a/src/packbuilder.rs b/src/packbuilder.rs index 6769d35114..06bf41dc7a 100644 --- a/src/packbuilder.rs +++ b/src/packbuilder.rs @@ -89,10 +89,11 @@ impl<'repo> PackBuilder<'repo> { { let mut cb = &mut cb as &mut ForEachCb<'_>; let ptr = &mut cb as *mut _; + let foreach: raw::git_packbuilder_foreach_cb = Some(foreach_c); unsafe { try_call!(raw::git_packbuilder_foreach( self.raw, - foreach_c, + foreach, ptr as *mut _ )); } @@ -112,7 +113,7 @@ impl<'repo> PackBuilder<'repo> { { let mut progress = Box::new(Box::new(progress) as Box>); let ptr = &mut *progress as *mut _; - let progress_c = Some(progress_c as raw::git_packbuilder_progress); + let progress_c: raw::git_packbuilder_progress = Some(progress_c); unsafe { try_call!(raw::git_packbuilder_set_callbacks( self.raw, diff --git a/src/patch.rs b/src/patch.rs index 370782b281..2ff112b2c3 100644 --- a/src/patch.rs +++ b/src/patch.rs @@ -206,7 +206,8 @@ impl<'buffers> Patch<'buffers> { pub fn print(&mut self, mut line_cb: &mut LineCb<'_>) -> Result<(), Error> { let ptr = &mut line_cb as *mut _ as *mut c_void; unsafe { - try_call!(raw::git_patch_print(self.raw, print_cb, ptr)); + let cb: raw::git_diff_line_cb = Some(print_cb); + try_call!(raw::git_patch_print(self.raw, cb, ptr)); Ok(()) } } diff --git a/src/remote_callbacks.rs b/src/remote_callbacks.rs index 619cef610c..ae741be399 100644 --- a/src/remote_callbacks.rs +++ b/src/remote_callbacks.rs @@ -174,24 +174,19 @@ impl<'a> Binding for RemoteCallbacks<'a> { 0 ); if self.progress.is_some() { - let f: raw::git_indexer_progress_cb = transfer_progress_cb; - callbacks.transfer_progress = Some(f); + callbacks.transfer_progress = Some(transfer_progress_cb); } if self.credentials.is_some() { - let f: raw::git_cred_acquire_cb = credentials_cb; - callbacks.credentials = Some(f); + callbacks.credentials = Some(credentials_cb); } if self.sideband_progress.is_some() { - let f: raw::git_transport_message_cb = sideband_progress_cb; - callbacks.sideband_progress = Some(f); + callbacks.sideband_progress = Some(sideband_progress_cb); } if self.certificate_check.is_some() { - let f: raw::git_transport_certificate_check_cb = certificate_check_cb; - callbacks.certificate_check = Some(f); + callbacks.certificate_check = Some(certificate_check_cb); } if self.push_update_reference.is_some() { - let f: extern "C" fn(_, _, _) -> c_int = push_update_reference_cb; - callbacks.push_update_reference = Some(f); + callbacks.push_update_reference = Some(push_update_reference_cb); } if self.update_tips.is_some() { let f: extern "C" fn( diff --git a/src/repo.rs b/src/repo.rs index 89a40b53a1..7f3bb4c98e 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -778,9 +778,10 @@ impl Repository { repo: self, ret: &mut ret, }; + let cb: raw::git_submodule_cb = Some(append); try_call!(raw::git_submodule_foreach( self.raw, - append, + cb, &mut data as *mut _ as *mut c_void )); } @@ -2426,9 +2427,10 @@ impl Repository { let mut data = StashCbData { callback: &mut callback, }; + let cb: raw::git_stash_cb = Some(stash_cb); try_call!(raw::git_stash_foreach( self.raw(), - stash_cb, + cb, &mut data as *mut _ as *mut _ )); Ok(()) diff --git a/src/transport.rs b/src/transport.rs index e7b398ce6b..c82eb1b27c 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -113,11 +113,8 @@ where }); let prefix = CString::new(prefix)?; let datap = (&mut *data) as *mut TransportData as *mut c_void; - try_call!(raw::git_transport_register( - prefix, - transport_factory, - datap - )); + let factory: raw::git_transport_cb = Some(transport_factory); + try_call!(raw::git_transport_register(prefix, factory, datap)); mem::forget(data); Ok(()) } @@ -141,9 +138,9 @@ impl Transport { let mut raw = Box::new(RawSmartSubtransport { raw: raw::git_smart_subtransport { - action: subtransport_action, - close: subtransport_close, - free: subtransport_free, + action: Some(subtransport_action), + close: Some(subtransport_close), + free: Some(subtransport_free), }, obj: Box::new(subtransport), }); @@ -257,9 +254,9 @@ extern "C" fn subtransport_action( *stream = mem::transmute(Box::new(RawSmartSubtransportStream { raw: raw::git_smart_subtransport_stream { subtransport: raw_transport, - read: stream_read, - write: stream_write, - free: stream_free, + read: Some(stream_read), + write: Some(stream_write), + free: Some(stream_free), }, obj: obj, })); diff --git a/src/tree.rs b/src/tree.rs index 9fd4e0cee1..436a8f50a2 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -132,7 +132,7 @@ impl<'repo> Tree<'repo> { raw::git_tree_walk( self.raw(), mode.into(), - treewalk_cb::, + Some(treewalk_cb::), &mut data as *mut _ as *mut c_void, ); Ok(()) diff --git a/src/treebuilder.rs b/src/treebuilder.rs index e14d96319b..5d40ea9b39 100644 --- a/src/treebuilder.rs +++ b/src/treebuilder.rs @@ -95,12 +95,9 @@ impl<'repo> TreeBuilder<'repo> { { let mut cb: &mut FilterCb<'_> = &mut filter; let ptr = &mut cb as *mut _; + let cb: raw::git_treebuilder_filter_cb = Some(filter_cb); unsafe { - try_call!(raw::git_treebuilder_filter( - self.raw, - filter_cb, - ptr as *mut _ - )); + try_call!(raw::git_treebuilder_filter(self.raw, cb, ptr as *mut _)); panic::check(); } Ok(())