Define ARRAYSIZE in utilities.h and use it.
author <shinichiro.hamaji@gmail.com> <>
Fri, 9 Jan 2009 06:07:55 +0000 (06:07 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Fri, 9 Jan 2009 06:07:55 +0000 (06:07 +0000)
git-svn-id: https://google-glog.googlecode.com/svn/trunk@27 eb4d4688-79bd-11dd-afb4-1d65580434c0

src/logging.cc
src/signalhandler.cc
src/utilities.cc
src/utilities.h

index c0da25e..2f34c4c 100644 (file)
@@ -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
 
index 367c226..58f197e 100644 (file)
@@ -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));
   }
 }
index 6f47085..711d743 100644 (file)
@@ -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) {
index 0da2625..700a6a9 100644 (file)
@@ -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_ {