RE: cleanup: Make no_free_ptr() __must_check

From: David Laight
Date: Tue Aug 15 2023 - 11:17:57 EST


From: Peter Zijlstra
> Sent: 15 August 2023 14:54
...
> > Also, isn't it more complicated than necessary? Can we get rid of the
> > inner stmt expr and tmp var by just making it
> >
> > ((void) (p), ((typeof(p))__no_free_ptr((void **)&(p)))
> >
> > which is more or less the whole reason comma expressions is a thing.
>
> Ah, so the point of the statement expression before the comma is to
> validate that (p) is in fact a pointer, and to that effect we assign it
> to a 'void *' temporary.
>
> If that case is invalid, we'll get a compile fail with a dodgy message.
>
> I did this, because (void **)&(p) looses type integrity due to the cast.
>
> But yeah, I suppose it all needs a wee comment.

Perhaps add an is_pointer_type() along with is_signed_type()
(and really is_constexpr()) to a global header.

Various checks can be used including:
#define is_pointer_type(t) (!is_constexpr((t)0))
which gives a 0/1 to play with rather than an immediate error.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)