#129 Define bad_alloc exception when exception handling disabled


When compiling STLport with the standard Android NDK (version R4), there is an incompatibility with Boost shared_ptr (see my blog article on this subject http://www.codexperiments.com/android/2010/05/android-introduction-part-2-setting-up-your-environment/\) and STLPort because STLPort does not define bad_alloc class when _STLP_USE_EXCEPTIONS flag is turned on. However, even when not using exceptions handling (try catch) as this is not authorized on defualt Android NDK, exceptions class should be available to allow emulation and avoid incompatibilities with exception-able code.

Here is the problematic Boost code:
in shared_count.hpp: "boost::throw_exception( std::bad_alloc() );"

And here is the error:
./../../../cots/boost/boost/smart_ptr/detail/shared_count.hpp: In constructor 'boost::detail::shared_count::shared_count(Y*)':
./../../../cots/boost/boost/smart_ptr/detail/shared_count.hpp:102: error: 'bad_alloc' is not a member of 'std'

I provide a patch which shouldn't have any side-effects on other platforms. However, as this is the first time I try a modification on STLPort and my knowledge of it is limited, please review it carefully. There may be a better way.


  • Ratamovic

    Ratamovic - 2010-12-04

    Adds a macro to define bad_alloc

  • Ratamovic

    Ratamovic - 2010-12-04
    • summary: Define bad_alloc exception in no exception mode --> Define bad_alloc exception when exception handling disabled
  • Ratamovic

    Ratamovic - 2010-12-04

    My STLPort make file for Android (-DANDROID must be defined)


Log in to post a comment.