Boost logo

Boost :

Subject: [boost] [test] sigaltstack does not work on older Android
From: Jan Hudec (bulb_at_[hidden])
Date: 2012-08-17 17:06:23


Hello Folks,

Android NDK contains several "platforms", depending on which release one
desires to be compatible with. Boost test compiles fine with android-8 and
newer, but the older versions have incomplete definition of sigaltstack (they
define the structure, but not the function), causing compilation error in
boost/test/detail/impl/execution_monitor.ipp.

I have fixed it locally by adjusting the condition for defining
BOOST_TEST_USE_ALT_STACK, but I am not sure which level of fix would be best
suited for integrating in boost. I see 3 options:

 1. Leaving it as is and simply saying android is only supported from API
    level 8 (that's 2.2; we are still compiling for 2.1 (which has no changes
    in native since 2.0))
 2. Simply disabling BOOST_TEST_USE_ALT_STACK in Android; it's not necessary
    after all.
 3. Being really precise and reading the API version, but that requires
    including extra header. It would be nice, but I am not sure what is the
    correct place to include it.

Here is a simple patch that just disables sigaltstack for Android:

--- a/boost/test/impl/execution_monitor.ipp
+++ b/boost/test/impl/execution_monitor.ipp
@@ -173,7 +173,7 @@ namespace { void _set_se_translator( void* ) {} }
 # endif
 # endif
 
-# if !defined(__CYGWIN__) && !defined(__QNXNTO__)
+# if !defined(__CYGWIN__) && !defined(__QNXNTO__) && !defined(__ANDROID__)
 # define BOOST_TEST_USE_ALT_STACK
 # endif
 

And here is a more complex patch that on android (the __ANDROID__ macro is
predefined by the compiler in Android NDK) reads the api-level and uses it to
decide:

--- a/boost/test/impl/execution_monitor.ipp
+++ b/boost/test/impl/execution_monitor.ipp
@@ -173,7 +173,11 @@ namespace { void _set_se_translator( void* ) {} }
 # endif
 # endif
 
-# if !defined(__CYGWIN__) && !defined(__QNXNTO__)
+# if defined(__ANDROID__)
+# include <android/api-level.h>
+# endif
+
+# if !defined(__CYGWIN__) && !defined(__QNXNTO__) && (!defined(__ANDROID__) || __ANDROID_API__ >= 8)
 # define BOOST_TEST_USE_ALT_STACK
 # endif
 

-- 
						 Jan 'Bulb' Hudec <bulb_at_[hidden]>

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