[ltt-dev] [UST PATCH] Fixes container_of macro redefinition warnings

Nils Carlson nils at as68123.uab.ericsson.se
Thu Sep 23 10:27:15 EDT 2010


Commente below...

On Wed, 22 Sep 2010, David Goulet wrote:

> On urcu commit 453629a9317adef5b96c3d55e4dcd98db680997a, the
> container_of macro was moved to urcu/compiler.h. Since, multiple
> warnings appear about redefinition
>

I think we should consider things in a more general sense. This is a 
little bit of what I think the Qemu/KVM people were complaining about.

We are terrible namespace polluters. Ideally, when you make a library,
you want to provide a limited set of external api's that are well defined
and well maintained and consistent over versions. You then want to hide
EVERYTHING else. This means that we should put some effort into hiding
all the macros and functions that we don't want to explicity export.

So I suggest we prefix all out internal-only macros which are visible in
global header files with __ust_. I would suggest Mathieu do the same with
urcu. If we don't want to support the macros, then they should have a 
private namespace. I think container_of is an excellent example of this, 
we use it, but it's not ours to export.

So a NACK here. Instead, call it __ust_container_of and then fix all the 
call sites.

/Nils




> Signed-off-by: David Goulet <david.goulet at polymtl.ca>
> ---
> include/ust/core.h           |    2 ++
> include/ust/kcompat/simple.h |    3 ++-
> 2 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/include/ust/core.h b/include/ust/core.h
> index 0172614..d5a1f4d 100644
> --- a/include/ust/core.h
> +++ b/include/ust/core.h
> @@ -141,8 +141,10 @@ static __inline__ int get_count_order(unsigned int count)
> 	return order;
> }
>
> +#ifndef container_of
> #define container_of(ptr, type, member) ({                      \
>         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
>         (type *)( (char *)__mptr - offsetof(type,member) );})
> +#endif /* containter_of */
>
> #endif /* UST_CORE_H */
> diff --git a/include/ust/kcompat/simple.h b/include/ust/kcompat/simple.h
> index 762d802..586b2ed 100644
> --- a/include/ust/kcompat/simple.h
> +++ b/include/ust/kcompat/simple.h
> @@ -28,10 +28,11 @@
>  * @member:	the name of the member within the struct.
>  *
>  */
> +#ifndef container_of
> #define container_of(ptr, type, member) ({			\
> 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
> 	(type *)( (char *)__mptr - offsetof(type,member) );})
> -
> +#endif /* container_of */
>
> /* libkcompat: from rcupdate.h */
>
> -- 
> 1.7.3
>
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>




More information about the lttng-dev mailing list