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

James Prestwood <[email protected]> Fri, 28 Apr 2023 09:08:59 -0700
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
Hi Brandon,

On 4/28/23 5:20 AM, 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.
> ---
>   ell/cert.h     |  4 ++--
>   ell/cleanup.h  |  4 ++--
>   ell/ecc.h      |  4 ++--
>   ell/icmp6.h    |  2 +-
>   ell/key.h      |  4 ++--
>   ell/rtnl.h     |  6 +++---
>   ell/settings.h |  2 +-
>   ell/string.h   |  2 +-
>   ell/strv.h     |  2 +-
>   ell/uintset.h  |  2 +-
>   ell/util.h     | 12 ++++++------
>   11 files changed, 22 insertions(+), 22 deletions(-)
> 

<snip>

> diff --git a/ell/cleanup.h b/ell/cleanup.h
> index 89b1981..d2c9232 100644
> --- a/ell/cleanup.h
> +++ b/ell/cleanup.h
> @@ -22,6 +22,6 @@
>   
>   #pragma once
>   
> -#define DEFINE_CLEANUP_FUNC(func)			\
> +#define DEFINE_CLEANUP_FUNC(func, arg_type)			\
>   	inline __attribute__((always_inline))		\
> -	void func ## _cleanup(void *p) { func(*(void **) p); }
> +	void func ## _cleanup(void *p) { func((arg_type)(*(void **) p)); }

Just an FYI, we do use DEFINE_CLEANUP_FUNC in IWD:

https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/src/util.h#n131

I doubt other projects use it since its pretty new, but maybe someone 
else can speak to that? Just wanted everyone to be aware of the API change.

Thanks,
James