From: Elliott Hughes Date: Sat, 10 May 2014 02:12:08 +0000 (-0700) Subject: Bring in google3-style DISALLOW_* macros. X-Git-Tag: android-x86-7.1-r1~757^2~1001^2~136^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39;p=android-x86%2Fbionic.git Bring in google3-style DISALLOW_* macros. I've been meaning to do this for a very long time... Change-Id: Ia8c16eee7c026c3c9505399948485fb778fb0152 --- diff --git a/libc/bionic/pthread_accessor.h b/libc/bionic/pthread_accessor.h index 2a320f6df..ccb71bb9a 100644 --- a/libc/bionic/pthread_accessor.h +++ b/libc/bionic/pthread_accessor.h @@ -19,6 +19,7 @@ #include +#include "private/bionic_macros.h" #include "pthread_internal.h" class pthread_accessor { @@ -57,9 +58,7 @@ class pthread_accessor { is_locked_ = true; } - // Disallow copy and assignment. - pthread_accessor(const pthread_accessor&); - void operator=(const pthread_accessor&); + DISALLOW_COPY_AND_ASSIGN(pthread_accessor); }; #endif // PTHREAD_ACCESSOR_H diff --git a/libc/bionic/scandir.cpp b/libc/bionic/scandir.cpp index 25d5200ee..9f731ab58 100644 --- a/libc/bionic/scandir.cpp +++ b/libc/bionic/scandir.cpp @@ -19,6 +19,7 @@ #include #include +#include "private/bionic_macros.h" #include "private/ScopedReaddir.h" // A smart pointer to the scandir dirent**. @@ -84,9 +85,7 @@ class ScandirResult { return copy; } - // Disallow copy and assignment. - ScandirResult(const ScandirResult&); - void operator=(const ScandirResult&); + DISALLOW_COPY_AND_ASSIGN(ScandirResult); }; int scandir(const char* dirname, dirent*** name_list, diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp index 4e4684afd..ec3d04bf7 100644 --- a/libc/bionic/system_properties.cpp +++ b/libc/bionic/system_properties.cpp @@ -54,6 +54,7 @@ #include #include "private/bionic_atomic_inline.h" +#include "private/bionic_macros.h" #define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) @@ -100,9 +101,7 @@ struct prop_bt { } private: - // Disallow copy and assign. - prop_bt(const prop_bt&); - prop_bt& operator=(const prop_bt&); + DISALLOW_COPY_AND_ASSIGN(prop_bt); }; struct prop_area { @@ -121,9 +120,7 @@ struct prop_area { } private: - // Disallow copy and assign. - prop_area(const prop_area&); - prop_area& operator=(const prop_area&); + DISALLOW_COPY_AND_ASSIGN(prop_area); }; struct prop_info { @@ -141,9 +138,7 @@ struct prop_info { ANDROID_MEMBAR_FULL(); } private: - // Disallow copy and assign. - prop_info(const prop_info&); - prop_info& operator=(const prop_info&); + DISALLOW_COPY_AND_ASSIGN(prop_info); }; struct find_nth_cookie { diff --git a/libc/private/ErrnoRestorer.h b/libc/private/ErrnoRestorer.h index ed6ab6270..f4673936a 100644 --- a/libc/private/ErrnoRestorer.h +++ b/libc/private/ErrnoRestorer.h @@ -19,6 +19,8 @@ #include +#include "bionic_macros.h" + class ErrnoRestorer { public: explicit ErrnoRestorer() : saved_errno_(errno) { @@ -35,9 +37,7 @@ class ErrnoRestorer { private: int saved_errno_; - // Disallow copy and assignment. - ErrnoRestorer(const ErrnoRestorer&); - void operator=(const ErrnoRestorer&); + DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer); }; #endif // ERRNO_RESTORER_H diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h index 4af52ab67..c8ea4977a 100644 --- a/libc/private/KernelArgumentBlock.h +++ b/libc/private/KernelArgumentBlock.h @@ -22,6 +22,8 @@ #include #include +#include "private/bionic_macros.h" + struct abort_msg_t; // When the kernel starts the dynamic linker, it passes a pointer to a block @@ -73,9 +75,7 @@ class KernelArgumentBlock { abort_msg_t** abort_message_ptr; private: - // Disallow copy and assignment. - KernelArgumentBlock(const KernelArgumentBlock&); - void operator=(const KernelArgumentBlock&); + DISALLOW_COPY_AND_ASSIGN(KernelArgumentBlock); }; #endif // KERNEL_ARGUMENT_BLOCK_H diff --git a/libc/private/ScopedPthreadMutexLocker.h b/libc/private/ScopedPthreadMutexLocker.h index 06b8e37b2..43dbdc115 100644 --- a/libc/private/ScopedPthreadMutexLocker.h +++ b/libc/private/ScopedPthreadMutexLocker.h @@ -19,6 +19,8 @@ #include +#include "bionic_macros.h" + class ScopedPthreadMutexLocker { public: explicit ScopedPthreadMutexLocker(pthread_mutex_t* mu) : mu_(mu) { @@ -32,9 +34,7 @@ class ScopedPthreadMutexLocker { private: pthread_mutex_t* mu_; - // Disallow copy and assignment. - ScopedPthreadMutexLocker(const ScopedPthreadMutexLocker&); - void operator=(const ScopedPthreadMutexLocker&); + DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLocker); }; #endif // SCOPED_PTHREAD_MUTEX_LOCKER_H diff --git a/libc/private/ScopedReaddir.h b/libc/private/ScopedReaddir.h index 797809a28..84c1b93a4 100644 --- a/libc/private/ScopedReaddir.h +++ b/libc/private/ScopedReaddir.h @@ -19,6 +19,8 @@ #include +#include "private/bionic_macros.h" + class ScopedReaddir { public: ScopedReaddir(const char* path) { @@ -42,9 +44,7 @@ class ScopedReaddir { private: DIR* dir_; - // Disallow copy and assignment. - ScopedReaddir(const ScopedReaddir&); - void operator=(const ScopedReaddir&); + DISALLOW_COPY_AND_ASSIGN(ScopedReaddir); }; #endif // SCOPED_READDIR_H diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h new file mode 100644 index 000000000..34da501c0 --- /dev/null +++ b/libc/private/bionic_macros.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BIONIC_MACROS_H_ +#define _BIONIC_MACROS_H_ + +// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. +// It goes in the private: declarations in a class. +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + DISALLOW_COPY_AND_ASSIGN(TypeName) + +#endif // _BIONIC_MACROS_H_