<div dir="ltr">Dear Pino,<br><br>Thank you for your helpful review. I fixed the patch based on your comments. I’ll send it later.<br><br>> The same also for the various .gitkeep files, as they need to be in the<br>> distribution tarball to ensure the directories exist.<br><br>Is ’src/bin/.gitkeep’ required in EXTRA_DIST? I think because src/bin/<a href="http://bindtests.rs">bindtests.rs</a> is included in EXTRA_DIST,  ’src/bin/.gitkeep’ is not required to make sure the directory exists. Is this idea is correct?<br><br><br>> From what I remember about the Rust naming conventions, maybe the name<br>> should be guestfs-sys?<br><br>From the previous conversation, I thought it was finally concluded that  ‘xxxx-sys’ should be used when the crate had only externs of linked libraries. And, this rust bindings has a little higher abstractions. Therefore, the name of this crate should not be ‘guestfs-sys.’<br><br><br>I also fixed the license of each file. Could you give me some advice if there are some mistakes?<div><br></div><div>Regards,</div><div>Hiroyuki<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2019年7月27日(土) 1:41 Pino Toscano <<a href="mailto:ptoscano@redhat.com" target="_blank">ptoscano@redhat.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Hiroyuki,<br>
<br>
sorry for the late reply.<br>
<br>
Most of the work is definitely nice! There are few notes below,<br>
although they are not big issues.  I will check this patch once more<br>
on monday, especially the rust parts.<br>
<br>
Otherwise, I'd say that we are close to merging this :)<br>
<br>
On Tuesday, 23 July 2019 10:37:17 CEST Hiroyuki Katsura wrote:<br>
> From: Hiroyuki_Katsura <<a href="mailto:hiroyuki.katsura.0513@gmail.com" target="_blank">hiroyuki.katsura.0513@gmail.com</a>><br>
> <br>
> Rust bindings: Add create / close functions<br>
> <br>
> Rust bindings: Add 4 bindings tests<br>
> <br>
> Rust bindings: Add generator of structs<br>
> <br>
> Rust bindings: Add generator of structs for optional arguments<br>
> <br>
> Rust bindings: Add generator of function signatures<br>
> <br>
> Rust bindings: Complete actions<br>
> <br>
> Rust bindings: Fix memory management<br>
> <br>
> Rust bindings: Add bindtests<br>
> <br>
> Rust bindings: Add additional 4 bindings tests<br>
> <br>
> Rust bindings: Format test files<br>
> <br>
> Rust bindings: Incorporate bindings to build system<br>
> ---<br>
<br>
IMHO there should be a commit message saying that this is new binding<br>
for Rust and its name, and what is included (actions & tests, not<br>
events, not examples).<br>
<br>
Also, as we talked about, make sure to fix the copyright to properly<br>
credit yourself.<br>
<br>
>  rust/src/.gitkeep                   |   0<br>
<br>
This .gitkeep file is not needed, as there are other files in src/.<br>
<br>
>  rust/tests/.gitkeep                 |   0<br>
<br>
Ditto.<br>
<br>
> +(* Utilities for Rust *)<br>
> +(* Are there corresponding functions to them? *)<br>
> +(* Should they be placed in <a href="http://utils.ml" rel="noreferrer" target="_blank">utils.ml</a>? *)<br>
<br>
Usually we add generic functions to common places only when we know in<br>
advance that there will be multiple users.  Otherwise, like in this<br>
case, having utilities only where used is perfectly fine.<br>
In any case, if any of these utilities will be needed in more places in<br>
the future, it is easy to do a simple no-op commit to just move some<br>
code.<br>
<br>
> +let rec indent n = match n with<br>
> +  | x when x > 0 -> pr "    "; indent (x - 1)<br>
> +  | _ -> ()<br>
<br>
A small nit here:<br>
<br>
let rec indent = function<br>
  | x when x > 0 -> pr "    "; indent (x - 1)<br>
  | _ -> ()<br>
<br>
> +<br>
> +(* split_on_char exists since OCaml 4.04 *)<br>
> +(* but current requirements: >=4.01 *)<br>
> +let split_on_char c = Str.split (Str.regexp (String.make 1 c))<br>
<br>
The generator uses the internal mlstdutils shared code, see<br>
common/mlstdutils.  One of the things provided are extra functions for<br>
the String module, and one in particular can help here: String.nsplit.<br>
Also...<br>
<br>
> +let snake2caml name =<br>
> +  let l = split_on_char '_' name in<br>
> +  let l = List.map (fun x -> String.capitalize_ascii x) l in<br>
> +  String.concat "" l<br>
<br>
... this can be simplified a bit using String.nsplit, and currying:<br>
<br>
let snake2caml name =<br>
  let l = String.nsplit "_" name in<br>
  let l = List.map String.capitalize_ascii l in<br>
  String.concat "" l<br>
<br>
> +(* because there is a function which contains 'unsafe' field *)<br>
> +let black_list = ["unsafe"]<br>
> +<br>
> +let translate_bad_symbols s =<br>
> +  if List.exists (fun x -> s = x) black_list then<br>
> +    s ^ "_"<br>
> +  else<br>
> +    s<br>
<br>
Hm IMHO the condition in the if sounds like List.mem :) What about:<br>
<br>
  if List.mem s black_list then<br>
<br>
> +      let cname = snake2caml name in<br>
> +      let rec contains_ptr args = match args with<br>
> +        | [] -> false<br>
> +        | OString _ ::_<br>
> +        | OStringList _::_ -> true<br>
> +        | _::xs -> contains_ptr xs<br>
<br>
As above, you can avoid the explicit match on the last parameter using<br>
the function syntax.<br>
<br>
OTOH, I think you can use List.exists here:<br>
<br>
let contains_ptr =<br>
  List.exists (<br>
    function<br>
    | OString _<br>
    | OStringList _ -> true<br>
    | _ -> false<br>
  )<br>
<br>
> diff --git a/rust/<a href="http://Cargo.toml.in" rel="noreferrer" target="_blank">Cargo.toml.in</a> b/rust/<a href="http://Cargo.toml.in" rel="noreferrer" target="_blank">Cargo.toml.in</a><br>
> new file mode 100644<br>
> index 000000000..e25dfe768<br>
> --- /dev/null<br>
> +++ b/rust/<a href="http://Cargo.toml.in" rel="noreferrer" target="_blank">Cargo.toml.in</a><br>
> @@ -0,0 +1,6 @@<br>
> +[package]<br>
> +name = "guestfs"<br>
> +version = "@VERSION@"<br>
> +edition = "2018"<br>
<br>
>From what I remember about the Rust naming conventions, maybe the name<br>
should be guestfs-sys? Martin?<br>
<br>
> +EXTRA_DIST = \<br>
> +     .gitignore \<br>
> +     $(generator_built) \<br>
> +     tests/*.rs \<br>
> +     Cargo.toml \<br>
> +     Cargo.lock \<br>
> +     run-bindtests \<br>
> +     run-tests<br>
<br>
Most probably also src/*.rs, as they are not automake sources (which<br>
are distributed automatically).<br>
<br>
The same also for the various .gitkeep files, as they need to be in the<br>
distribution tarball to ensure the directories exist.<br>
<br>
Also, you need to use TESTS_ENVIRONMENT like done elsewhere, so the<br>
in-built stuff is used when running the tests.<br>
<br>
> diff --git a/rust/run-bindtests b/rust/run-bindtests<br>
> new file mode 100755<br>
> index 000000000..55484a2c7<br>
> --- /dev/null<br>
> +++ b/rust/run-bindtests<br>
> @@ -0,0 +1,23 @@<br>
> +#!/bin/sh -<br>
> +# libguestfs Rust bindings<br>
> +# Copyright (C) 2013 Red Hat Inc.<br>
> +#<br>
> +# This program is free software; you can redistribute it and/or modify<br>
> +# it under the terms of the GNU General Public License as published by<br>
> +# the Free Software Foundation; either version 2 of the License, or<br>
> +# (at your option) any later version.<br>
> +#<br>
> +# This program is distributed in the hope that it will be useful,<br>
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
> +# GNU General Public License for more details.<br>
> +#<br>
> +# You should have received a copy of the GNU General Public License<br>
> +# along with this program; if not, write to the Free Software<br>
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
> +<br>
> +set -e<br>
> +<br>
> +$CARGO run --bin bindtests > bindtests.tmp<br>
<br>
Hmm I don't think $CARGO is exported.  A simple way is to make it<br>
available is to export it as test environment, via TESTS_ENVIRONMENT.<br>
<br>
> diff --git a/rust/src/<a href="http://base.rs" rel="noreferrer" target="_blank">base.rs</a> b/rust/src/<a href="http://base.rs" rel="noreferrer" target="_blank">base.rs</a><br>
> new file mode 100644<br>
> index 000000000..2dfad91a1<br>
> --- /dev/null<br>
> +++ b/rust/src/<a href="http://base.rs" rel="noreferrer" target="_blank">base.rs</a><br>
> @@ -0,0 +1,125 @@<br>
> +/* libguestfs generated file<br>
> + * WARNING: THIS FILE IS GENERATED<br>
> + *          from the code in the generator/ subdirectory.<br>
> + * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.<br>
<br>
Definitely not ;-)<br>
<br>
-- <br>
Pino Toscano</blockquote></div></div></div>