[libcxx-commits] [libcxx] 19bc9ea - [libc++] Avoid including <Block.h> from <functional>
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 31 11:22:34 PDT 2020
Author: Louis Dionne
Date: 2020-07-31T14:22:28-04:00
New Revision: 19bc9ea480b60b607a3e303f20c7a3a2ea553369
URL: https://github.com/llvm/llvm-project/commit/19bc9ea480b60b607a3e303f20c7a3a2ea553369
DIFF: https://github.com/llvm/llvm-project/commit/19bc9ea480b60b607a3e303f20c7a3a2ea553369.diff
LOG: [libc++] Avoid including <Block.h> from <functional>
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
Added:
Modified:
libcxx/include/functional
libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp
Removed:
################################################################################
diff --git a/libcxx/include/functional b/libcxx/include/functional
index 3e9425320fc3..9a0ca96c4611 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 <Block.h>
-#endif
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
@@ -2257,6 +2253,9 @@ template <class _Rp, class... _ArgTypes> 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 _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
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 33c11651f12f..9a8e9389426a 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 <cstdlib>
#include <cassert>
+#include <Block.h>
+
#include "test_macros.h"
#include "count_new.h"
More information about the libcxx-commits
mailing list