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

Unified Diff: base/memory/scoped_ptr.h

Issue 610533003: Allow custom deleters to opt out of self reset checks for scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a header + guard Created 6 years, 3 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 | base/memory/scoped_ptr_unittest.cc » ('j') | base/memory/scoped_ptr_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/scoped_ptr.h
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index 81b4a6239386cc3d556810aa1fbc6c0526de9b12..b4ed87117fac44e8265ca6d628e0d0f4fdfb1d3c 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -101,6 +101,10 @@
#include "base/move.h"
#include "base/template_util.h"
+#if defined(OS_POSIX)
+#include <unistd.h> // For _exit() on POSIX
+#endif
+
namespace base {
namespace subtle {
@@ -184,6 +188,17 @@ template <typename T> struct IsNotRefCounted {
};
};
+template <typename T>
+struct ShouldAbortOnSelfReset {
+ template <typename U>
+ static NoType Test(const typename U::AllowSelfReset*);
+
+ template <typename U>
+ static YesType Test(...);
+
+ static const bool value = sizeof(Test<T>(0)) == sizeof(YesType);
+};
+
// Minimal implementation of the core logic of scoped_ptr, suitable for
// reuse in both scoped_ptr and its specializations.
template <class T, class D>
@@ -222,9 +237,10 @@ class scoped_ptr_impl {
}
void reset(T* p) {
- // This is a self-reset, which is no longer allowed: http://crbug.com/162971
- if (p != nullptr && p == data_.ptr)
- abort();
+ // This is a self-reset, which is no longer allowed for default deleters:
+ // https://crbug.com/162971
+ if (ShouldAbortOnSelfReset<D>::value && p != nullptr && p == data_.ptr)
+ _exit(1);
// Note that running data_.ptr = p can lead to undefined behavior if
// get_deleter()(get()) deletes this. In order to prevent this, reset()
« no previous file with comments | « no previous file | base/memory/scoped_ptr_unittest.cc » ('j') | base/memory/scoped_ptr_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698