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

Unified Diff: base/mac/scoped_block.h

Issue 1855483004: [iOS/OS X] Allow base::scoped_nsobject<> to be used when ARC is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing copy constructor from scoped_nsobject<subclass> to scoped_nsobject<class> Created 4 years, 6 months 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 | « base/mac/bind_objc_block_unittest_arc.mm ('k') | base/mac/scoped_nsobject.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/scoped_block.h
diff --git a/base/mac/scoped_block.h b/base/mac/scoped_block.h
index bc2688f13ac064d9c1acfd37fedc37d72c52b458..8199677f1506061dcdc644de3c2e726e6bd0ce6d 100644
--- a/base/mac/scoped_block.h
+++ b/base/mac/scoped_block.h
@@ -9,6 +9,12 @@
#include "base/mac/scoped_typeref.h"
+#if defined(__has_feature) && __has_feature(objc_arc)
+#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) (__bridge TYPE)(VALUE)
+#else
+#define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) VALUE
+#endif
+
namespace base {
namespace mac {
@@ -17,8 +23,13 @@ namespace internal {
template <typename B>
struct ScopedBlockTraits {
static B InvalidValue() { return nullptr; }
- static B Retain(B block) { return Block_copy(block); }
- static void Release(B block) { Block_release(block); }
+ static B Retain(B block) {
+ return BASE_MAC_BRIDGE_CAST(
+ B, Block_copy(BASE_MAC_BRIDGE_CAST(const void*, block)));
+ }
+ static void Release(B block) {
+ Block_release(BASE_MAC_BRIDGE_CAST(const void*, block));
+ }
};
} // namespace internal
@@ -32,4 +43,6 @@ using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
} // namespace mac
} // namespace base
+#undef BASE_MAC_BRIDGE_CAST
+
#endif // BASE_MAC_SCOPED_BLOCK_H_
« no previous file with comments | « base/mac/bind_objc_block_unittest_arc.mm ('k') | base/mac/scoped_nsobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698