[PATCH] lib: add const-ness to appropriate parameters in addr, attr, data

Thomas Haller thaller at redhat.com
Tue Feb 17 04:19:47 PST 2015


On Sat, 2015-02-14 at 03:39 +0800, Rohan Joyce wrote:
> Hi Dan,
> 
> > Though I think it'll break source compatibility at least?  eg something
> > built against libnl before this patch will no longer build after this
> > patch, potentially.  Just something to think about.
> 
> I don't think it should. It changes the following types for some parameters
> (and a few function-local vars):
> 
> struct nlattr *     -> const struct nlattr *
> struct nl_addr *    -> const struct nl_addr *
> struct nla_policy * -> const struct nla_policy *
> struct nl_data *    -> const struct nl_data *
> struct nl_msg *     -> const struct nl_msg *
> void *              -> const void *
> char *              -> const char *
> 
> As far as I know, anything that previously called:
> 
> uint8_t nla_get_u8(struct nlattr *);
> 
> should be fine (with respect to both syntax and abi) calling:
> 
> uint8_t nla_get_u8(const struct nlattr *);
> 
> With the latter it'll accept arguments of either type 'struct nlattr *' or
> 'const struct nlattr *'. The current API won't accept const-qualified pointers
> for some operations that seem like they should be fine with them.

I agree that it is not an API break.


Also, although the patch does not fix all the missing const-ness, it
goes in the right direction.



I have some doubts about functions like 
  void *nl_data_get(const struct nl_data *data)
which return a non-const pointer to an internal field.

As you say, that is also what strchr() does. And while it's not great, I
think it's the best you can do in C.



I merged the patch as
https://github.com/thom311/libnl/commit/6f891f6c0c9ca68658491fe3b959613809309027



Thanks for your help!!
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20150217/e9828826/attachment.sig>


More information about the libnl mailing list