diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1545,11 +1545,31 @@ #define _LIBCPP_BUILTIN_CONSTANT_P(x) false #endif +#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 +#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS +#endif + +// define try / catch / throw macros. +// The intended use case is to deal with exceptions transparently for rollbacks: +// _LIBCCP_TRY { +// ++__p_; +// __this_may_fail(__p); +// } _CATCH_ALL { +// --__p_; +// _LIBCPP_THROW; +// } +// When compiling with exceptions disabled, the CATCH_ALL block is elided. // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set // of functions used in cstdio may not be available for low API levels when // using 64-bit file offsets on LP32. -#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 -#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS +#ifdef _LIBCPP_NO_EXCEPTIONS +#define _LIBCPP_TRY +#define _LIBCPP_CATCH_ALL if (false) +#define _LIBCPP_THROW +#else +#define _LIBCPP_TRY try +#define _LIBCPP_CATCH_ALL catch(...) +#define _LIBCPP_THROW throw #endif #endif // __cplusplus diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -863,12 +863,21 @@ if (__beg && is_same::value) __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); } -#else + _LIBCPP_INLINE_VISIBILITY - void __annotate_contiguous_container(const void*, const void*, const void*, - const void*) const _NOEXCEPT {} -#endif + void __annotate_increase(size_type __n) const _NOEXCEPT + { + __annotate_contiguous_container(data(), data() + capacity(), + data() + size(), data() + size() + __n); + } + _LIBCPP_INLINE_VISIBILITY + void __annotate_shrink(size_type __old_size) const _NOEXCEPT + { + __annotate_contiguous_container(data(), data() + capacity(), + data() + __old_size, data() + size()); + } + void __annotate_new(size_type __current_size) const _NOEXCEPT { __annotate_contiguous_container(data(), data() + capacity(), data() + capacity(), data() + __current_size); @@ -879,21 +888,22 @@ __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + capacity()); } - +#else _LIBCPP_INLINE_VISIBILITY - void __annotate_increase(size_type __n) const _NOEXCEPT - { - __annotate_contiguous_container(data(), data() + capacity(), - data() + size(), data() + size() + __n); - } + void __annotate_contiguous_container(const void*, const void*, const void*, + const void*) const _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void __annotate_increase(size_type) const _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY - void __annotate_shrink(size_type __old_size) const _NOEXCEPT - { - __annotate_contiguous_container(data(), data() + capacity(), - data() + __old_size, data() + size()); - } + void __annotate_shrink(size_type) const _NOEXCEPT {} + void __annotate_new(size_type) const _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + void __annotate_delete() const _NOEXCEPT {} +#endif + _LIBCPP_INLINE_VISIBILITY struct _ConstructTransaction { explicit _ConstructTransaction(vector &__v, size_type __n) : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { @@ -919,37 +929,19 @@ _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; }; -#if defined(_LIBCPP_HAS_NO_ASAN) - struct _AsanTransaction { - explicit _AsanTransaction(vector&, size_type) {} - void __commit(size_type) {} - }; -#elif defined(_LIBCPP_NO_EXCEPTIONS) - struct _AsanTransaction { - explicit _AsanTransaction(vector &, size_type __n) { - __v_.__annotate_increase(__n); - } - void __commit(size_type) {} - }; -#else // _LIBCPP_NO_EXCEPTIONS - struct _AsanTransaction { - _AsanTransaction(vector& __v, size_type __n) : __v_(__v), __n(__n) { - __v_.__annotate_increase(__n); - } - ~_AsanTransaction() { __v_.__annotate_shrink(__n_); } - void __commit(size_type __n) { __n_ -= __n; } - vector& __v_; - size_t __n_; - }; -#endif // _LIBCPP_NO_EXCEPTIONS template _LIBCPP_INLINE_VISIBILITY void __construct_one_at(pointer __pos, _Args&&... __args) { - _AsanTransaction tx(*this, 1); - __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), - _VSTD::forward<_Args>(__args)...); - tx.__commit(1); + _LIBCPP_TRY { + __annotate_increase(1); + __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), + _VSTD::forward<_Args>(__args)...); + } + _LIBCPP_CATCH_ALL { + __annotate_shrink(1); + _LIBCPP_THROW; + } } template