On Thu, Aug 10, 2023 at 11:24:30AM +0000, Tage Johansson wrote: > Add two new fields, cblifetime and cbcount, to the `closure` type > in generator/API.ml*. cblifetime tells if the closure may only be used > for as long as the command is in flight or if the closure may be used > until the handle is destructed. cbcount tells whether the closure may > be called many times or just once. > > This information is needed in the Rust bindings for: > a) Knowing if the closure trait should be FnMut or FnOnce > (see <https://doc.rust-lang.org/std/ops/trait.FnOnce.html>). > b) Knowing for what lifetime the closure should be valid. A closure that > may be called after the function invokation has returned must live
invocation > for the `'static` lietime. But static closures are inconveniant for lifetime > the user since they can't effectively borrow any local data. So it is > good if this restriction is relaxed when it is not needed. > --- > generator/API.ml | 20 ++++++++++++++++++++ > generator/API.mli | 17 +++++++++++++++++ > 2 files changed, 37 insertions(+) > > +++ b/generator/API.mli > @@ -94,6 +94,12 @@ and ret = > and closure = { > cbname : string; (** name of callback function *) > cbargs : cbarg list; (** all closures return int for now *) > + (** An upper bound of the lifetime of the closure. Either it will be used > for > + as long as the command is in flight or it may be used until the handle > + is destructed. *) > + cblifetime : cblifetime; > + (** Whether the callback may only be called once or many times. *) > + cbcount : cbcount; > } > and cbarg = > | CBArrayAndLen of arg * string (** array + number of entries *) > @@ -104,6 +110,17 @@ and cbarg = > | CBString of string (** like String *) > | CBUInt of string (** like UInt *) > | CBUInt64 of string (** like UInt64 *) > +and cblifetime = > +| CBCommand (** The closure may only be used until the command is retired. > + (E.G., completion callback or list callback.) *) > +| CBHandle (** The closure might be used until the handle is descructed. > + (E.G., debug callback.) *) > +and cbcount = > +| CBOnce (** The closure will be used 0 or 1 time if the aio_* call returned > an > + error and exactly once if the call succeeded. > + (E.g., completion callback.) *) Rather, the closure will not be used if the aio_* returned error, and used exactly once if the aio_* call succeeded. > +| CBMany (** The closure may be used any number of times. > + (E.g., list callback.) *) > and enum = { > enum_prefix : string; (** prefix of each enum variant *) > enums : (string * int) list (** enum names and their values in C *) > -- > 2.41.0 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://listman.redhat.com/mailman/listinfo/libguestfs > -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs