diff options
-rw-r--r-- | PRESUBMIT.py | 26 | ||||
-rwxr-xr-x | PRESUBMIT_test.py | 39 | ||||
-rw-r--r-- | base/memory/scoped_ptr.h | 4 | ||||
-rw-r--r-- | base/move.h | 57 | ||||
-rw-r--r-- | base/scoped_generic.h | 2 | ||||
-rw-r--r-- | mojo/edk/embedder/scoped_platform_handle.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/associated_interface_ptr.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/associated_interface_ptr_info.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/associated_interface_request.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/interface_ptr.h | 2 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h | 3 | ||||
-rw-r--r-- | third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h | 2 |
12 files changed, 27 insertions, 116 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 294ee17..52e3b62 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -1537,31 +1537,6 @@ def _CheckSingletonInHeaders(input_api, output_api): return [] -def _CheckBaseMacrosInHeaders(input_api, output_api): - """Check for base/macros.h if DISALLOW_* macro is used.""" - - disallows = ('DISALLOW_ASSIGN', 'DISALLOW_COPY', 'DISALLOW_EVIL') - macros = '#include "base/macros.h"' - basictypes = '#include "base/basictypes.h"' - - files = [] - for f in input_api.AffectedSourceFiles(None): - if not f.LocalPath().endswith('.h'): - continue - for line_num, line in f.ChangedContents(): - if line.lstrip().startswith('//'): # Strip C++ comment. - continue - if any(d in line for d in disallows): - contents = input_api.ReadFile(f) - if not (macros in contents or basictypes in contents): - files.append(f) - break - - msg = ('The following files appear to be using DISALLOW_* macros.\n' - 'Please #include "base/macros.h" in them.') - return [output_api.PresubmitError(msg, files)] if files else [] - - _DEPRECATED_CSS = [ # Values ( "-webkit-box", "flex" ), @@ -1693,7 +1668,6 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckForCopyrightedCode(input_api, output_api)) results.extend(_CheckForWindowsLineEndings(input_api, output_api)) results.extend(_CheckSingletonInHeaders(input_api, output_api)) - results.extend(_CheckBaseMacrosInHeaders(input_api, output_api)) if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): results.extend(input_api.canned_checks.RunUnitTestsInDirectory( diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index e488c94..6b83350 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -416,45 +416,6 @@ class CheckSingletonInHeadersTest(unittest.TestCase): self.assertEqual(0, len(warnings)) -class CheckBaseMacrosInHeadersTest(unittest.TestCase): - def _make_h(self, macro, header, line_prefix=''): - return (""" -#include "base/%s.h" - -class Thing { - private: -%sDISALLOW_%s(Thing); -}; -""" % (macro, line_prefix, header)).splitlines() - - def testBaseMacrosInHeadersBad(self): - mock_input_api = MockInputApi() - mock_input_api.files = [ - MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), - MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), - MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), - MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')), - ] - warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, - MockOutputApi()) - self.assertEqual(1, len(warnings)) - self.assertEqual(4, len(warnings[0].items)) - - def testBaseMacrosInHeadersGood(self): - mock_input_api = MockInputApi() - mock_input_api.files = [ - MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), - MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), - MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), - MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), - MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', '//')), - MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', ' //')), - ] - warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, - MockOutputApi()) - self.assertEqual(0, len(warnings)) - - class InvalidOSMacroNamesTest(unittest.TestCase): def testInvalidOSMacroNames(self): lines = ['#if defined(OS_WINDOWS)', diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h index 0120f89..269c5a3 100644 --- a/base/memory/scoped_ptr.h +++ b/base/memory/scoped_ptr.h @@ -238,7 +238,7 @@ class scoped_ptr_impl { // types. template <class T, class D = std::default_delete<T>> class scoped_ptr { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_ptr) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr) static_assert(base::internal::IsNotRefCounted<T>::value, "T is a refcounted type and needs a scoped_refptr"); @@ -403,7 +403,7 @@ class scoped_ptr { template <class T, class D> class scoped_ptr<T[], D> { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(scoped_ptr) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(scoped_ptr) public: // The element and deleter types. diff --git a/base/move.h b/base/move.h index 6743eb7..91c91df 100644 --- a/base/move.h +++ b/base/move.h @@ -9,50 +9,27 @@ #include "base/compiler_specific.h" -// Macro with the boilerplate that makes a type move-only in C++11. -// -// USAGE -// -// This macro should be used instead of DISALLOW_COPY_AND_ASSIGN to create -// a "move-only" type. Unlike DISALLOW_COPY_AND_ASSIGN, this macro should be -// the first line in a class declaration. -// -// A class using this macro must call .Pass() (or somehow be an r-value already) -// before it can be: -// -// * Passed as a function argument -// * Used as the right-hand side of an assignment -// * Returned from a function -// -// Each class will still need to define their own move constructor and move -// operator= to make this useful. Here's an example of the macro, the move -// constructor, and the move operator= from a hypothetical scoped_ptr class: -// -// template <typename T> -// class scoped_ptr { -// MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(type); -// public: -// scoped_ptr(scoped_ptr&& other) : ptr_(other.release()) { } -// scoped_ptr& operator=(scoped_ptr&& other) { -// reset(other.release()); -// return *this; -// } -// }; -// +// TODO(crbug.com/566182): DEPRECATED! +// Use DISALLOW_COPY_AND_ASSIGN instead, or if your type will be used in +// Callbacks, use DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND instead. +#define MOVE_ONLY_TYPE_FOR_CPP_03(type) \ + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(type) + +// A macro to disallow the copy constructor and copy assignment functions. +// This should be used in the private: declarations for a class. // -// WHY HAVE typedef void MoveOnlyTypeForCPP03 +// Use this macro instead of DISALLOW_COPY_AND_ASSIGN if you want to pass +// ownership of the type through a base::Callback without heap-allocating it +// into a scoped_ptr. The class must define a move constructor and move +// assignment operator to make this work. // -// Callback<>/Bind() needs to understand movable-but-not-copyable semantics -// to call .Pass() appropriately when it is expected to transfer the value. -// The cryptic typedef MoveOnlyTypeForCPP03 is added to make this check -// easy and automatic in helper templates for Callback<>/Bind(). +// This version of the macro adds a Pass() function and a cryptic +// MoveOnlyTypeForCPP03 typedef for the base::Callback implementation to use. // See IsMoveOnlyType template and its usage in base/callback_internal.h // for more details. - -#define MOVE_ONLY_TYPE_FOR_CPP_03(type) \ - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(type) - -#define MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(type) \ +// TODO(crbug.com/566182): Remove this macro and use DISALLOW_COPY_AND_ASSIGN +// everywhere instead. +#define DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(type) \ private: \ type(const type&) = delete; \ void operator=(const type&) = delete; \ diff --git a/base/scoped_generic.h b/base/scoped_generic.h index f6807e2..02db2e5 100644 --- a/base/scoped_generic.h +++ b/base/scoped_generic.h @@ -53,7 +53,7 @@ namespace base { // typedef ScopedGeneric<int, FooScopedTraits> ScopedFoo; template<typename T, typename Traits> class ScopedGeneric { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGeneric) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(ScopedGeneric) private: // This must be first since it's used inline below. diff --git a/mojo/edk/embedder/scoped_platform_handle.h b/mojo/edk/embedder/scoped_platform_handle.h index ae75202..1bf71f5 100644 --- a/mojo/edk/embedder/scoped_platform_handle.h +++ b/mojo/edk/embedder/scoped_platform_handle.h @@ -14,7 +14,7 @@ namespace mojo { namespace edk { class MOJO_SYSTEM_IMPL_EXPORT ScopedPlatformHandle { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPlatformHandle) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(ScopedPlatformHandle) public: ScopedPlatformHandle() {} diff --git a/mojo/public/cpp/bindings/associated_interface_ptr.h b/mojo/public/cpp/bindings/associated_interface_ptr.h index fae7a1a..15c12ce 100644 --- a/mojo/public/cpp/bindings/associated_interface_ptr.h +++ b/mojo/public/cpp/bindings/associated_interface_ptr.h @@ -19,7 +19,7 @@ namespace mojo { // InterfacePtr, except that it doesn't own a message pipe handle. template <typename Interface> class AssociatedInterfacePtr { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(AssociatedInterfacePtr) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtr) public: // Constructs an unbound AssociatedInterfacePtr. diff --git a/mojo/public/cpp/bindings/associated_interface_ptr_info.h b/mojo/public/cpp/bindings/associated_interface_ptr_info.h index 43f9027..1bbe1d2 100644 --- a/mojo/public/cpp/bindings/associated_interface_ptr_info.h +++ b/mojo/public/cpp/bindings/associated_interface_ptr_info.h @@ -19,7 +19,7 @@ class AssociatedInterfacePtrInfoHelper; // it doesn't own a message pipe handle. template <typename Interface> class AssociatedInterfacePtrInfo { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(AssociatedInterfacePtrInfo); + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtrInfo); public: AssociatedInterfacePtrInfo() : version_(0u) {} diff --git a/mojo/public/cpp/bindings/associated_interface_request.h b/mojo/public/cpp/bindings/associated_interface_request.h index 96019a3..668d5ff 100644 --- a/mojo/public/cpp/bindings/associated_interface_request.h +++ b/mojo/public/cpp/bindings/associated_interface_request.h @@ -18,7 +18,7 @@ class AssociatedInterfaceRequestHelper; // similar to InterfaceRequest except that it doesn't own a message pipe handle. template <typename Interface> class AssociatedInterfaceRequest { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(AssociatedInterfaceRequest); + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfaceRequest); public: // Constructs an empty AssociatedInterfaceRequest, representing that the diff --git a/mojo/public/cpp/bindings/interface_ptr.h b/mojo/public/cpp/bindings/interface_ptr.h index b6515cc..abc096a 100644 --- a/mojo/public/cpp/bindings/interface_ptr.h +++ b/mojo/public/cpp/bindings/interface_ptr.h @@ -29,7 +29,7 @@ class AssociatedGroup; // create and bind a new InterfacePtr from that thread. template <typename Interface> class InterfacePtr { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(InterfacePtr) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(InterfacePtr) public: // Constructs an unbound InterfacePtr. diff --git a/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h b/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h index c4527d0..cb94181 100644 --- a/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h +++ b/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h @@ -18,8 +18,7 @@ class MultiplexRouter; // ScopedInterfaceEndpointHandle refers to one end of an interface, either the // implementation side or the client side. class ScopedInterfaceEndpointHandle { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03( - ScopedInterfaceEndpointHandle); + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(ScopedInterfaceEndpointHandle); public: // Creates an invalid endpoint handle. diff --git a/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h b/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h index ed5ce61..2f3c001 100644 --- a/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h +++ b/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h @@ -14,7 +14,7 @@ namespace mojo { namespace embedder { class MOJO_SYSTEM_IMPL_EXPORT ScopedPlatformHandle { - MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPlatformHandle) + DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(ScopedPlatformHandle) public: ScopedPlatformHandle() {} |