Commit 8c4e3a92 authored by 's avatar

Suppress warnings. Most of this patch was given by keir (thanks!).

Corresponding glog bug: http://code.google.com/p/google-glog/issues/detail?id=10

The differences from keir's patch are:
- For raw_logging.h.in, I just included time.h for struct tm.
- Added a fprintf which warns that we should have died to avoid a warning for unused local variable.
- Added inline for some functions which may be unused in googletest.h.
- Removed DumpPCAndFrameSize as it was unused.


git-svn-id: https://google-glog.googlecode.com/svn/trunk@56 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent 4cd83814
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#ifndef BASE_RAW_LOGGING_H_ #ifndef BASE_RAW_LOGGING_H_
#define BASE_RAW_LOGGING_H_ #define BASE_RAW_LOGGING_H_
#include <time.h>
@ac_google_start_namespace@ @ac_google_start_namespace@
#include "glog/log_severity.h" #include "glog/log_severity.h"
...@@ -176,8 +178,7 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity, ...@@ -176,8 +178,7 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
// Hack to propagate time information into this module so that // Hack to propagate time information into this module so that
// this module does not have to directly call localtime_r(), // this module does not have to directly call localtime_r(),
// which could allocate memory. // which could allocate memory.
extern "C" struct ::tm; GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct ::tm& t, int usecs);
@ac_google_end_namespace@ @ac_google_end_namespace@
......
...@@ -71,7 +71,7 @@ _END_GOOGLE_NAMESPACE_ ...@@ -71,7 +71,7 @@ _END_GOOGLE_NAMESPACE_
#undef GOOGLE_GLOG_DLL_DECL #undef GOOGLE_GLOG_DLL_DECL
#define GOOGLE_GLOG_DLL_DECL #define GOOGLE_GLOG_DLL_DECL
static string GetTempDir() { static inline string GetTempDir() {
#ifndef OS_WINDOWS #ifndef OS_WINDOWS
return "/tmp"; return "/tmp";
#else #else
...@@ -180,7 +180,7 @@ vector<void (*)()> g_testlist; // the tests to run ...@@ -180,7 +180,7 @@ vector<void (*)()> g_testlist; // the tests to run
void Test_##a##_##b::RunTest() void Test_##a##_##b::RunTest()
static int RUN_ALL_TESTS() { static inline int RUN_ALL_TESTS() {
vector<void (*)()>::const_iterator it; vector<void (*)()>::const_iterator it;
for (it = g_testlist.begin(); it != g_testlist.end(); ++it) { for (it = g_testlist.begin(); it != g_testlist.end(); ++it) {
(*it)(); (*it)();
...@@ -197,7 +197,7 @@ _START_GOOGLE_NAMESPACE_ ...@@ -197,7 +197,7 @@ _START_GOOGLE_NAMESPACE_
static bool g_called_abort; static bool g_called_abort;
static jmp_buf g_jmp_buf; static jmp_buf g_jmp_buf;
static void CalledAbort() { static inline void CalledAbort() {
g_called_abort = true; g_called_abort = true;
longjmp(g_jmp_buf, 1); longjmp(g_jmp_buf, 1);
} }
...@@ -241,7 +241,7 @@ class BenchmarkRegisterer { ...@@ -241,7 +241,7 @@ class BenchmarkRegisterer {
} }
}; };
static void RunSpecifiedBenchmarks() { static inline void RunSpecifiedBenchmarks() {
if (!FLAGS_run_benchmark) { if (!FLAGS_run_benchmark) {
return; return;
} }
...@@ -319,21 +319,21 @@ static CapturedStream * s_captured_streams[STDERR_FILENO+1]; ...@@ -319,21 +319,21 @@ static CapturedStream * s_captured_streams[STDERR_FILENO+1];
// Redirect a file descriptor to a file. // Redirect a file descriptor to a file.
// fd - Should be STDOUT_FILENO or STDERR_FILENO // fd - Should be STDOUT_FILENO or STDERR_FILENO
// filename - File where output should be stored // filename - File where output should be stored
static void CaptureTestOutput(int fd, const string & filename) { static inline void CaptureTestOutput(int fd, const string & filename) {
CHECK((fd == STDOUT_FILENO) || (fd == STDERR_FILENO)); CHECK((fd == STDOUT_FILENO) || (fd == STDERR_FILENO));
CHECK(s_captured_streams[fd] == NULL); CHECK(s_captured_streams[fd] == NULL);
s_captured_streams[fd] = new CapturedStream(fd, filename); s_captured_streams[fd] = new CapturedStream(fd, filename);
} }
static void CaptureTestStderr() { static inline void CaptureTestStderr() {
CaptureTestOutput(STDERR_FILENO, FLAGS_test_tmpdir + "/captured.err"); CaptureTestOutput(STDERR_FILENO, FLAGS_test_tmpdir + "/captured.err");
} }
// Return the size (in bytes) of a file // Return the size (in bytes) of a file
static size_t GetFileSize(FILE * file) { static inline size_t GetFileSize(FILE * file) {
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
return static_cast<size_t>(ftell(file)); return static_cast<size_t>(ftell(file));
} }
// Read the entire content of a file as a string // Read the entire content of a file as a string
static string ReadEntireFile(FILE * file) { static inline string ReadEntireFile(FILE * file) {
const size_t file_size = GetFileSize(file); const size_t file_size = GetFileSize(file);
char * const buffer = new char[file_size]; char * const buffer = new char[file_size];
...@@ -356,7 +356,7 @@ static string ReadEntireFile(FILE * file) { ...@@ -356,7 +356,7 @@ static string ReadEntireFile(FILE * file) {
} }
// Get the captured stdout (when fd is STDOUT_FILENO) or stderr (when // Get the captured stdout (when fd is STDOUT_FILENO) or stderr (when
// fd is STDERR_FILENO) as a string // fd is STDERR_FILENO) as a string
static string GetCapturedTestOutput(int fd) { static inline string GetCapturedTestOutput(int fd) {
CHECK(fd == STDOUT_FILENO || fd == STDERR_FILENO); CHECK(fd == STDOUT_FILENO || fd == STDERR_FILENO);
CapturedStream * const cap = s_captured_streams[fd]; CapturedStream * const cap = s_captured_streams[fd];
CHECK(cap) CHECK(cap)
...@@ -376,12 +376,12 @@ static string GetCapturedTestOutput(int fd) { ...@@ -376,12 +376,12 @@ static string GetCapturedTestOutput(int fd) {
return content; return content;
} }
// Get the captured stderr of a test as a string. // Get the captured stderr of a test as a string.
static string GetCapturedTestStderr() { static inline string GetCapturedTestStderr() {
return GetCapturedTestOutput(STDERR_FILENO); return GetCapturedTestOutput(STDERR_FILENO);
} }
// Check if the string is [IWEF](\d{4}|DATE) // Check if the string is [IWEF](\d{4}|DATE)
static bool IsLoggingPrefix(const string& s) { static inline bool IsLoggingPrefix(const string& s) {
if (s.size() != 5) return false; if (s.size() != 5) return false;
if (!strchr("IWEF", s[0])) return false; if (!strchr("IWEF", s[0])) return false;
for (int i = 1; i <= 4; ++i) { for (int i = 1; i <= 4; ++i) {
...@@ -395,7 +395,7 @@ static bool IsLoggingPrefix(const string& s) { ...@@ -395,7 +395,7 @@ static bool IsLoggingPrefix(const string& s) {
// Example: // Example:
// I0102 030405 logging_unittest.cc:345] RAW: vlog -1 // I0102 030405 logging_unittest.cc:345] RAW: vlog -1
// => IDATE TIME__ logging_unittest.cc:LINE] RAW: vlog -1 // => IDATE TIME__ logging_unittest.cc:LINE] RAW: vlog -1
static string MungeLine(const string& line) { static inline string MungeLine(const string& line) {
std::istringstream iss(line); std::istringstream iss(line);
string before, logcode_date, time, thread_lineinfo; string before, logcode_date, time, thread_lineinfo;
iss >> logcode_date; iss >> logcode_date;
...@@ -427,7 +427,7 @@ static string MungeLine(const string& line) { ...@@ -427,7 +427,7 @@ static string MungeLine(const string& line) {
MungeLine(rest)); MungeLine(rest));
} }
static void StringReplace(string* str, static inline void StringReplace(string* str,
const string& oldsub, const string& oldsub,
const string& newsub) { const string& newsub) {
size_t pos = str->find(oldsub); size_t pos = str->find(oldsub);
...@@ -436,7 +436,7 @@ static void StringReplace(string* str, ...@@ -436,7 +436,7 @@ static void StringReplace(string* str,
} }
} }
static string Munge(const string& filename) { static inline string Munge(const string& filename) {
FILE* fp = fopen(filename.c_str(), "rb"); FILE* fp = fopen(filename.c_str(), "rb");
CHECK(fp != NULL) << filename << ": couldn't open"; CHECK(fp != NULL) << filename << ": couldn't open";
char buf[4096]; char buf[4096];
...@@ -444,7 +444,7 @@ static string Munge(const string& filename) { ...@@ -444,7 +444,7 @@ static string Munge(const string& filename) {
while (fgets(buf, 4095, fp)) { while (fgets(buf, 4095, fp)) {
string line = MungeLine(buf); string line = MungeLine(buf);
char null_str[256]; char null_str[256];
sprintf(null_str, "%p", NULL); sprintf(null_str, "%p", static_cast<void*>(NULL));
StringReplace(&line, "__NULLP__", null_str); StringReplace(&line, "__NULLP__", null_str);
// Remove 0x prefix produced by %p. VC++ doesn't put the prefix. // Remove 0x prefix produced by %p. VC++ doesn't put the prefix.
StringReplace(&line, " 0x", " "); StringReplace(&line, " 0x", " ");
...@@ -468,13 +468,13 @@ static string Munge(const string& filename) { ...@@ -468,13 +468,13 @@ static string Munge(const string& filename) {
return result; return result;
} }
static void WriteToFile(const string& body, const string& file) { static inline void WriteToFile(const string& body, const string& file) {
FILE* fp = fopen(file.c_str(), "wb"); FILE* fp = fopen(file.c_str(), "wb");
fwrite(body.data(), 1, body.size(), fp); fwrite(body.data(), 1, body.size(), fp);
fclose(fp); fclose(fp);
} }
static bool MungeAndDiffTestStderr(const string& golden_filename) { static inline bool MungeAndDiffTestStderr(const string& golden_filename) {
CapturedStream* cap = s_captured_streams[STDERR_FILENO]; CapturedStream* cap = s_captured_streams[STDERR_FILENO];
CHECK(cap) << ": did you forget CaptureTestStderr()?"; CHECK(cap) << ": did you forget CaptureTestStderr()?";
...@@ -567,7 +567,7 @@ class Thread { ...@@ -567,7 +567,7 @@ class Thread {
#endif #endif
}; };
static void SleepForMilliseconds(int t) { static inline void SleepForMilliseconds(int t) {
#ifndef OS_WINDOWS #ifndef OS_WINDOWS
usleep(t * 1000); usleep(t * 1000);
#else #else
......
...@@ -232,7 +232,8 @@ void DumpStackFrameInfo(const char* prefix, void* pc) { ...@@ -232,7 +232,8 @@ void DumpStackFrameInfo(const char* prefix, void* pc) {
// Invoke the default signal handler. // Invoke the default signal handler.
void InvokeDefaultSignalHandler(int signal_number) { void InvokeDefaultSignalHandler(int signal_number) {
struct sigaction sig_action = {}; // Zero-clear. struct sigaction sig_action;
memset(&sig_action, 0, sizeof(sig_action));
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
sig_action.sa_handler = SIG_DFL; sig_action.sa_handler = SIG_DFL;
sigaction(signal_number, &sig_action, NULL); sigaction(signal_number, &sig_action, NULL);
...@@ -326,7 +327,8 @@ void FailureSignalHandler(int signal_number, ...@@ -326,7 +327,8 @@ void FailureSignalHandler(int signal_number,
void InstallFailureSignalHandler() { void InstallFailureSignalHandler() {
// Build the sigaction struct. // Build the sigaction struct.
struct sigaction sig_action = {}; // Zero-clear. struct sigaction sig_action;
memset(&sig_action, 0, sizeof(sig_action));
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
sig_action.sa_flags |= SA_SIGINFO; sig_action.sa_flags |= SA_SIGINFO;
sig_action.sa_sigaction = &FailureSignalHandler; sig_action.sa_sigaction = &FailureSignalHandler;
......
...@@ -48,6 +48,8 @@ void* DieInThread(void*) { ...@@ -48,6 +48,8 @@ void* DieInThread(void*) {
// Use volatile to prevent from these to be optimized away. // Use volatile to prevent from these to be optimized away.
volatile int a = 0; volatile int a = 0;
volatile int b = 1 / a; volatile int b = 1 / a;
fprintf(stderr, "We should have died: b=%d\n", b);
return NULL;
} }
void WriteToStdout(const char* data, int size) { void WriteToStdout(const char* data, int size) {
......
...@@ -193,7 +193,8 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) { ...@@ -193,7 +193,8 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) {
memset(altstack, kAlternateStackFillValue, kAlternateStackSize); memset(altstack, kAlternateStackFillValue, kAlternateStackSize);
// Set up the alt-signal-stack (and save the older one). // Set up the alt-signal-stack (and save the older one).
stack_t sigstk = {}; // Zero-clear. stack_t sigstk;
memset(&sigstk, 0, sizeof(stack_t));
stack_t old_sigstk; stack_t old_sigstk;
sigstk.ss_sp = altstack; sigstk.ss_sp = altstack;
sigstk.ss_size = kAlternateStackSize; sigstk.ss_size = kAlternateStackSize;
...@@ -201,7 +202,8 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) { ...@@ -201,7 +202,8 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) {
CHECK_ERR(sigaltstack(&sigstk, &old_sigstk)); CHECK_ERR(sigaltstack(&sigstk, &old_sigstk));
// Set up SIGUSR1 and SIGUSR2 signal handlers (and save the older ones). // Set up SIGUSR1 and SIGUSR2 signal handlers (and save the older ones).
struct sigaction sa = {}; // Zero-clear; struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
struct sigaction old_sa1, old_sa2; struct sigaction old_sa1, old_sa2;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_ONSTACK; sa.sa_flags = SA_ONSTACK;
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
# define OS_MACOSX # define OS_MACOSX
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
# define OS_FREEBSD # define OS_FREEBSD
#elif defined(__OpenBSD__)
# define OS_OPENBSD
#else #else
// TODO(hamaji): Add other platforms. // TODO(hamaji): Add other platforms.
#endif #endif
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#ifndef BASE_RAW_LOGGING_H_ #ifndef BASE_RAW_LOGGING_H_
#define BASE_RAW_LOGGING_H_ #define BASE_RAW_LOGGING_H_
#include <time.h>
namespace google { namespace google {
#include "glog/log_severity.h" #include "glog/log_severity.h"
...@@ -180,8 +182,7 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity, ...@@ -180,8 +182,7 @@ GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
// Hack to propagate time information into this module so that // Hack to propagate time information into this module so that
// this module does not have to directly call localtime_r(), // this module does not have to directly call localtime_r(),
// which could allocate memory. // which could allocate memory.
extern "C" struct ::tm; GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs);
GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct ::tm& t, int usecs);
} }
......
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