This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Mis-detection of posix_memalign()

Tags: None
(comma "," separated)
Ross Smith
Registered Member
Posts
1
Karma
0

Mis-detection of posix_memalign()

Fri Apr 24, 2009 1:51 am
Trying to use Eigen on Cygwin, I got a compiler error about posix_memalign() being undeclared. I traced the problem to the file Eigen/src/Core/util/Memory.h, which uses this preprocessor code to test for the availability of that function:

Code: Select all
#if (defined _GNU_SOURCE) || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))
  #define EIGEN_HAS_POSIX_MEMALIGN 1
#else
  #define EIGEN_HAS_POSIX_MEMALIGN 0
#endif


This fails because posix_memalign() is in an optional section of Posix, so testing for _XOPEN_SOURCE (or _GNU_SOURCE) doesn't necessarily mean that it's available. Cygwin uses Newlib, which doesn't include it. I recommend correcting the test by checking for the relevant feature test macro:

Code: Select all
#if (defined(_GNU_SOURCE) || _XOPEN_SOURCE >= 600) && _POSIX_ADVISORY_INFO > 0


Although in theory this even simpler version should be enough:

Code: Select all
#if _POSIX_ADVISORY_INFO > 0
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Thanks a lot for finding and fixing this bug! I'm applying your change right now.

Except that I'm keeping the (defined _XOPEN_SOURCE) because, as far as I understand, the standard doesn't guarantee that undefined symbols are treated as 0 even though most compilers do that.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
MarkusS
Registered Member
Posts
9
Karma
0
OS
Hi,

your test "#if (defined _GNU_SOURCE) || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))" could still go wrong, if _XOPEN_SOURCE is defined without a value.

On a Mac (10.6.3 with default gcc 4.2.1), I get a compile error, if I include Eigen/Core and _XOPEN_SOURCE is defined without a value:

/usr/local/include/Eigen/src/Core/util/Memory.h:69:70: error: operator '>=' has no left operand

I suggest you change the test to:

#if (defined _GNU_SOURCE) || ((_XOPEN_SOURCE + 0) >= 600))

This compiles cleanly, even if _XOPEN_SOURCE is defined without a value...

Markus


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]