summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-09 19:12:08 -0700
committerElliott Hughes <enh@google.com>2014-05-09 19:12:08 -0700
commit8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39 (patch)
treed69e6b95bccca6e095b5e320198c552c9ee0e398
parentb2c3c803f0f4a50acfdc31eb28bd83b48a0026fe (diff)
downloadbionic-8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39.zip
bionic-8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39.tar.gz
bionic-8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39.tar.bz2
Bring in google3-style DISALLOW_* macros.
I've been meaning to do this for a very long time... Change-Id: Ia8c16eee7c026c3c9505399948485fb778fb0152
-rw-r--r--libc/bionic/pthread_accessor.h5
-rw-r--r--libc/bionic/scandir.cpp5
-rw-r--r--libc/bionic/system_properties.cpp13
-rw-r--r--libc/private/ErrnoRestorer.h6
-rw-r--r--libc/private/KernelArgumentBlock.h6
-rw-r--r--libc/private/ScopedPthreadMutexLocker.h6
-rw-r--r--libc/private/ScopedReaddir.h6
-rw-r--r--libc/private/bionic_macros.h36
8 files changed, 56 insertions, 27 deletions
diff --git a/libc/bionic/pthread_accessor.h b/libc/bionic/pthread_accessor.h
index 2a320f6..ccb71bb 100644
--- a/libc/bionic/pthread_accessor.h
+++ b/libc/bionic/pthread_accessor.h
@@ -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
diff --git a/libc/bionic/scandir.cpp b/libc/bionic/scandir.cpp
index 25d5200..9f731ab 100644
--- a/libc/bionic/scandir.cpp
+++ b/libc/bionic/scandir.cpp
@@ -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,
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 4e4684a..ec3d04b 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -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 {
diff --git a/libc/private/ErrnoRestorer.h b/libc/private/ErrnoRestorer.h
index ed6ab62..f467393 100644
--- a/libc/private/ErrnoRestorer.h
+++ b/libc/private/ErrnoRestorer.h
@@ -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
diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h
index 4af52ab..c8ea497 100644
--- a/libc/private/KernelArgumentBlock.h
+++ b/libc/private/KernelArgumentBlock.h
@@ -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
diff --git a/libc/private/ScopedPthreadMutexLocker.h b/libc/private/ScopedPthreadMutexLocker.h
index 06b8e37..43dbdc1 100644
--- a/libc/private/ScopedPthreadMutexLocker.h
+++ b/libc/private/ScopedPthreadMutexLocker.h
@@ -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
diff --git a/libc/private/ScopedReaddir.h b/libc/private/ScopedReaddir.h
index 797809a..84c1b93 100644
--- a/libc/private/ScopedReaddir.h
+++ b/libc/private/ScopedReaddir.h
@@ -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
index 0000000..34da501
--- /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_