OSDN Git Service

Bring in google3-style DISALLOW_* macros.
authorElliott Hughes <enh@google.com>
Sat, 10 May 2014 02:12:08 +0000 (19:12 -0700)
committerElliott Hughes <enh@google.com>
Sat, 10 May 2014 02:12:08 +0000 (19:12 -0700)
I've been meaning to do this for a very long time...

Change-Id: Ia8c16eee7c026c3c9505399948485fb778fb0152

libc/bionic/pthread_accessor.h
libc/bionic/scandir.cpp
libc/bionic/system_properties.cpp
libc/private/ErrnoRestorer.h
libc/private/KernelArgumentBlock.h
libc/private/ScopedPthreadMutexLocker.h
libc/private/ScopedReaddir.h
libc/private/bionic_macros.h [new file with mode: 0644]

index 2a320f6..ccb71bb 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <pthread.h>
 
+#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
index 25d5200..9f731ab 100644 (file)
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#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,
index 4e4684a..ec3d04b 100644 (file)
@@ -54,6 +54,7 @@
 #include <sys/atomics.h>
 
 #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 {
index ed6ab62..f467393 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <errno.h>
 
+#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
index 4af52ab..c8ea497 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdint.h>
 #include <sys/auxv.h>
 
+#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
index 06b8e37..43dbdc1 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <pthread.h>
 
+#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
index 797809a..84c1b93 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <dirent.h>
 
+#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 (file)
index 0000000..34da501
--- /dev/null
@@ -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_