Re: [PATCH] ell: Make public headers compilable with C++

Brandon Cheo Fusi <[email protected]> Wed, 10 May 2023 16:43:54 +0100
Newsgroups dev.linux.lists.ell
Message-ID <CAEVJM+pD_CafRK=B+OXqJZHx-MDz-PsCRDkO43fji1VmZ_cjew@mail.gmail.com>
Hi Dennis,

Sorry for the delay in responding.

Thanks for pointing that out. Wouldn't it be better to not assume an
array of 6+ bytes and instead
do NULL and size checking in the implementations?

Regards,
Brandon

On Sun, Apr 30, 2023 at 7:24 PM Denis Kenzior <[email protected]> wrote:
>
> Hi Brandon,
>
> On 4/28/23 07:20, Brandon Cheo Fusi wrote:
> > This patch allows ell/ell.h to be included in C++ code by removing
> > 'only C' features. These comprise
> >
> > i)  implicit casts from void* to other types which are now made
> >      explicit
> > ii) C99 Static array indices.
>
> <snip>
>
> >   bool l_icmp6_client_set_address(struct l_icmp6_client *client,
> > -                                     const uint8_t addr[static 6]);
> > +                                     const uint8_t addr[]);
>
> You can't really do that because l_icmp6_client_set_address implementation
> doesn't do any NULL/size checking.  It assumes an array of 6+ bytes.  And that
> is sort of the whole point of using the 'static 6' syntax.
>
> Maybe there's a way to come up with an alternative declaration, using
> '__attribute__ nonnull'?  Perhaps combined with using a pointer to an array?
>
> >   uint32_t l_rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
> > -                                     const uint8_t addr[static 6],
> > +                                     const uint8_t addr[],
> >                                       bool power_up,
> >                                       l_netlink_command_func_t cb,
> >                                       void *user_data,
>
> Same comments here.
>
> Regards,
> -Denis