[PATCH 2 of 5 RFC] rust: iterator bindings to C code

Georges Racinet georges.racinet at octobus.net
Wed Jan 16 05:13:00 EST 2019


Hi Augie,

On 10/1/18 5:02 PM, Augie Fackler wrote:
> On Fri, Sep 28, 2018 at 03:31:09PM +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 de88c09512565ed1c12e2ff9159e06ed8d762d15
>> # Parent  d8c9571755a64e1fc3429587dfd3949b9862eceb
>> # EXP-Topic rustancestors-rfc
>> rust: iterator bindings to C code
>>
>> In this changeset, still made of Rust code only,
>> we expose the Rust iterator for instantiation and
>> consumption from C code.
>>
>> The idea is that both the index and index_get_parents()
>> will be passed from the C extension, hence avoiding a hard
>> link dependency to parsers.so, so that the crate can
>> still be built and tested independently.
>>
>> On the other hand, parsers.so will use the symbols
>> defined in this changeset.
>>
>> diff -r d8c9571755a6 -r de88c0951256 mercurial/rust/Cargo.lock
>> --- a/mercurial/rust/Cargo.lock	Thu Sep 27 17:03:16 2018 +0200
>> +++ b/mercurial/rust/Cargo.lock	Thu Sep 27 16:51:36 2018 +0200
>> @@ -1,4 +1,14 @@
>>  [[package]]
>>  name = "hgancestors"
>>  version = "0.1.0"
>> +dependencies = [
>> + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
>> +]
>>
>> +[[package]]
>> +name = "libc"
>> +version = "0.2.43"
>> +source = "registry+https://github.com/rust-lang/crates.io-index"
>> +
>> +[metadata]
>> +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
>> diff -r d8c9571755a6 -r de88c0951256 mercurial/rust/Cargo.toml
>> --- a/mercurial/rust/Cargo.toml	Thu Sep 27 17:03:16 2018 +0200
>> +++ b/mercurial/rust/Cargo.toml	Thu Sep 27 16:51:36 2018 +0200
>> @@ -2,3 +2,9 @@
>>  name = "hgancestors"
>>  version = "0.1.0"
>>  authors = ["Georges Racinet <gracinet at anybox.fr>"]
>> +
>> +[dependencies]
>> +libc = "*"
>> +
>> +[lib]
>> +crate-type = ["dylib"]
>> diff -r d8c9571755a6 -r de88c0951256 mercurial/rust/src/cpython.rs
>> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
>> +++ b/mercurial/rust/src/cpython.rs	Thu Sep 27 16:51:36 2018 +0200
>> @@ -0,0 +1,170 @@
>> +// Copyright 2018 Georges Racinet <gracinet at anybox.fr>
>> +//
>> +// This software may be used and distributed according to the terms of the
>> +// GNU General Public License version 2 or any later version.
>> +
>> +//! Bindings for CPython extension code
> This looks like you're using cffi and not cpython extension logic? I
> don't see anything python-specific in here, so maybe this is misnamed?
This patch is outdated, and the corresponding code has been moved during
the October sprint in its own crate, rust/hg-direct-ffi, before Yuya
queued it.
>
> If I've misread this, why this route rather than using the cpython
> crate, so that the `unsafe` code is consolidated into one package?

This is indeed the way forward that's been adopted since then (see
rust/hg-cpython). I believe there was a rationale for this choice in one
of the changesets of the series. The TL;DR would be that it wasn't clear
at that time how Rust code could call index_get_parents() from parsers.c
[1] and that it could be done without choosing between the three options
presented in the Oxidation wiki page (namely rust-cpython, pyo3 and
cffi), something I wasn't at ease with before meeting other developers IRL.

Now it is expected that hg-direct-ffi will die in some not-too-far future.

Hope this helps,

[1] now it is, this is what PyCapsule is meant for, but I discovered it
later, also during the October sprint. As a side note, I have a
currently a PR about it in rust-cpython which will reduce the amount of
unsafe code in hg-cpython if I can make it land.

-- 
Georges Racinet
https://octobus.net
GPG: BF5456F4DC625443849B6E58EE20CA44EF691D39, sur serveurs publics


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20190116/95d76a23/attachment.sig>


More information about the Mercurial-devel mailing list