[PATCH libevdev 3/4] Constify libevdev_get_repeat
Peter Hutterer
peter.hutterer at who-t.net
Thu Dec 5 13:46:34 PST 2013
On Thu, Dec 05, 2013 at 06:18:25PM +0100, David Herrmann wrote:
> Hi
>
> On Wed, Dec 4, 2013 at 10:56 PM, Peter Hutterer
> <peter.hutterer at who-t.net> wrote:
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> > ---
> > libevdev/libevdev.c | 2 +-
> > libevdev/libevdev.h | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
> > index 2944f8f..d543dad 100644
> > --- a/libevdev/libevdev.c
> > +++ b/libevdev/libevdev.c
> > @@ -1335,7 +1335,7 @@ libevdev_event_type_get_max(unsigned int type)
> > }
> >
> > LIBEVDEV_EXPORT int
> > -libevdev_get_repeat(struct libevdev *dev, int *delay, int *period)
> > +libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period)
>
> I really dislike the "const" on opaque structures. I only just noticed
> that we do that for all read-only calls, but I cannot imagine a
> situation where a user gets a read-only libevdev object. "const" makes
> sense to mark read-only memory, but I've never seen a sane way to use
> it for access-protection.
>
> But I guess that's just personal taste..
tbh, I often use const less for access protection and more for readability.
having an API that takes a const pointer signals that this function call
won't change the object. when you're debugging code (or just generally
trying to understand it) this can be of great help. And the compiler can
get a few hints from that as well.
plus, there's the usual self-protection against accidentially changing the
struct when we don't want to.
Cheers,
Peter
> > {
> > if (!libevdev_has_event_type(dev, EV_REP))
> > return -1;
> > diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
> > index 23d1b32..afcf366 100644
> > --- a/libevdev/libevdev.h
> > +++ b/libevdev/libevdev.h
> > @@ -1614,7 +1614,7 @@ int libevdev_event_code_from_name_n(unsigned int type, const char *name,
> > *
> > * @note This function is signal-safe
> > */
> > -int libevdev_get_repeat(struct libevdev *dev, int *delay, int *period);
> > +int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period);
> >
> >
> > /********* DEPRECATED SECTION *********/
> > --
> > 1.8.3.1
> >
> > _______________________________________________
> > Input-tools mailing list
> > Input-tools at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list