Commit 9de1077e authored by 's avatar

Define ARRAYSIZE in utilities.h and use it.


git-svn-id: https://google-glog.googlecode.com/svn/trunk@27 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent cc27d6aa
...@@ -1393,7 +1393,7 @@ static void GetTempDirectories(vector<string>* list) { ...@@ -1393,7 +1393,7 @@ static void GetTempDirectories(vector<string>* list) {
"/tmp", "/tmp",
}; };
for (int i = 0; i < sizeof(candidates) / sizeof(*candidates); i++) { for (int i = 0; i < ARRAYSIZE(candidates); i++) {
const char *d = candidates[i]; const char *d = candidates[i];
if (!d) continue; // Empty env var if (!d) continue; // Empty env var
......
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
_START_GOOGLE_NAMESPACE_ _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 { namespace {
// We'll install the failure signal handler for these signals. We could // We'll install the failure signal handler for these signals. We could
...@@ -139,7 +136,7 @@ void DumpTimeInfo() { ...@@ -139,7 +136,7 @@ void DumpTimeInfo() {
void DumpSignalInfo(int signal_number, siginfo_t *siginfo) { void DumpSignalInfo(int signal_number, siginfo_t *siginfo) {
// Get the signal name. // Get the signal name.
const char* signal_name = NULL; 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) { if (signal_number == kFailureSignals[i].number) {
signal_name = kFailureSignals[i].name; signal_name = kFailureSignals[i].name;
} }
...@@ -272,7 +269,7 @@ void FailureSignalHandler(int signal_number, ...@@ -272,7 +269,7 @@ void FailureSignalHandler(int signal_number,
// Get the stack traces. // Get the stack traces.
void *stack[32]; void *stack[32];
// +1 to exclude this function. // +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); DumpSignalInfo(signal_number, signal_info);
// Dump the stack traces. // Dump the stack traces.
for (int i = 0; i < depth; ++i) { for (int i = 0; i < depth; ++i) {
...@@ -306,7 +303,7 @@ void InstallFailureSignalHandler() { ...@@ -306,7 +303,7 @@ void InstallFailureSignalHandler() {
sig_action.sa_flags |= SA_SIGINFO; sig_action.sa_flags |= SA_SIGINFO;
sig_action.sa_sigaction = &FailureSignalHandler; 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)); CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL));
} }
} }
......
...@@ -84,7 +84,7 @@ static void DumpPC(DebugWriter *writerfn, void *arg, void *pc, ...@@ -84,7 +84,7 @@ static void DumpPC(DebugWriter *writerfn, void *arg, void *pc,
static void DumpStackTrace(int skip_count, DebugWriter *writerfn, void *arg) { static void DumpStackTrace(int skip_count, DebugWriter *writerfn, void *arg) {
// Print stack trace // Print stack trace
void* stack[32]; 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++) { for (int i = 0; i < depth; i++) {
#if defined(HAVE_SYMBOLIZE) #if defined(HAVE_SYMBOLIZE)
if (FLAGS_symbolize_stacktrace) { if (FLAGS_symbolize_stacktrace) {
......
...@@ -95,6 +95,9 @@ ...@@ -95,6 +95,9 @@
# define HAVE_SYMBOLIZE # define HAVE_SYMBOLIZE
#endif #endif
// There is a better way, but this is good enough in this file.
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
_START_GOOGLE_NAMESPACE_ _START_GOOGLE_NAMESPACE_
namespace glog_internal_namespace_ { namespace glog_internal_namespace_ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment