Re: [libgpiod][RFC PATCH] bindings: cxx: demote the line's parent chip reference to a weak_ptr

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

 



On Fri, Oct 16, 2020 at 3:38 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
>
> On Fri, Oct 16, 2020 at 12:29 PM Helmut Grohne <helmut.grohne@xxxxxxxxxx> wrote:
> >
>
> [snip]
>
> > > +chip::chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr)
> > > +     : _m_chip(chip_ptr)
> > > +{
> > > +
> > > +}
> > > +
> >
> > I think what happens here is that you upgrade a weak_ptr to a
> > shared_ptr. Wouldn't it be more natural to request a
> >
> >     ::std::shared_ptr<::gpiod_chip> &&
> >
> > here and thus make the ownership-taking more explicit? It would be done
> > on the caller-side and thus be more transparent. Stuffing weak_ptrs
> > should continue to work.
> >
>
> Sure, sounds good.
>

After a second look - I'm not sure if this is actually better. By
taking weak_ptr reference as argument we benefit from implicit
conversion to shared_ptr via shared_ptr's constructor taking weak_ptr
as argument. What you propose would require us to always instantiate a
shared_ptr in the argument list when calling the chip's constructor
and makes code uglier in the end IMO.

Bartosz



[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