This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/7] Fix __PTHREAD_MUTEX_HAVE_ELISION -Wundef warning
- From: Roland McGrath <roland at hack dot frob dot com>
- To: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 18 Mar 2014 15:46:07 -0700 (PDT)
- Subject: Re: [PATCH 1/7] Fix __PTHREAD_MUTEX_HAVE_ELISION -Wundef warning
- Authentication-results: sourceware.org; auth=none
- References: <1395059004-20960-1-git-send-email-will dot newton at linaro dot org> <20140317182818 dot 5EAD474457 at topped-with-meat dot com> <20140317183732 dot C5A2374458 at topped-with-meat dot com> <532749D3 dot 3080008 at linux dot vnet dot ibm dot com> <20140317195304 dot 3AA2174461 at topped-with-meat dot com> <53283BD1 dot 1020000 at linux dot vnet dot ibm dot com>
> So your idea is also to refactor __PTHREAD_MUTEX_HAVE_PREV to use as #if
> ... along with __PTHREAD_MUTEX_HAVE_ELISION then? Both defines are set by
> arch specific headers, so would be the idea to just a generic pthread
> header (or use an existing one) to define them to default values?
I haven't examined that particular set of macros, so I don't have something
specific in mind. It's just the general rule that we should organize our
macros (including wholesale reshuffling of what we have today, if need be)
so that every use under our control if typo-proof.
For cases like this in general (sysdeps headers making the choices), I
think when it's straightforward enough to simply require that each variant
of the sysdeps header #define the full set to 1/0 explicitly, then that is
the way to go. Building with -Wundef ensures that if a new macro is added
and some sysdeps file gets out of date, the next person doing a build of
that configuration will notice with loud and obvious -Wundef warnings. We
should also establish a clear and regimented convention for comments
describing what macros the sysdeps file is obliged to define.
It's entirely plausible that there will be cases where it seems cleaner to
have a generic header that includes a sysdeps one and then uses #ifndef to
provide defaults. But that style is prone to typo bugs, so it should be a
high burden to say that this is the preferable approach for any given
header and set of macros. If there are cases where we decide to do that,
it should be treated like the predefines case: a single block of #if hooey,
clearly isolated from all other logic and in an obvious place like near the
beginning of a header, should do all the #ifndef testing in one place that
is easy to verify by eye, does nothing at all but yield a set of
always-defined macros to be tested later with #if, and has a comments
following a clear convention to say what all the macros are.
Thanks,
Roland