Re: [PATCH V2 2/4] libgpiod: Add rust wrappers

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

 



On 17-12-21, 13:02, Bartosz Golaszewski wrote:
> On Fri, Dec 17, 2021 at 10:54 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> > > I don't know Rust that well to be able to come up with an idea off the
> > > top of my head but I assume inheritance in one way or another exists
> > > in rust? Can you have an EdgeEvent interface implemented by two
> > > specialized structs, one that's stored in the buffer (stores a pointer
> > > to the internal event)
> >
> > This is what my initial patch had, right? It isn't safe. There is no way for
> > libgpiod-rust to guarantee that the users don't access the EdgeEvent after the
> > buffer is freed and this needs to be made safer at libgpiod itself.
> >
> 
> I'm not sure it had the same thing. In libgpiod it's simple a matter
> of definition. The docs state that a pointer retrieved using
> gpiod_edge_event_buffer_get_event() must not be freed while one
> obtained with gpiod_edge_event_copy() does have to be disposed of. In
> C++ it's safe because either you hold a const reference to the object
> stored in the event buffer or you have copied it and now it will
> survive the parent meaning the user can access the event even after
> the buffer was deleted.
> 
> > > and one that stores the copy (and frees it when
> > > it goes out of scope)?
> >
> > I don't understand what we will get out of such a scheme? Is there any benefit
> > of getting these values via the pointer to the internal C event ?
> >
> 
> You avoid allocating memory for those objects. The memory exists in
> the C buffer. In order to keep a similar level of performance you'd
> need to replicate the behavior of the buffer in rust as well.

I was aligned with all this, I just wanted to skip providing the interface where
we use the event without copying as that has Safety issues. I will try to
provide both the options now, lets see how it looks.

-- 
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