Re: [PATCH V6 3/8] libgpiod: Add rust wrapper crate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28-09-22, 19:54, Bartosz Golaszewski wrote:
> On Wed, Sep 28, 2022 at 5:17 PM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> > Hmm, so what exactly do we want to do here then ?
> >
> > - Don't allow events to be referenced ? i.e. make event_clone() the default
> >   behavior ?
> >
> 
> God no, that would be wasteful.
> 
> > - Don't allow read_edge_event() to be called twice for a buffer ? that will be
> >   inefficient though.
> >
> 
> Not good either.

As I expected for both of them :)

> > - Somehow guarantee that reference to all the events are dropped before issuing
> >   read_edge_event() again, else make it fail ? I am not sure how straight
> >   forward that can be though.
> 
> In C++ the preferred way is to do buffer.get_event(0) which will
> return a constant reference. If you store that reference as const
> edge_event& ev = buffer.get_event(0) and reuse it after rereading into
> that buffer and the program crashes - that's on you. In most cases you
> should just do buffer.get_event(0).line_offset() etc. If you do:
> 
> edge_event event = buffer.get_event(0);
> 
> You'll copy the event and it will survive the overwriting of the buffer.

Right, same happens here.

> I'm a Rust beginner but my understanding is that the whole idea of the
> language design is to *not* allow a situation where the program can
> crash. It should be detected at build-time. We must not rely on
> "contracts" defined by documentation.

If everything was written in Rust, then this problem won't occur for sure. But
in this case part of the code is available via FFI (foreign function interface)
and they guarantees are a bit limited there and depend on what the FFI
guarantees.

> Is there a way to invalidate a reference in Rust? Have a small (cheap)
> object in the buffer which the event references and which would get
> dropped when reading into the buffer?

I am not sure. There are locks, but then they have a cost.

Miguel, any suggestions ?

Bartosz, just as an FYI I am out on vacation until end of next week and won't
have access to a workstation. I can still reply via Gmail (html) from my phone
though.

-- 
viresh



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux