public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
From: Helmut Grohne <helmut.grohne@intenta.de>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	Kent Gibson <warthog618@gmail.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][RFC PATCH] bindings: cxx: demote the line's parent chip reference to a weak_ptr
Date: Tue, 20 Oct 2020 07:57:14 +0200	[thread overview]
Message-ID: <20201020055714.GA10256@laureti-dev> (raw)
In-Reply-To: <CAMpxmJU0y5Zze3we-NjnLi1fCG69v38fMwvTgCe0JXGK+RxLNQ@mail.gmail.com>

On Mon, Oct 19, 2020 at 03:06:18PM +0200, Bartosz Golaszewski wrote:
> But this still forces us to do
> 
>     return chip(::std::shared_ptr<::gpiod_chip>(this->_m_owner));
> 
> instead of a much more elegant
> 
>     return chip(this->_m_owner);
> 
> in line.cpp and there's an even less elegant thing in iter.cpp. Or am
> I missing something?

I confirm the behaviour you see. My intuition that the conversion would
happen implicitly was wrong.

Still the sticking point is this: Your constructor should allow for most
flexibility to the caller and in this case that means it should consume
a shared_ptr by value.

In order to make the case with a weak_ptr bearable, I suggest adding a
delegating constructor:

    chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr) :
        chip(::std::shared_ptr<::gpiod_chip>(chip_ptr)) {}

That way your desired way of calling should continue to work while not
forcing callers to convert a real shared_ptr to weak_ptr and back.

Sorry for the confusion about this.

Helmut

  reply	other threads:[~2020-10-20  5:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16  9:09 [libgpiod][RFC PATCH] bindings: cxx: demote the line's parent chip reference to a weak_ptr Bartosz Golaszewski
2020-10-16 10:29 ` Helmut Grohne
2020-10-16 13:38   ` Bartosz Golaszewski
2020-10-19 12:17     ` Bartosz Golaszewski
2020-10-19 12:38       ` Helmut Grohne
2020-10-19 13:06         ` Bartosz Golaszewski
2020-10-20  5:57           ` Helmut Grohne [this message]
2020-10-20  6:58             ` Bartosz Golaszewski
2020-11-04 15:45               ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201020055714.GA10256@laureti-dev \
    --to=helmut.grohne@intenta.de \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox