diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-08-11 17:04:31 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-11 17:04:31 +0000 |
commit | d444470d6cd1cad554139c4ba7f3c4f3fe921a5d (patch) | |
tree | 6281d60246fdb081fa2e7df5b0942c1f9920dd8b | |
parent | 81e68580b2c1fc311e2393fafdfb56adc2a240fd (diff) | |
download | external_libcxx-d444470d6cd1cad554139c4ba7f3c4f3fe921a5d.tar.gz external_libcxx-d444470d6cd1cad554139c4ba7f3c4f3fe921a5d.tar.bz2 external_libcxx-d444470d6cd1cad554139c4ba7f3c4f3fe921a5d.zip |
now works with -fno-exceptions and -fno-rtti
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@110828 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/__config | 8 | ||||
-rw-r--r-- | include/__functional_03 | 64 | ||||
-rw-r--r-- | include/__locale | 2 | ||||
-rw-r--r-- | include/__tree | 12 | ||||
-rw-r--r-- | include/exception | 6 | ||||
-rw-r--r-- | include/functional | 16 | ||||
-rw-r--r-- | include/locale | 4 | ||||
-rw-r--r-- | include/map | 4 | ||||
-rw-r--r-- | include/memory | 14 | ||||
-rw-r--r-- | include/regex | 126 | ||||
-rwxr-xr-x | lib/buildit | 2 | ||||
-rw-r--r-- | src/exception.cpp | 10 | ||||
-rw-r--r-- | src/ios.cpp | 14 | ||||
-rw-r--r-- | src/locale.cpp | 62 | ||||
-rw-r--r-- | src/memory.cpp | 4 | ||||
-rw-r--r-- | src/mutex.cpp | 4 | ||||
-rw-r--r-- | src/new.cpp | 14 | ||||
-rw-r--r-- | src/string.cpp | 32 | ||||
-rw-r--r-- | src/system_error.cpp | 2 | ||||
-rw-r--r-- | src/thread.cpp | 4 |
20 files changed, 394 insertions, 10 deletions
diff --git a/include/__config b/include/__config index c3cf8c7b1..a19b297e1 100644 --- a/include/__config +++ b/include/__config @@ -90,6 +90,10 @@ #define _LIBCPP_NO_EXCEPTIONS #endif +#if !(__has_feature(cxx_rtti)) +#define _LIBCPP_NO_RTTI +#endif + #define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_STRONG_USING #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES @@ -139,6 +143,10 @@ #define _LIBCPP_NO_EXCEPTIONS #endif +#ifndef __GXX_RTTI +#define _LIBCPP_NO_RTTI +#endif + #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #ifndef __GXX_EXPERIMENTAL_CXX0X__ diff --git a/include/__functional_03 b/include/__functional_03 index ffbb165fc..fa318df16 100644 --- a/include/__functional_03 +++ b/include/__functional_03 @@ -243,8 +243,10 @@ public: virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _R operator()() = 0; +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const = 0; virtual const std::type_info& target_type() const = 0; +#endif }; template<class _R, class _A0> @@ -260,8 +262,10 @@ public: virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _R operator()(_A0) = 0; +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const = 0; virtual const std::type_info& target_type() const = 0; +#endif }; template<class _R, class _A0, class _A1> @@ -277,8 +281,10 @@ public: virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _R operator()(_A0, _A1) = 0; +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const = 0; virtual const std::type_info& target_type() const = 0; +#endif }; template<class _R, class _A0, class _A1, class _A2> @@ -294,8 +300,10 @@ public: virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _R operator()(_A0, _A1, _A2) = 0; +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const = 0; virtual const std::type_info& target_type() const = 0; +#endif }; template<class _FD, class _Alloc, class _FB> class __func; @@ -313,8 +321,10 @@ public: virtual void destroy(); virtual void destroy_deallocate(); virtual _R operator()(); +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const; virtual const std::type_info& target_type() const; +#endif }; template<class _F, class _Alloc, class _R> @@ -360,6 +370,8 @@ __func<_F, _Alloc, _R()>::operator()() return __invoke<_R>(__f_.first()); } +#ifndef _LIBCPP_NO_RTTI + template<class _F, class _Alloc, class _R> const void* __func<_F, _Alloc, _R()>::target(const type_info& __ti) const @@ -376,6 +388,8 @@ __func<_F, _Alloc, _R()>::target_type() const return typeid(_F); } +#endif + template<class _F, class _Alloc, class _R, class _A0> class __func<_F, _Alloc, _R(_A0)> : public __base<_R(_A0)> @@ -389,8 +403,10 @@ public: virtual void destroy(); virtual void destroy_deallocate(); virtual _R operator()(_A0); +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const; virtual const std::type_info& target_type() const; +#endif }; template<class _F, class _Alloc, class _R, class _A0> @@ -436,6 +452,8 @@ __func<_F, _Alloc, _R(_A0)>::operator()(_A0 __a0) return __invoke(__f_.first(), __a0); } +#ifndef _LIBCPP_NO_RTTI + template<class _F, class _Alloc, class _R, class _A0> const void* __func<_F, _Alloc, _R(_A0)>::target(const type_info& __ti) const @@ -452,6 +470,8 @@ __func<_F, _Alloc, _R(_A0)>::target_type() const return typeid(_F); } +#endif + template<class _F, class _Alloc, class _R, class _A0, class _A1> class __func<_F, _Alloc, _R(_A0, _A1)> : public __base<_R(_A0, _A1)> @@ -465,8 +485,10 @@ public: virtual void destroy(); virtual void destroy_deallocate(); virtual _R operator()(_A0, _A1); +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const; virtual const std::type_info& target_type() const; +#endif }; template<class _F, class _Alloc, class _R, class _A0, class _A1> @@ -512,6 +534,8 @@ __func<_F, _Alloc, _R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) return __invoke(__f_.first(), __a0, __a1); } +#ifndef _LIBCPP_NO_RTTI + template<class _F, class _Alloc, class _R, class _A0, class _A1> const void* __func<_F, _Alloc, _R(_A0, _A1)>::target(const type_info& __ti) const @@ -528,6 +552,8 @@ __func<_F, _Alloc, _R(_A0, _A1)>::target_type() const return typeid(_F); } +#endif + template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> class __func<_F, _Alloc, _R(_A0, _A1, _A2)> : public __base<_R(_A0, _A1, _A2)> @@ -541,8 +567,10 @@ public: virtual void destroy(); virtual void destroy_deallocate(); virtual _R operator()(_A0, _A1, _A2); +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const; virtual const std::type_info& target_type() const; +#endif }; template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> @@ -588,6 +616,8 @@ __func<_F, _Alloc, _R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) return __invoke(__f_.first(), __a0, __a1, __a2); } +#ifndef _LIBCPP_NO_RTTI + template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> const void* __func<_F, _Alloc, _R(_A0, _A1, _A2)>::target(const type_info& __ti) const @@ -604,6 +634,8 @@ __func<_F, _Alloc, _R(_A0, _A1, _A2)>::target_type() const return typeid(_F); } +#endif + } // __function template<class _R> @@ -669,10 +701,12 @@ public: // 20.7.16.2.4, function invocation: _R operator()() const; +#ifndef _LIBCPP_NO_RTTI // 20.7.16.2.5, function target access: const std::type_info& target_type() const; template <typename _T> _T* target(); template <typename _T> const _T* target() const; +#endif }; template<class _R> @@ -797,11 +831,15 @@ template<class _R> _R function<_R()>::operator()() const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) throw bad_function_call(); +#endif return (*__f_)(); } +#ifndef _LIBCPP_NO_RTTI + template<class _R> const std::type_info& function<_R()>::target_type() const @@ -831,6 +869,8 @@ function<_R()>::target() const return (const _T*)__f_->target(typeid(_T)); } +#endif + template<class _R, class _A0> class function<_R(_A0)> : public unary_function<_A0, _R> @@ -905,10 +945,12 @@ public: // 20.7.16.2.4, function invocation: _R operator()(_A0) const; +#ifndef _LIBCPP_NO_RTTI // 20.7.16.2.5, function target access: const std::type_info& target_type() const; template <typename _T> _T* target(); template <typename _T> const _T* target() const; +#endif }; template<class _R, class _A0> @@ -1033,11 +1075,15 @@ template<class _R, class _A0> _R function<_R(_A0)>::operator()(_A0 __a0) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) throw bad_function_call(); +#endif return (*__f_)(__a0); } +#ifndef _LIBCPP_NO_RTTI + template<class _R, class _A0> const std::type_info& function<_R(_A0)>::target_type() const @@ -1067,6 +1113,8 @@ function<_R(_A0)>::target() const return (const _T*)__f_->target(typeid(_T)); } +#endif + template<class _R, class _A0, class _A1> class function<_R(_A0, _A1)> : public binary_function<_A0, _A1, _R> @@ -1141,10 +1189,12 @@ public: // 20.7.16.2.4, function invocation: _R operator()(_A0, _A1) const; +#ifndef _LIBCPP_NO_RTTI // 20.7.16.2.5, function target access: const std::type_info& target_type() const; template <typename _T> _T* target(); template <typename _T> const _T* target() const; +#endif }; template<class _R, class _A0, class _A1> @@ -1269,11 +1319,15 @@ template<class _R, class _A0, class _A1> _R function<_R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) throw bad_function_call(); +#endif return (*__f_)(__a0, __a1); } +#ifndef _LIBCPP_NO_RTTI + template<class _R, class _A0, class _A1> const std::type_info& function<_R(_A0, _A1)>::target_type() const @@ -1303,6 +1357,8 @@ function<_R(_A0, _A1)>::target() const return (const _T*)__f_->target(typeid(_T)); } +#endif + template<class _R, class _A0, class _A1, class _A2> class function<_R(_A0, _A1, _A2)> { @@ -1376,10 +1432,12 @@ public: // 20.7.16.2.4, function invocation: _R operator()(_A0, _A1, _A2) const; +#ifndef _LIBCPP_NO_RTTI // 20.7.16.2.5, function target access: const std::type_info& target_type() const; template <typename _T> _T* target(); template <typename _T> const _T* target() const; +#endif }; template<class _R, class _A0, class _A1, class _A2> @@ -1504,11 +1562,15 @@ template<class _R, class _A0, class _A1, class _A2> _R function<_R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) throw bad_function_call(); +#endif return (*__f_)(__a0, __a1, __a2); } +#ifndef _LIBCPP_NO_RTTI + template<class _R, class _A0, class _A1, class _A2> const std::type_info& function<_R(_A0, _A1, _A2)>::target_type() const @@ -1538,6 +1600,8 @@ function<_R(_A0, _A1, _A2)>::target() const return (const _T*)__f_->target(typeid(_T)); } +#endif + template <class _F> inline _LIBCPP_INLINE_VISIBILITY bool diff --git a/include/__locale b/include/__locale index c2146d9b9..743b39355 100644 --- a/include/__locale +++ b/include/__locale @@ -134,8 +134,10 @@ template <class _Facet> locale locale::combine(const locale& __other) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (!_STD::has_facet<_Facet>(__other)) throw runtime_error("locale::combine: locale missing facet"); +#endif return locale(*this, &const_cast<_Facet&>(_STD::use_facet<_Facet>(__other))); } diff --git a/include/__tree b/include/__tree index 53c1e1f2a..18363dc53 100644 --- a/include/__tree +++ b/include/__tree @@ -1102,8 +1102,10 @@ __tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _Inpu if (size() != 0) { __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif for (; __cache != nullptr && __first != __last; ++__first) { __cache->__value_ = *__first; @@ -1111,6 +1113,7 @@ __tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _Inpu __node_insert_unique(__cache); __cache = __next; } +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -1119,6 +1122,7 @@ __tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _Inpu destroy(__cache); throw; } +#endif if (__cache != nullptr) { while (__cache->__parent_ != nullptr) @@ -1138,8 +1142,10 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input if (size() != 0) { __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif for (; __cache != nullptr && __first != __last; ++__first) { __cache->__value_ = *__first; @@ -1147,6 +1153,7 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input __node_insert_multi(__cache); __cache = __next; } +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -1155,6 +1162,7 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input destroy(__cache); throw; } +#endif if (__cache != nullptr) { while (__cache->__parent_ != nullptr) @@ -1253,8 +1261,10 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) if (size() != 0) { __node_pointer __cache = __detach(); +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif while (__cache != nullptr && __t.size() != 0) { __cache->__value_ = _STD::move(__t.remove(__t.begin())->__value_); @@ -1262,6 +1272,7 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) __node_insert_multi(__cache); __cache = __next; } +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -1270,6 +1281,7 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) destroy(__cache); throw; } +#endif if (__cache != nullptr) { while (__cache->__parent_ != nullptr) diff --git a/include/exception b/include/exception index 51e83136b..772ada4ea 100644 --- a/include/exception +++ b/include/exception @@ -141,6 +141,7 @@ template<class _E> exception_ptr make_exception_ptr(_E __e) { +#ifndef _LIBCPP_NO_EXCEPTIONS try { throw __e; @@ -149,6 +150,7 @@ make_exception_ptr(_E __e) { return current_exception(); } +#endif } // nested_exception @@ -188,7 +190,9 @@ throw_with_nested (_Tp& __t, typename enable_if< >::type* = 0) #endif { +#ifndef _LIBCPP_NO_EXCEPTIONS throw __nested<typename remove_reference<_Tp>::type>(_STD::forward<_Tp>(__t)); +#endif } template <class _Tp> @@ -204,7 +208,9 @@ throw_with_nested (_Tp& __t, typename enable_if< >::type* = 0) #endif { +#ifndef _LIBCPP_NO_EXCEPTIONS throw _STD::forward<_Tp>(__t); +#endif } template <class _E> diff --git a/include/functional b/include/functional index e645a55e7..430f32553 100644 --- a/include/functional +++ b/include/functional @@ -1000,8 +1000,10 @@ public: virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _R operator()(_ArgTypes&& ...) = 0; +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const = 0; virtual const std::type_info& target_type() const = 0; +#endif }; template<class _FD, class _Alloc, class _FB> class __func; @@ -1019,8 +1021,10 @@ public: virtual void destroy(); virtual void destroy_deallocate(); virtual _R operator()(_ArgTypes&& ... __arg); +#ifndef _LIBCPP_NO_RTTI virtual const void* target(const type_info&) const; virtual const std::type_info& target_type() const; +#endif }; template<class _F, class _Alloc, class _R, class ..._ArgTypes> @@ -1066,6 +1070,8 @@ __func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...); } +#ifndef _LIBCPP_NO_RTTI + template<class _F, class _Alloc, class _R, class ..._ArgTypes> const void* __func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const @@ -1082,6 +1088,8 @@ __func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const return typeid(_F); } +#endif + } // __function template<class _R, class ..._ArgTypes> @@ -1163,10 +1171,12 @@ public: // 20.7.16.2.4, function invocation: _R operator()(_ArgTypes...) const; +#ifndef _LIBCPP_NO_RTTI // 20.7.16.2.5, function target access: const std::type_info& target_type() const; template <typename _T> _T* target(); template <typename _T> const _T* target() const; +#endif }; template<class _R, class ..._ArgTypes> @@ -1331,11 +1341,15 @@ template<class _R, class ..._ArgTypes> _R function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) throw bad_function_call(); +#endif return (*__f_)(_STD::forward<_ArgTypes>(__arg)...); } +#ifndef _LIBCPP_NO_RTTI + template<class _R, class ..._ArgTypes> const std::type_info& function<_R(_ArgTypes...)>::target_type() const @@ -1365,6 +1379,8 @@ function<_R(_ArgTypes...)>::target() const return (const _T*)__f_->target(typeid(_T)); } +#endif + template <class _R, class... _ArgTypes> inline _LIBCPP_INLINE_VISIBILITY bool diff --git a/include/locale b/include/locale index f48a75ecf..b86143e6f 100644 --- a/include/locale +++ b/include/locale @@ -3690,8 +3690,10 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: if (__r == codecvt_base::ok) return __ws; } +#ifndef _LIBCPP_NO_EXCEPTIONS if (__wide_err_string_.empty()) throw range_error("wstring_convert: from_bytes error"); +#endif return __wide_err_string_; } @@ -3776,8 +3778,10 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: return __bs; } } +#ifndef _LIBCPP_NO_EXCEPTIONS if (__byte_err_string_.empty()) throw range_error("wstring_convert: to_bytes error"); +#endif return __byte_err_string_; } diff --git a/include/map b/include/map index 3998fdf74..fd06c21d1 100644 --- a/include/map +++ b/include/map @@ -1136,8 +1136,10 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) { __node_base_pointer __parent; __node_base_pointer& __child = __find_equal_key(__parent, __k); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); +#endif return static_cast<__node_pointer>(__child)->__value_.second; } @@ -1147,8 +1149,10 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const { __node_base_const_pointer __parent; __node_base_const_pointer __child = __find_equal_key(__parent, __k); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); +#endif return static_cast<__node_const_pointer>(__child)->__value_.second; } diff --git a/include/memory b/include/memory index 3358a19f3..5aa2fadd2 100644 --- a/include/memory +++ b/include/memory @@ -2642,7 +2642,9 @@ public: long use_count() const {return __shared_count::use_count();} __shared_weak_count* lock(); +#ifndef _LIBCPP_NO_RTTI virtual const void* __get_deleter(const type_info&) const; +#endif private: virtual void __on_zero_shared_weak() = 0; }; @@ -2656,13 +2658,17 @@ public: __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a) : __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {} +#ifndef _LIBCPP_NO_RTTI virtual const void* __get_deleter(const type_info&) const; +#endif private: virtual void __on_zero_shared(); virtual void __on_zero_shared_weak(); }; +#ifndef _LIBCPP_NO_RTTI + template <class _Tp, class _Dp, class _Alloc> const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const @@ -2670,6 +2676,8 @@ __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) cons return __t == typeid(_Dp) ? &__data_.first().second() : 0; } +#endif + template <class _Tp, class _Dp, class _Alloc> void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() @@ -2834,9 +2842,11 @@ public: template <class _U> bool owner_before(weak_ptr<_U> const& __p) const {return __cntrl_ < __p.__cntrl_;} +#ifndef _LIBCPP_NO_RTTI template <class _Dp> _Dp* __get_deleter() const {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} +#endif #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -3591,6 +3601,8 @@ const_pointer_cast(const shared_ptr<_Up>& __r) return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); } +#ifndef _LIBCPP_NO_RTTI + template<class _Dp, class _Tp> inline _LIBCPP_INLINE_VISIBILITY _Dp* @@ -3599,6 +3611,8 @@ get_deleter(const shared_ptr<_Tp>& __p) return __p.template __get_deleter<_Dp>(); } +#endif + template<class _Tp> class weak_ptr { diff --git a/include/regex b/include/regex index 51ba1eaf1..be49cd294 100644 --- a/include/regex +++ b/include/regex @@ -2263,8 +2263,10 @@ public: } else { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__b.size() != 1 || __e.size() != 1) throw regex_error(regex_constants::error_collate); +#endif if (__icase_) { __b[0] = __traits_.translate_nocase(__b[0]); @@ -2894,8 +2896,10 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, case egrep: __first = __parse_egrep(__first, __last); break; +#ifndef _LIBCPP_NO_EXCEPTIONS default: throw regex_error(regex_constants::__re_err_grammar); +#endif } return __first; } @@ -2926,8 +2930,10 @@ basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, } } } +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first != __last) throw regex_error(regex_constants::__re_err_empty); +#endif } return __first; } @@ -2940,15 +2946,19 @@ basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, { __owns_one_state<_CharT>* __sa = __end_; _ForwardIterator __temp = __parse_ERE_branch(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::__re_err_empty); +#endif __first = __temp; while (__first != __last && *__first == '|') { __owns_one_state<_CharT>* __sb = __end_; __temp = __parse_ERE_branch(++__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::__re_err_empty); +#endif __push_alternation(__sa, __sb); __first = __temp; } @@ -2962,8 +2972,10 @@ basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last) { _ForwardIterator __temp = __parse_ERE_expression(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::__re_err_empty); +#endif do { __first = __temp; @@ -2998,8 +3010,10 @@ basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, unsigned __temp_count = __marked_count_; ++__open_count_; __temp = __parse_extended_reg_exp(++__temp, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last || *__temp != ')') throw regex_error(regex_constants::error_paren); +#endif __push_end_marked_subexpression(__temp_count); --__open_count_; ++__temp; @@ -3064,8 +3078,10 @@ basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, unsigned __temp_count = __marked_count_; __first = __parse_RE_expression(__temp, __last); __temp = __parse_Back_close_paren(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_paren); +#endif __push_end_marked_subexpression(__temp_count); __first = __temp; } @@ -3374,16 +3390,22 @@ basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, int __min = 0; __first = __temp; __temp = __parse_DUP_COUNT(__first, __last, __min); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_badbrace); +#endif __first = __temp; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_brace); +#endif if (*__first != ',') { __temp = __parse_Back_close_brace(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_brace); +#endif __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, true); __first = __temp; @@ -3394,14 +3416,18 @@ basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, int __max = -1; __first = __parse_DUP_COUNT(__first, __last, __max); __temp = __parse_Back_close_brace(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_brace); +#endif if (__max == -1) __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); else { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__max < __min) throw regex_error(regex_constants::error_badbrace); +#endif __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, true); } @@ -3461,11 +3487,15 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, { int __min; _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_badbrace); +#endif __first = __temp; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_brace); +#endif switch (*__first) { case '}': @@ -3479,8 +3509,11 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); break; case ',': - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_badbrace); +#endif if (*__first == '}') { ++__first; @@ -3496,14 +3529,20 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, { int __max = -1; __temp = __parse_DUP_COUNT(__first, __last, __max); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __first) throw regex_error(regex_constants::error_brace); +#endif __first = __temp; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last || *__first != '}') throw regex_error(regex_constants::error_brace); +#endif ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__max < __min) throw regex_error(regex_constants::error_badbrace); +#endif if (__grammar == ECMAScript && __first != __last && *__first == '?') { ++__first; @@ -3513,8 +3552,10 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); } break; +#ifndef _LIBCPP_NO_EXCEPTIONS default: throw regex_error(regex_constants::error_badbrace); +#endif } } break; @@ -3531,8 +3572,11 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs { if (__first != __last && *__first == '[') { - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_brack); +#endif bool __negate = false; if (*__first == '^') { @@ -3541,23 +3585,29 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs } __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); // __ml owned by *this +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_brack); +#endif if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') { __ml->__add_char(']'); ++__first; } __first = __parse_follow_list(__first, __last, __ml); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_brack); +#endif if (*__first == '-') { __ml->__add_char('-'); ++__first; } +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last || *__first != ']') throw regex_error(regex_constants::error_brack); +#endif ++__first; } return __first; @@ -3677,8 +3727,10 @@ basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, basic_string<_CharT>& __str, __bracket_expression<_CharT, _Traits>* __ml) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif switch (*__first) { case 0: @@ -3719,8 +3771,10 @@ basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif switch (*__first) { case '\\': @@ -3788,8 +3842,10 @@ basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, else __push_char(_CharT(__val)); } +#ifndef _LIBCPP_NO_EXCEPTIONS else throw regex_error(regex_constants::error_escape); +#endif return __first; } @@ -3805,14 +3861,18 @@ basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first value_type _Equal_close[2] = {'=', ']'}; _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, _Equal_close+2); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last) throw regex_error(regex_constants::error_brack); +#endif // [__first, __temp) contains all text in [= ... =] typedef typename _Traits::string_type string_type; string_type __collate_name = __traits_.lookup_collatename(__first, __temp); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__collate_name.empty()) throw regex_error(regex_constants::error_collate); +#endif string_type __equiv_name = __traits_.transform_primary(__collate_name.begin(), __collate_name.end()); @@ -3828,8 +3888,10 @@ basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first case 2: __ml->__add_digraph(__collate_name[0], __collate_name[1]); break; +#ifndef _LIBCPP_NO_EXCEPTIONS default: throw regex_error(regex_constants::error_collate); +#endif } } __first = next(__temp, 2); @@ -3848,14 +3910,18 @@ basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, value_type _Colon_close[2] = {':', ']'}; _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, _Colon_close+2); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last) throw regex_error(regex_constants::error_brack); +#endif // [__first, __temp) contains all text in [: ... :] typedef typename _Traits::char_class_type char_class_type; char_class_type __class_type = __traits_.lookup_classname(__first, __temp, __flags_ & icase); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__class_type == 0) throw regex_error(regex_constants::error_brack); +#endif __ml->__add_class(__class_type); __first = next(__temp, 2); return __first; @@ -3873,8 +3939,10 @@ basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, value_type _Dot_close[2] = {'.', ']'}; _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, _Dot_close+2); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last) throw regex_error(regex_constants::error_brack); +#endif // [__first, __temp) contains all text in [. ... .] typedef typename _Traits::string_type string_type; __col_sym = __traits_.lookup_collatename(__first, __temp); @@ -3883,8 +3951,10 @@ basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, case 1: case 2: break; +#ifndef _LIBCPP_NO_EXCEPTIONS default: throw regex_error(regex_constants::error_collate); +#endif } __first = next(__temp, 2); return __first; @@ -4022,8 +4092,10 @@ basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, __temp = __exp.__parse(++__temp, __last); __exp.__push_l_anchor(); __push_lookahead(_STD::move(__exp), false); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last || *__temp != ')') throw regex_error(regex_constants::error_paren); +#endif __first = ++__temp; } break; @@ -4034,8 +4106,10 @@ basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, __temp = __exp.__parse(++__temp, __last); __exp.__push_l_anchor(); __push_lookahead(_STD::move(__exp), true); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last || *__temp != ')') throw regex_error(regex_constants::error_paren); +#endif __first = ++__temp; } break; @@ -4071,15 +4145,20 @@ basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, break; case '(': { - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_paren); +#endif _ForwardIterator __temp = _STD::next(__first); if (__temp != __last && *__first == '?' && *__temp == ':') { ++__open_count_; __first = __parse_ecma_exp(++__temp, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last || *__first != ')') throw regex_error(regex_constants::error_paren); +#endif --__open_count_; ++__first; } @@ -4089,8 +4168,10 @@ basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, unsigned __temp_count = __marked_count_; ++__open_count_; __first = __parse_ecma_exp(__first, __last); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__first == __last || *__first != ')') throw regex_error(regex_constants::error_paren); +#endif __push_end_marked_subexpression(__temp_count); --__open_count_; ++__first; @@ -4151,8 +4232,10 @@ basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, unsigned __v = *__first - '0'; for (++__first; '0' <= *__first && *__first <= '9'; ++__first) __v = 10 * __v + *__first - '0'; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__v > mark_count()) throw regex_error(regex_constants::error_backref); +#endif __push_back_ref(__v); } } @@ -4270,31 +4353,51 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, } break; case 'u': - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif __hd = __traits_.value(*__first, 16); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__hd == -1) throw regex_error(regex_constants::error_escape); +#endif __sum = 16 * __sum + __hd; - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif __hd = __traits_.value(*__first, 16); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__hd == -1) throw regex_error(regex_constants::error_escape); +#endif __sum = 16 * __sum + __hd; // drop through case 'x': - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif __hd = __traits_.value(*__first, 16); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__hd == -1) throw regex_error(regex_constants::error_escape); +#endif __sum = 16 * __sum + __hd; - if (++__first == __last) + ++__first; +#ifndef _LIBCPP_NO_EXCEPTIONS + if (__first == __last) throw regex_error(regex_constants::error_escape); +#endif __hd = __traits_.value(*__first, 16); +#ifndef _LIBCPP_NO_EXCEPTIONS if (__hd == -1) throw regex_error(regex_constants::error_escape); +#endif __sum = 16 * __sum + __hd; if (__str) *__str = _CharT(__sum); @@ -4311,8 +4414,10 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, __push_char(*__first); ++__first; } +#ifndef _LIBCPP_NO_EXCEPTIONS else if (__str) throw regex_error(regex_constants::error_escape); +#endif break; } } @@ -5206,8 +5311,11 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma( __states.pop_back(); break; default: +#ifndef _LIBCPP_NO_EXCEPTIONS throw regex_error(regex_constants::__re_err_unknown); +#endif break; + } } while (!__states.empty()); } @@ -5274,7 +5382,9 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( __states.pop_back(); break; default: +#ifndef _LIBCPP_NO_EXCEPTIONS throw regex_error(regex_constants::__re_err_unknown); +#endif break; } } while (!__states.empty()); @@ -5354,7 +5464,9 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( __states.pop_back(); break; default: +#ifndef _LIBCPP_NO_EXCEPTIONS throw regex_error(regex_constants::__re_err_unknown); +#endif break; } } while (!__states.empty()); diff --git a/lib/buildit b/lib/buildit index 44e7c3a06..89b38b619 100755 --- a/lib/buildit +++ b/lib/buildit @@ -21,7 +21,7 @@ case $TRIPLE in *-apple-*) if [ -z $RC_BUILDIT ] then - RC_CFLAGS="-arch i386 -arch x86_64" + RC_CFLAGS="-arch i386 -arch x86_64 -fno-exceptions -fno-rtti" fi SOEXT=dylib LDSHARED_FLAGS="-o libc++.1.dylib \ diff --git a/src/exception.cpp b/src/exception.cpp index 9bed6f49b..7c5211534 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -54,15 +54,21 @@ std::set_terminate(std::terminate_handler func) throw() void std::terminate() { - try { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif (*__terminate_handler)(); // handler should not return ::abort (); +#ifndef _LIBCPP_NO_EXCEPTIONS } - catch (...) { + catch (...) + { // handler should not throw exception ::abort (); } +#endif } diff --git a/src/ios.cpp b/src/ios.cpp index eb597bfbd..4139cd4c9 100644 --- a/src/ios.cpp +++ b/src/ios.cpp @@ -260,8 +260,10 @@ ios_base::clear(iostate state) __rdstate_ = state; else __rdstate_ = state | badbit; +#ifndef _LIBCPP_NO_EXCEPTIONS if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0) throw failure("ios_base::clear"); +#endif } // init @@ -300,23 +302,31 @@ ios_base::copyfmt(const ios_base& rhs) if (__event_cap_ < rhs.__event_size_) { new_callbacks.reset((event_callback*)malloc(sizeof(event_callback) * rhs.__event_size_)); +#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_callbacks) throw bad_alloc(); +#endif new_ints.reset((int*)malloc(sizeof(int) * rhs.__event_size_)); +#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_ints) throw bad_alloc(); +#endif } if (__iarray_cap_ < rhs.__iarray_size_) { new_longs.reset((long*)malloc(sizeof(long) * rhs.__iarray_size_)); +#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_longs) throw bad_alloc(); +#endif } if (__parray_cap_ < rhs.__parray_size_) { new_pointers.reset((void**)malloc(sizeof(void*) * rhs.__parray_size_)); +#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_pointers) throw bad_alloc(); +#endif } // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_ __fmtflags_ = rhs.__fmtflags_; @@ -417,16 +427,20 @@ void ios_base::__set_badbit_and_consider_rethrow() { __rdstate_ |= badbit; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__exceptions_ & badbit) throw; +#endif } void ios_base::__set_failbit_and_consider_rethrow() { __rdstate_ |= failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS if (__exceptions_ & failbit) throw; +#endif } bool diff --git a/src/locale.cpp b/src/locale.cpp index e0d97dc67..93d881e5f 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -132,8 +132,10 @@ locale::__imp::__imp(const string& name, size_t refs) name_(name), facets_(N) { +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif facets_ = locale::classic().__locale_->facets_; for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) @@ -158,6 +160,7 @@ locale::__imp::__imp(const string& name, size_t refs) install(new time_put_byname<wchar_t>(name_)); install(new messages_byname<char>(name_)); install(new messages_byname<wchar_t>(name_)); +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -166,6 +169,7 @@ locale::__imp::__imp(const string& name, size_t refs) facets_[i]->__release_shared(); throw; } +#endif } locale::__imp::__imp(const __imp& other) @@ -186,8 +190,10 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c) for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) facets_[i]->__add_shared(); +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif if (c & locale::collate) { install(new collate_byname<char>(name)); @@ -226,6 +232,7 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c) install(new messages_byname<char>(name)); install(new messages_byname<wchar_t>(name)); } +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -234,6 +241,7 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c) facets_[i]->__release_shared(); throw; } +#endif } template<class F> @@ -253,8 +261,10 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c) for (unsigned i = 0; i < facets_.size(); ++i) if (facets_[i]) facets_[i]->__add_shared(); +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif if (c & locale::collate) { install_from<_STD::collate<char> >(one); @@ -301,6 +311,7 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c) install_from<_STD::messages<char> >(one); install_from<_STD::messages<wchar_t> >(one); } +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -309,6 +320,7 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c) facets_[i]->__release_shared(); throw; } +#endif } locale::__imp::__imp(const __imp& other, facet* f, long id) @@ -346,8 +358,10 @@ locale::__imp::install(facet* f, long id) const locale::facet* locale::__imp::use_facet(long id) const { +#ifndef _LIBCPP_NO_EXCEPTIONS if (!has_facet(id)) throw bad_cast(); +#endif return facets_[id]; } @@ -414,8 +428,12 @@ locale::operator=(const locale& other) throw() } locale::locale(const char* name) +#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(name) : throw runtime_error("locale constructed with null")) +#else + : __locale_(new __imp(name)) +#endif { __locale_->__add_shared(); } @@ -427,8 +445,12 @@ locale::locale(const string& name) } locale::locale(const locale& other, const char* name, category c) +#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(*other.__locale_, name, c) : throw runtime_error("locale constructed with null")) +#else + : __locale_(new __imp(*other.__locale_, name, c)) +#endif { __locale_->__add_shared(); } @@ -545,18 +567,22 @@ collate_byname<char>::collate_byname(const char* n, size_t refs) : collate<char>(refs), __l(newlocale(LC_ALL_MASK, n, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("collate_byname<char>::collate_byname" " failed to construct for " + string(n)); +#endif } collate_byname<char>::collate_byname(const string& name, size_t refs) : collate<char>(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("collate_byname<char>::collate_byname" " failed to construct for " + name); +#endif } collate_byname<char>::~collate_byname() @@ -593,18 +619,22 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs) : collate<wchar_t>(refs), __l(newlocale(LC_ALL_MASK, n, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)" " failed to construct for " + string(n)); +#endif } collate_byname<wchar_t>::collate_byname(const string& name, size_t refs) : collate<wchar_t>(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)" " failed to construct for " + name); +#endif } collate_byname<wchar_t>::~collate_byname() @@ -828,18 +858,22 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs) : ctype<char>(0, false, refs), __l(newlocale(LC_ALL_MASK, name, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("ctype_byname<char>::ctype_byname" " failed to construct for " + string(name)); +#endif } ctype_byname<char>::ctype_byname(const string& name, size_t refs) : ctype<char>(0, false, refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("ctype_byname<char>::ctype_byname" " failed to construct for " + name); +#endif } ctype_byname<char>::~ctype_byname() @@ -881,18 +915,22 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs) : ctype<wchar_t>(refs), __l(newlocale(LC_ALL_MASK, name, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("ctype_byname<wchar_t>::ctype_byname" " failed to construct for " + string(name)); +#endif } ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs) : ctype<wchar_t>(refs), __l(newlocale(LC_ALL_MASK, name.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("ctype_byname<wchar_t>::ctype_byname" " failed to construct for " + name); +#endif } ctype_byname<wchar_t>::~ctype_byname() @@ -1092,9 +1130,11 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs) : locale::facet(refs), __l(newlocale(LC_ALL_MASK, nm, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__l == 0) throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname" " failed to construct for " + string(nm)); +#endif } codecvt<wchar_t, char, mbstate_t>::~codecvt() @@ -3832,9 +3872,11 @@ numpunct_byname<char>::__init(const char* nm) if (strcmp(nm, "C") != 0) { unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("numpunct_byname<char>::numpunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; @@ -3869,9 +3911,11 @@ numpunct_byname<wchar_t>::__init(const char* nm) if (strcmp(nm, "C") != 0) { unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("numpunct_byname<char>::numpunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->decimal_point) __decimal_point_ = *lc->decimal_point; @@ -4274,17 +4318,21 @@ __time_get_c_storage<wchar_t>::__r() const __time_get::__time_get(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__loc_ == 0) throw runtime_error("time_get_byname" " failed to construct for " + string(nm)); +#endif } __time_get::__time_get(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__loc_ == 0) throw runtime_error("time_get_byname" " failed to construct for " + nm); +#endif } __time_get::~__time_get() @@ -4921,17 +4969,21 @@ __time_get_storage<wchar_t>::__do_date_order() const __time_put::__time_put(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__loc_ == 0) throw runtime_error("time_put_byname" " failed to construct for " + string(nm)); +#endif } __time_put::__time_put(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (__loc_ == 0) throw runtime_error("time_put_byname" " failed to construct for " + nm); +#endif } __time_put::~__time_put() @@ -5210,9 +5262,11 @@ moneypunct_byname<char, false>::init(const char* nm) { typedef moneypunct<char, false> base; unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; @@ -5246,9 +5300,11 @@ moneypunct_byname<char, true>::init(const char* nm) { typedef moneypunct<char, true> base; unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = *lc->mon_decimal_point; @@ -5282,9 +5338,11 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) { typedef moneypunct<wchar_t, false> base; unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); @@ -5341,9 +5399,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) { typedef moneypunct<wchar_t, true> base; unique_ptr<_xlocale, int(*)(locale_t)> loc(newlocale(LC_ALL_MASK, nm, 0), freelocale); +#ifndef _LIBCPP_NO_EXCEPTIONS if (loc == 0) throw runtime_error("moneypunct_byname" " failed to construct for " + string(nm)); +#endif lconv* lc = localeconv_l(loc.get()); if (*lc->mon_decimal_point) __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point); @@ -5398,7 +5458,9 @@ void __do_nothing(void*) {} void __throw_runtime_error(const char* msg) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw runtime_error(msg); +#endif } template class collate<char>; diff --git a/src/memory.cpp b/src/memory.cpp index f35b838b6..2caa12b3a 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -107,12 +107,16 @@ __shared_weak_count::lock() return 0; } +#ifndef _LIBCPP_NO_RTTI + const void* __shared_weak_count::__get_deleter(const type_info&) const { return 0; } +#endif + void declare_reachable(void*) { diff --git a/src/mutex.cpp b/src/mutex.cpp index 1f8160d0a..fa1e7a0e8 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -220,8 +220,10 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) pthread_cond_wait(&cv, &mut); if (flag == 0) { +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif flag = 1; pthread_mutex_unlock(&mut); func(arg); @@ -229,6 +231,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) flag = ~0ul; pthread_mutex_unlock(&mut); pthread_cond_broadcast(&cv); +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { @@ -238,6 +241,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) pthread_cond_broadcast(&cv); throw; } +#endif } else pthread_mutex_unlock(&mut); diff --git a/src/new.cpp b/src/new.cpp index 964d87b89..f751f171f 100644 --- a/src/new.cpp +++ b/src/new.cpp @@ -42,7 +42,11 @@ operator new(std::size_t size) throw (std::bad_alloc) if (__new_handler) __new_handler(); else +#ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); +#else + break; +#endif } return p; } @@ -52,13 +56,17 @@ void* operator new(size_t size, const std::nothrow_t&) throw() { void* p = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif p = ::operator new(size); +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } +#endif return p; } @@ -74,13 +82,17 @@ void* operator new[](size_t size, const std::nothrow_t& nothrow) throw() { void* p = 0; +#ifndef _LIBCPP_NO_EXCEPTIONS try { +#endif p = ::operator new[](size); +#ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } +#endif return p; } @@ -162,7 +174,9 @@ bad_array_new_length::what() const throw() void __throw_bad_alloc() { +#ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); +#endif } } // std diff --git a/src/string.cpp b/src/string.cpp index 819935c07..946e915af 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -79,9 +79,11 @@ stoi(const string& str, size_t* idx, int base) ptr = const_cast<char*>(p); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoi: no conversion"); throw out_of_range("stoi: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -98,9 +100,11 @@ stoi(const wstring& str, size_t* idx, int base) ptr = const_cast<wchar_t*>(p); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoi: no conversion"); throw out_of_range("stoi: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -115,9 +119,11 @@ stol(const string& str, size_t* idx, int base) long r = strtol(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stol: no conversion"); throw out_of_range("stol: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -132,9 +138,11 @@ stol(const wstring& str, size_t* idx, int base) long r = wcstol(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stol: no conversion"); throw out_of_range("stol: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -149,9 +157,11 @@ stoul(const string& str, size_t* idx, int base) unsigned long r = strtoul(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoul: no conversion"); throw out_of_range("stoul: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -166,9 +176,11 @@ stoul(const wstring& str, size_t* idx, int base) unsigned long r = wcstoul(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoul: no conversion"); throw out_of_range("stoul: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -183,9 +195,11 @@ stoll(const string& str, size_t* idx, int base) long long r = strtoll(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoll: no conversion"); throw out_of_range("stoll: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -200,9 +214,11 @@ stoll(const wstring& str, size_t* idx, int base) long long r = wcstoll(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoll: no conversion"); throw out_of_range("stoll: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -217,9 +233,11 @@ stoull(const string& str, size_t* idx, int base) unsigned long long r = strtoull(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoull: no conversion"); throw out_of_range("stoull: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -234,9 +252,11 @@ stoull(const wstring& str, size_t* idx, int base) unsigned long long r = wcstoull(p, &ptr, base); if (ptr == p) { +#ifndef _LIBCPP_NO_EXCEPTIONS if (r == 0) throw invalid_argument("stoull: no conversion"); throw out_of_range("stoull: out of range"); +#endif } if (idx) *idx = static_cast<size_t>(ptr - p); @@ -252,10 +272,12 @@ stof(const string& str, size_t* idx) errno = 0; double r = strtod(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stof: out of range"); if (ptr == p) throw invalid_argument("stof: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return static_cast<float>(r); @@ -270,10 +292,12 @@ stof(const wstring& str, size_t* idx) errno = 0; double r = wcstod(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stof: out of range"); if (ptr == p) throw invalid_argument("stof: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return static_cast<float>(r); @@ -288,10 +312,12 @@ stod(const string& str, size_t* idx) errno = 0; double r = strtod(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stod: out of range"); if (ptr == p) throw invalid_argument("stod: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return r; @@ -306,10 +332,12 @@ stod(const wstring& str, size_t* idx) errno = 0; double r = wcstod(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stod: out of range"); if (ptr == p) throw invalid_argument("stod: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return r; @@ -324,10 +352,12 @@ stold(const string& str, size_t* idx) errno = 0; long double r = strtold(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stold: out of range"); if (ptr == p) throw invalid_argument("stold: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return r; @@ -342,10 +372,12 @@ stold(const wstring& str, size_t* idx) errno = 0; long double r = wcstold(p, &ptr); swap(errno, errno_save); +#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) throw out_of_range("stold: out of range"); if (ptr == p) throw invalid_argument("stold: no conversion"); +#endif if (idx) *idx = static_cast<size_t>(ptr - p); return r; diff --git a/src/system_error.cpp b/src/system_error.cpp index 3c1f0003a..1ca85cb2f 100644 --- a/src/system_error.cpp +++ b/src/system_error.cpp @@ -193,7 +193,9 @@ system_error::~system_error() throw() void __throw_system_error(int ev, const char* what_arg) { +#ifndef _LIBCPP_NO_EXCEPTIONS throw system_error(error_code(ev, system_category()), what_arg); +#endif } _LIBCPP_END_NAMESPACE_STD diff --git a/src/thread.cpp b/src/thread.cpp index f2db6d51b..de53f78ef 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -24,8 +24,10 @@ void thread::join() { int ec = pthread_join(__t_, 0); +#ifndef _LIBCPP_NO_EXCEPTIONS if (ec) throw system_error(error_code(ec, system_category()), "thread::join failed"); +#endif __t_ = 0; } @@ -39,8 +41,10 @@ thread::detach() if (ec == 0) __t_ = 0; } +#ifndef _LIBCPP_NO_EXCEPTIONS if (ec) throw system_error(error_code(ec, system_category()), "thread::detach failed"); +#endif } unsigned |