All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: "Viresh Kumar" <viresh.kumar@linaro.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"Wedson Almeida Filho" <wedsonaf@google.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	stratos-dev@op-lists.linaro.org,
	"Gerard Ryan" <g.m0n3y.2503@gmail.com>
Subject: Re: [PATCH V4 4/8] libgpiod: Add rust wrapper crate
Date: Thu, 28 Jul 2022 11:11:04 +0800	[thread overview]
Message-ID: <20220728031104.GB15896@sol> (raw)
In-Reply-To: <CANiq72nGS492exNopKBZnbS72A4jaCYHAV_faSaMDuqE2P23=g@mail.gmail.com>

On Wed, Jul 27, 2022 at 03:02:10PM +0200, Miguel Ojeda wrote:
> On Wed, Jul 27, 2022 at 2:40 PM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > Unfortunately the C header doesn't currently provide any guarantee -
> > except in the cases where it CAN return NULL.
> > But we can fix that.
> 
> Yeah, fixing that is what I was suggesting, since it is a possibility
> here, and would improve things for C users too.
> 
> > Not sure I'm onboard with that.  Unless the API has a contract not to
> > return a NULL then it is free to at a later date. The user should
> > always assume that NULL is a possibility, even if they have never seen
> > one.
> >
> > But in practice you are probably right.
> 
> I definitely agree that a client should aim to avoid assuming anything.
> 
> However, if we are strict, given C pointers are unconstrained, all
> pointers would be useless unless told otherwise, because checking for
> NULL is not a guarantee of validity either.
> 
> Also, if an C API just says "returns the name", for instance, it is
> reasonable to assume it is a valid name because it is not said
> otherwise (e.g. it does not say "returns the name, if available" nor
> "returns an optional name").
> 
> And, of course, eventually consumers will end up relying on your
> particular implementation no matter what, and returning invalid
> pointers where there weren't before is a very dangerous idea for a C
> library.
> 

All true, but practically speaking the only cases we need to be
concerned with here are NULL and valid.  NULL is the only one we can
detect for certain, and we have no alternative but to assume valid if not.

> > I'd be fine with that.
> > I'd also be satisfied with a comment in the Rust that the C guarantees a
> > non-NULL where that is the case.  That would at least demonstrate that the
> > possibility has been duly considered.
> 
> I think the current `SAFETY` comment already intends to imply that,
> but yeah, it could be clarified.
> 

The comment is:

    // SAFETY: The string is guaranteed to be valid here.

and that is whether there a NULL check or not, so it isn't clear what
the source of the guarantee is.
I would prefer:

    // SAFETY: The string is guaranteed to be valid by the C API.

and updating the C header to explicitly state it returns a valid pointer.
It currently says "Pointer to a human-readable string" which could be
taken to mean valid, but making it "Valid pointer to..." would more
clearly place the onus of it actually being valid on the C library.

Cheers,
Kent.

> In any case, I would say it always returns a valid pointer, not
> "non-NULL", since the latter does not really show it is a valid
> pointer (it could point to a non-NULL, bad address).
> 
> Cheers,
> Miguel

  reply	other threads:[~2022-07-28  3:11 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 11:34 [PATCH V4 0/8] libgpiod: Add Rust bindings Viresh Kumar
2022-07-08 11:34 ` [PATCH V4 1/8] libgpiod: Add libgpiod-sys rust crate Viresh Kumar
2022-07-27  2:57   ` Kent Gibson
2022-07-27  4:51     ` Viresh Kumar
2022-07-27  5:17       ` Kent Gibson
2022-07-27  5:45         ` Viresh Kumar
2022-08-01 12:11         ` Viresh Kumar
2022-08-01 15:56           ` Kent Gibson
2022-08-02  8:50             ` Viresh Kumar
2022-08-02  9:36               ` Kent Gibson
2022-07-08 11:34 ` [PATCH V4 2/8] libgpiod: Add pre generated rust bindings Viresh Kumar
2022-07-27  2:57   ` Kent Gibson
2022-07-27  5:15     ` Viresh Kumar
2022-07-27  5:31       ` Kent Gibson
2022-07-27  6:00         ` Viresh Kumar
2022-07-27  6:06           ` Kent Gibson
2022-07-08 11:34 ` [PATCH V4 3/8] libgpiod-sys: Add support to generate gpiosim bindings Viresh Kumar
2022-07-27  2:57   ` Kent Gibson
2022-07-27  5:30     ` Viresh Kumar
2022-07-08 11:34 ` [PATCH V4 4/8] libgpiod: Add rust wrapper crate Viresh Kumar
2022-07-27  2:57   ` Kent Gibson
2022-07-27  9:07     ` Viresh Kumar
2022-07-27 10:08       ` Kent Gibson
2022-07-27 11:06         ` Miguel Ojeda
2022-07-27 12:40           ` Kent Gibson
2022-07-27 13:02             ` Miguel Ojeda
2022-07-28  3:11               ` Kent Gibson [this message]
2022-07-29  4:40                 ` Viresh Kumar
2022-07-28  3:10         ` Kent Gibson
2022-08-01 12:05         ` Viresh Kumar
2022-08-01 13:20           ` Kent Gibson
2022-08-01 13:28             ` Miguel Ojeda
2022-07-28  8:52     ` Viresh Kumar
2022-07-28  9:59       ` Kent Gibson
2022-07-08 11:34 ` [PATCH V4 5/8] libgpiod: Add rust examples Viresh Kumar
2022-07-27  2:58   ` Kent Gibson
2022-07-27  9:23     ` Viresh Kumar
2022-07-27  9:59       ` Kent Gibson
2022-07-27 10:06         ` Viresh Kumar
2022-07-27 10:32           ` Kent Gibson
2022-07-27 10:33             ` Viresh Kumar
2022-07-08 11:34 ` [PATCH V4 6/8] libgpiod: Derive debug traits for few definitions Viresh Kumar
2022-07-27  2:58   ` Kent Gibson
2022-07-27  6:20     ` Viresh Kumar
2022-07-08 11:35 ` [PATCH V4 7/8] libgpiod: Add rust tests Viresh Kumar
2022-07-27  2:58   ` Kent Gibson
2022-07-27  9:59     ` Viresh Kumar
2022-07-27 10:27       ` Kent Gibson
2022-08-01 11:54     ` Viresh Kumar
2022-08-01 12:38       ` Kent Gibson
2022-08-02  5:44         ` Viresh Kumar
2022-08-02  5:47           ` Kent Gibson
2022-07-08 11:35 ` [PATCH V4 8/8] libgpiod: Integrate building of rust bindings with make Viresh Kumar
2022-07-27  2:59   ` Kent Gibson
2022-07-27  6:18     ` Viresh Kumar
2022-07-27  6:25       ` Kent Gibson
2022-07-27  6:35         ` Viresh Kumar
2022-07-27  6:45           ` Kent Gibson
2022-07-27  6:51             ` Viresh Kumar
2022-07-15 19:07 ` [PATCH V4 0/8] libgpiod: Add Rust bindings Bartosz Golaszewski
2022-07-15 19:17   ` Miguel Ojeda
2022-07-15 19:27     ` Miguel Ojeda
2022-07-16  9:43       ` Miguel Ojeda
2022-07-16 10:43         ` Bartosz Golaszewski
2022-07-16 12:23           ` Kent Gibson
2022-07-16 13:46           ` Miguel Ojeda

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=20220728031104.GB15896@sol \
    --to=warthog618@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=g.m0n3y.2503@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=stratos-dev@op-lists.linaro.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=wedsonaf@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.