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

Unified Diff: base/scoped_nsobject.h

Issue 292011: Fixes up scoped_nsobject so that you don't accidentally release the object... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/scoped_nsobject.h
===================================================================
--- base/scoped_nsobject.h (revision 29378)
+++ base/scoped_nsobject.h (working copy)
@@ -18,6 +18,12 @@
// caller must own the object it gives to scoped_nsobject<>, and relinquishes
// an ownership claim to that object. scoped_nsobject<> does not call
// -retain.
+//
+// scoped_nsobject<> is not to be used for NSAutoreleasePools. For
+// NSAutoreleasePools use ScopedNSAutoreleasePool from
+// scoped_nsautorelease_pool.h instead.
+// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
+// time with a template specialization (see below).
template<typename NST>
class scoped_nsobject {
public:
@@ -32,6 +38,11 @@
}
void reset(NST* object = nil) {
+ // We intentionally do not check that object != object_ as the caller must
+ // already have an ownership claim over whatever it gives to scoped_nsobject
+ // and scoped_cftyperef, whether it's in the constructor or in a call to
+ // reset(). In either case, it relinquishes that claim and the scoper
+ // assumes it.
[object_ release];
object_ = object;
}
@@ -88,6 +99,11 @@
}
void reset(id object = nil) {
+ // We intentionally do not check that object != object_ as the caller must
+ // already have an ownership claim over whatever it gives to scoped_nsobject
+ // and scoped_cftyperef, whether it's in the constructor or in a call to
+ // reset(). In either case, it relinquishes that claim and the scoper
+ // assumes it.
[object_ release];
object_ = object;
}
@@ -129,4 +145,14 @@
DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
};
+// Do not use scoped_nsobject for NSAutoreleasePools, use
+// ScopedNSAutoreleasePool instead. This is a compile time check. See details
+// at top of header.
+template<>
+class scoped_nsobject<NSAutoreleasePool> {
+ private:
+ explicit scoped_nsobject(NSAutoreleasePool* object = nil);
+ DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
+};
+
#endif // BASE_SCOPED_NSOBJECT_H_
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698