Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2183)

Unified Diff: base/mac/bind_objc_block.h

Issue 2522943003: [iOS/ARC] Fix a violation of ODR in base::BindBlock under ARC. (Closed)
Patch Set: Use EXPECT_NSEQ instead of EXPECT_EQ/EXPECT_TRUE. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/mac/bind_objc_block_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/bind_objc_block.h
diff --git a/base/mac/bind_objc_block.h b/base/mac/bind_objc_block.h
index 2434d444f5c4b6c275fad2161c75c9de63f93b85..9a481ed987d5bd72e3619f006802b5ccfaee3d8d 100644
--- a/base/mac/bind_objc_block.h
+++ b/base/mac/bind_objc_block.h
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/callback_forward.h"
+#include "base/compiler_specific.h"
#include "base/mac/scoped_block.h"
// BindBlock builds a callback from an Objective-C block. Example usages:
@@ -27,6 +28,13 @@
// seven total arguments, and the bound block itself is used as one of these
// arguments, so functionally the templates are limited to binding blocks with
// zero through six arguments.
+//
+// For code compiled with ARC (automatic reference counting), use BindBlockArc.
+// This is because the method has a different implementation (to avoid over-
+// retaining the block) and need to have a different name not to break the ODR
+// (one definition rule). Another subtle difference is that the implementation
+// will call a different version of ScopedBlock constructor thus the linker must
+// not merge both functions.
namespace base {
@@ -41,6 +49,8 @@ R RunBlock(base::mac::ScopedBlock<R(^)(Args...)> block, Args... args) {
} // namespace internal
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+
// Construct a callback from an objective-C block with up to six arguments (see
// note above).
template<typename R, typename... Args>
@@ -52,6 +62,18 @@ base::Callback<R(Args...)> BindBlock(R(^block)(Args...)) {
block)));
}
+#else
+
+// Construct a callback from an objective-C block with up to six arguments (see
+// note above).
+template <typename R, typename... Args>
+base::Callback<R(Args...)> BindBlockArc(R (^block)(Args...)) {
+ return base::Bind(&base::internal::RunBlock<R, Args...>,
+ base::mac::ScopedBlock<R (^)(Args...)>(block));
+}
+
+#endif
+
} // namespace base
#endif // BASE_MAC_BIND_OBJC_BLOCK_H_
« no previous file with comments | « no previous file | base/mac/bind_objc_block_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698