[PATCH 2 of 6 V2] rust: iterator bindings to C code
Yuya Nishihara
yuya at tcha.org
Fri Oct 12 01:04:33 EDT 2018
On Tue, 09 Oct 2018 17:22:46 +0200, Georges Racinet wrote:
> # HG changeset patch
> # User Georges Racinet <gracinet at anybox.fr>
> # Date 1538059896 -7200
> # Thu Sep 27 16:51:36 2018 +0200
> # Node ID 81b8781de6fad514634713fa2cb9f10c320d1af3
> # Parent e466b892b487a2f258fe2000c76a9e916c7344d8
> # EXP-Topic rustancestors-rfc
> rust: iterator bindings to C code
(not including the concerns I raised for the previous series.)
> +/// Wrapping of AncestorsIterator<Index> constructor, for C callers.
> +///
> +/// Besides `initrevs`, `stoprev` and `inclusive`, that are converted
> +/// we receive the index and the parents function as pointers
> +#[no_mangle]
> +pub extern "C" fn rustlazyancestors_init(
> + index: IndexPtr,
> + parents: IndexParentsFn,
> + initrevslen: usize,
> + initrevs: *mut c_long,
> + stoprev: c_long,
> + inclusive: c_long,
The caller appears to pass in "inclusive" as int.
> +/// Testable (for any Graph) version of rustlazyancestors_init
> +#[inline]
> +fn raw_init<G: Graph>(
> + graph: G,
> + initrevslen: usize,
> + initrevs: *mut c_long,
> + stoprev: c_long,
> + inclusive: c_long,
> +) -> *mut AncestorsIterator<G> {
> +
> + let inclb = match inclusive {
> + 0 => false,
> + 1 => true,
> + _ => {
> + return null_mut();
> + }
> + };
> +
> + let slice = unsafe { slice::from_raw_parts(initrevs, initrevslen) };
Nit: we might want to flag this function as unsafe as the caller has to be
careful, but I'm not sure if that's common.
More information about the Mercurial-devel
mailing list