From 19bc9ea480b60b607a3e303f20c7a3a2ea553369 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 31 Jul 2020 12:56:36 -0400 Subject: [PATCH] [libc++] Avoid including from Block.h is a pretty common name, which can lead to nasty collisions with user provided headers. Since we're only getting a few simple declarations from the header, it's better to declare them manually than to include the header. rdar://66384326 Differential Revision: https://reviews.llvm.org/D85035 --- libcxx/include/functional | 13 ++++++------- .../libcxx/utilities/function.objects/func.blocks.sh.cpp | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libcxx/include/functional b/libcxx/include/functional index 3e94253..9a0ca96 100644 --- a/libcxx/include/functional +++ b/libcxx/include/functional @@ -508,10 +508,6 @@ POLICY: For non-variadic implementations, the number of arguments is limited #include <__functional_base> -#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC) -#include -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -2257,6 +2253,9 @@ template class __policy_func<_Rp(_ArgTypes...)> #if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC) +extern "C" void *_Block_copy(const void *); +extern "C" void _Block_release(const void *); + template class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> @@ -2267,14 +2266,14 @@ class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> public: _LIBCPP_INLINE_VISIBILITY explicit __func(__block_type const& __f) - : __f_(__f ? Block_copy(__f) : (__block_type)0) + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) { } // [TODO] add && to save on a retain _LIBCPP_INLINE_VISIBILITY explicit __func(__block_type __f, const _Alloc& /* unused */) - : __f_(__f ? Block_copy(__f) : (__block_type)0) + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) { } virtual __base<_Rp(_ArgTypes...)>* __clone() const { @@ -2291,7 +2290,7 @@ public: virtual void destroy() _NOEXCEPT { if (__f_) - Block_release(__f_); + _Block_release(__f_); __f_ = 0; } diff --git a/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp b/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp index 33c1165..9a8e938 100644 --- a/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp +++ b/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include "test_macros.h" #include "count_new.h" -- 2.7.4