summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author <shinichiro.hamaji@gmail.com>2009-01-09 06:07:55 +0000
committer <shinichiro.hamaji@gmail.com>2009-01-09 06:07:55 +0000
commit9de1077eeddbb722714315ebca819ea4288ebb3e (patch)
tree4f32e20d65c03594c9c05547b6284bbbb488c2eb /src
parentcc27d6aa59995501104e03b691222bbc939c1c11 (diff)
downloadglog-9de1077eeddbb722714315ebca819ea4288ebb3e.tar.gz
glog-9de1077eeddbb722714315ebca819ea4288ebb3e.tar.bz2
glog-9de1077eeddbb722714315ebca819ea4288ebb3e.zip
Define ARRAYSIZE in utilities.h and use it.
git-svn-id: https://google-glog.googlecode.com/svn/trunk@27 eb4d4688-79bd-11dd-afb4-1d65580434c0
Diffstat (limited to 'src')
-rw-r--r--src/logging.cc2
-rw-r--r--src/signalhandler.cc9
-rw-r--r--src/utilities.cc2
-rw-r--r--src/utilities.h3
4 files changed, 8 insertions, 8 deletions
diff --git a/src/logging.cc b/src/logging.cc
index c0da25e..2f34c4c 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -1393,7 +1393,7 @@ static void GetTempDirectories(vector<string>* list) {
"/tmp",
};
- for (int i = 0; i < sizeof(candidates) / sizeof(*candidates); i++) {
+ for (int i = 0; i < ARRAYSIZE(candidates); i++) {
const char *d = candidates[i];
if (!d) continue; // Empty env var
diff --git a/src/signalhandler.cc b/src/signalhandler.cc
index 367c226..58f197e 100644
--- a/src/signalhandler.cc
+++ b/src/signalhandler.cc
@@ -17,9 +17,6 @@
_START_GOOGLE_NAMESPACE_
-// There is a better way, but this is good enough in this file.
-#define NAIVE_ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
-
namespace {
// We'll install the failure signal handler for these signals. We could
@@ -139,7 +136,7 @@ void DumpTimeInfo() {
void DumpSignalInfo(int signal_number, siginfo_t *siginfo) {
// Get the signal name.
const char* signal_name = NULL;
- for (int i = 0; i < NAIVE_ARRAYSIZE(kFailureSignals); ++i) {
+ for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
if (signal_number == kFailureSignals[i].number) {
signal_name = kFailureSignals[i].name;
}
@@ -272,7 +269,7 @@ void FailureSignalHandler(int signal_number,
// Get the stack traces.
void *stack[32];
// +1 to exclude this function.
- const int depth = GetStackTrace(stack, NAIVE_ARRAYSIZE(stack), 1);
+ const int depth = GetStackTrace(stack, ARRAYSIZE(stack), 1);
DumpSignalInfo(signal_number, signal_info);
// Dump the stack traces.
for (int i = 0; i < depth; ++i) {
@@ -306,7 +303,7 @@ void InstallFailureSignalHandler() {
sig_action.sa_flags |= SA_SIGINFO;
sig_action.sa_sigaction = &FailureSignalHandler;
- for (int i = 0; i < NAIVE_ARRAYSIZE(kFailureSignals); ++i) {
+ for (int i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL));
}
}
diff --git a/src/utilities.cc b/src/utilities.cc
index 6f47085..711d743 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -84,7 +84,7 @@ static void DumpPC(DebugWriter *writerfn, void *arg, void *pc,
static void DumpStackTrace(int skip_count, DebugWriter *writerfn, void *arg) {
// Print stack trace
void* stack[32];
- int depth = GetStackTrace(stack, sizeof(stack)/sizeof(*stack), skip_count+1);
+ int depth = GetStackTrace(stack, ARRAYSIZE(stack), skip_count+1);
for (int i = 0; i < depth; i++) {
#if defined(HAVE_SYMBOLIZE)
if (FLAGS_symbolize_stacktrace) {
diff --git a/src/utilities.h b/src/utilities.h
index 0da2625..700a6a9 100644
--- a/src/utilities.h
+++ b/src/utilities.h
@@ -95,6 +95,9 @@
# define HAVE_SYMBOLIZE
#endif
+// There is a better way, but this is good enough in this file.
+#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
+
_START_GOOGLE_NAMESPACE_
namespace glog_internal_namespace_ {