Boost logo

Boost :

From: Martin Wille (mw8329_at_[hidden])
Date: 2003-08-17 14:32:58


Hi,

I found a problem in execution_monitor.cpp of Boost.Test
on POSIX systems.

The file uses the sigsetjmp() and siglongjmp() functions
and the sigjmp_buf data type.

They all are defined by POSIX as an extention to the
ANSI-C standard, i.e. the interface is defined in a
header file defined by ANSI-C (<setjmp.h> in this case)
and the extension has to be enabled by #defining certain
symbols before #including any of the header files defined
by ANSI-C or POSIX.

The glibc implementation of the POSIX API relaxes that
requirement: when the symbol __STRICT_ANSI__ isn't
defined and none of the POSIX symbols is defined, either,
then a couple of symbols gets defined in <features.h>,
thus enabling most of the POSIX stuff. Also, defining
the symbol _GNU_SOURCE enables all of the POSIX stuff.

gcc defines __STRICT_ANSI__ when the -ansi flag is
used. gcc versions >= 3 strangely define _GNU_SOURCE
(on Linux systems. On cygwin they don't define that
symbol). Hence, with gcc versions >= 3 or when -ansi
isn't used with gcc, execution_monitor.cpp compiles fine.
With -ansi and -U_GNU_SOURCE the compilation of
execution_monitor.cpp fails.

Other compilers probably also enable POSIX by default.

However, como defines __STRICT_ANSI__ (in non-scrict and
in scrict modes) and doesn't define _GNU_SOURCE or any
of the POSIX enabling symbols. Therefore, compiling
execution_monitor.cpp fails for como unless _GNU_SOURCE
or one of the POSIX enabling symbols is defined explicitely.

In order to correctly enable the POSIX interface we
need to get _POSIX_SOURCE defined for older POSIX
implementations and one of _POSIX_C_SOURCE or
_XOPEN_SOURCE defined to an appropriate value for
newer POSIX implementations.

However, this isn't easy, because the POSIX feature
flags have to be set before any of the POSIX or ANSI-C
header are #included. One way to accomplish this would
be on the commandline of the compiler.

When I tried to add a define to the DEFINES
variable of the como tools set I ran into
the problem described in a seperate posting
to the Jamboost mailing list. Also, I think,
the como (or any other) toolset or the Boost.Test
Jamfile would be the wrong places to add the define(s).
The users should have a chance to specify different
POSIX feature flags.

However, for the regression tests one of the feature
flags should be set. Therefore, I suggest to add
-D_POSIX_SOURCE and -D_POSIX_C_SOURCE=1 to the command-
lines of all compile commands for tests on POSIX systems
(AFAIK, similar problems for other POSIX systems haven't
been reported yet. However, the POSIX standard requires
these symbols to be defined). Maybe, Boost.Thread requires
a different value for POSIX_C_SOURCE.

The documentation for Boost.Test and for Boost.Thread
should mention the need to enable the POSIX API on
POSIX systems.

Regards,
m


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk