Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=32d926dcc3293fb2bff192cf690878a2091da00a
commit 32d926dcc3293fb2bff192cf690878a2091da00a Author: Michel Hermier <[email protected]> Date: Sun Jun 9 09:12:13 2013 +0200 libflib: Added f_typeof_member, and protect f_containerof for NULL so f_container (NULL, struct foo, bar) allways return NULL. diff --git a/lib/libflib/fstddef.h b/lib/libflib/fstddef.h index e1f9ab1..e70a6c8 100644 --- a/lib/libflib/fstddef.h +++ b/lib/libflib/fstddef.h @@ -36,8 +36,12 @@ #warning Unsupported compiler #endif +#define __f_containerof(ptr, type, offsetof) \ + ((type *) ((ptr) != NULL ? ((char *)(ptr)) - (offsetof) : NULL)) + #define f_containerof(ptr, type, member) \ - ((type *) ((char *)f_identity_cast (f_typeof (&((type *)0)->member), (ptr)) - offsetof (type, member))) + __f_containerof ( f_identity_cast (f_typeof_member (type, member), (ptr)), \ + type, offsetof (type, member)) #define f_identity_cast(type, expr) \ f_static_if (f_typecmp (type, f_typeof (expr)), \ @@ -49,6 +53,9 @@ #define f_type_assert(expr, type) \ f_static_assert (f_typecmp (f_typeof (expr), type)) +#define f_typeof_member(type, member) \ + f_typeof (&((type *)NULL)->member) + #endif /* F_STDDEF_H */ /* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
