[RFC] add NetBSD compat macros to sys/cdefs.h

Garrett Cooper yaneurabeya at gmail.com
Tue May 28 02:21:22 UTC 2013


Hi,
    One of the things that I've done in order to reduce unnecessary
divergence when porting NetBSD testcases to FreeBSD is I've pushed a
few macros into my sys/cdefs.h in order to facilitate compatibility
with NetBSD:

/* NetBSD compat */
/*
 * The following macro is used to remove const cast-away warnings
 * from gcc -Wcast-qual; it should be used with caution because it
 * can hide valid errors; in particular most valid uses are in
 * situations where the API requires it, not to cast away string
 * constants. We don't use *intptr_t on purpose here and we are
 * explicit about unsigned long so that we don't have additional
 * dependencies.
 */
#define __UNCONST(a)    ((void *)(unsigned long)(const void *)(a))

#define ___STRING(x)            __STRING(x)
#define __arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))
/* End NetBSD compat */

To clarify...
- I know __UNCONST is basically like __DECONST on steroids as
__UNCONST doesn't have the typecasting like __DECONST does.
- I'm working at removing the need for ___STRING with upstream.
- I know that __arraycount is equivalent to nitems.

    The reason why I'm doing this is to reduce divergence and get
things going ASAP with the testing effort as I have a couple thousand
testcases ported from NetBSD which will be hooked into release images
(really soon) and will result in automated testing (not too far away,
potentially a couple months), versus the zero coverage we currently
have in FreeBSD. If _anyone_ has a better idea and is willing to pony
up the patch to make things more sane, please by all means do.
    I would prefer not to use libnetbsd as it just introduces
unnecessary churn in Makefiles and dependencies on a compat library
strictly for a couple of C macros.
    Thoughts?
Thanks!
-Garrett


More information about the freebsd-arch mailing list