Index: base/mac/scoped_nsobject.h |
diff --git a/base/mac/scoped_nsobject.h b/base/mac/scoped_nsobject.h |
index 04c5877db718e5926584fda5c07eeede5f7078c2..e4fc5c4b3ed5845c18478cf1c15192bf73d0cc6a 100644 |
--- a/base/mac/scoped_nsobject.h |
+++ b/base/mac/scoped_nsobject.h |
@@ -15,7 +15,9 @@ |
#include "base/compiler_specific.h" |
#include "base/mac/scoped_typeref.h" |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
@class NSAutoreleasePool; |
+#endif |
namespace base { |
@@ -41,11 +43,24 @@ namespace base { |
namespace internal { |
+id ScopedNSProtocolTraitsRetain(__unsafe_unretained id obj) |
+ __attribute((ns_returns_not_retained)); |
+id ScopedNSProtocolTraitsAutoRelease(__unsafe_unretained id obj) |
+ __attribute((ns_returns_not_retained)); |
+void ScopedNSProtocolTraitsRelease(__unsafe_unretained id obj); |
+ |
template <typename NST> |
struct ScopedNSProtocolTraits { |
- static NST InvalidValue() { return nil; } |
- static NST Retain(NST nst) { return [nst retain]; } |
- static void Release(NST nst) { [nst release]; } |
+ static NST InvalidValue() __attribute((ns_returns_not_retained)) { |
Nico
2016/04/04 17:53:45
is this one needed? [nil retain] is a noop, right?
|
+ return nil; |
+ } |
+ static NST Retain(__unsafe_unretained NST nst) |
Nico
2016/04/04 17:53:45
`Retain() returns_not_retained` needs a comment on
|
+ __attribute((ns_returns_not_retained)) { |
+ return ScopedNSProtocolTraitsRetain(nst); |
+ } |
+ static void Release(__unsafe_unretained NST nst) { |
+ ScopedNSProtocolTraitsRelease(nst); |
+ } |
}; |
} // namespace internal |
@@ -58,7 +73,9 @@ class scoped_nsprotocol |
internal::ScopedNSProtocolTraits<NST>>::ScopedTypeRef; |
// Shift reference to the autorelease pool to be released later. |
- NST autorelease() { return [this->release() autorelease]; } |
+ NST autorelease() __attribute((ns_returns_not_retained)) { |
+ return internal::ScopedNSProtocolTraitsAutoRelease(this->release()); |
+ } |
}; |
// Free functions |
@@ -82,8 +99,10 @@ class scoped_nsobject : public scoped_nsprotocol<NST*> { |
public: |
using scoped_nsprotocol<NST*>::scoped_nsprotocol; |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
static_assert(std::is_same<NST, NSAutoreleasePool>::value == false, |
"Use ScopedNSAutoreleasePool instead"); |
+#endif |
}; |
// Specialization to make scoped_nsobject<id> work. |