Test for GNU/XSI version of strerror_r

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am writing a Python extension that calls strerror_r.  Unfortunately,
the Python extension build system requires that Python.h be the first
header file included; it also sets the _GNU_SOURCE feature test macro
*and* includes string.h.

If I define _GNU_SOURCE before including Python.h, I receive a warning
about the macro being redefined.  AFAICT, gcc does not provide a way to
suppress this warning.

My tests show that I am getting the GNU version of strerror_r, but I
hate relying on the internal structure of the Python header files (even
more that I hate warnings).

So I'm trying to come up with a compile-time check, to ensure that
strerror_r has the desired signature (i.e. it returns a char *, not an
int).  Here's what I've got:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic error "-Wincompatible-pointer-types"
__attribute__((unused))
static inline void check_for_gnu_strerror_r(void)
{
    /*
    * If this causes an 'incompatible pointer type' error, strerror_r is
    * the XSI-compliant version; we need the GNU-specific version.  See
    * strerror(3).
    */
    char *(*foo)(int, char *, size_t) = strerror_r;
}
#pragma GCC diagnostic pop

This appears to work, but it (obviously) generates a completely
unhelpful error message.  It also has the potential to actually output
the code for check_for_gnu_strerror_r(), although a simple test at -O3
shows it being optimized completely out.

Is there a better way to do this?

--
========================================================================
Ian Pilcher                                         arequipeno@xxxxxxxxx
-------- "I grew up before Mark Zuckerberg invented friendship" --------
========================================================================




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux