From e27437d2d4923de8e120141ff2c45ec3a35d085d Mon Sep 17 00:00:00 2001
From: Leif Walsh <leif@tokutek.com>
Date: Sun, 13 May 2012 23:50:41 +0000
Subject: [PATCH] [t:4871] really turn on -Werror, make things compile with it

git-svn-id: file:///svn/toku/tokudb@43473 c7de825b-a66e-492c-adef-691d508d4ae1
---
 CTestCustom.cmake                             |  1 -
 cmake_modules/TokuSetupCompiler.cmake         |  9 +++----
 newbrt/logcursor.c                            |  1 -
 newbrt/logger.c                               |  1 -
 newbrt/tests/logfilemgr-create-destroy.c      |  2 +-
 newbrt/tests/logfilemgr-print.c               |  2 +-
 portability/tests/test-rwlock.c               | 24 +++++++++----------
 src/loader.c                                  |  1 +
 .../tests/test_conflict_read_table_write.c    |  8 -------
 src/ydb.c                                     |  1 +
 10 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/CTestCustom.cmake b/CTestCustom.cmake
index 9808304a3d9..57d1c8dccec 100644
--- a/CTestCustom.cmake
+++ b/CTestCustom.cmake
@@ -160,5 +160,4 @@ endif()
 
 list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
   "xz-4.999.9beta/src/liblzma"              # don't complain about warnings in xz source
-  "tokudb/portability/tests/test-rwlock.c"  # non-static functions seem to be on purpose
   )
diff --git a/cmake_modules/TokuSetupCompiler.cmake b/cmake_modules/TokuSetupCompiler.cmake
index d7c83144efc..2197b3a4f0a 100644
--- a/cmake_modules/TokuSetupCompiler.cmake
+++ b/cmake_modules/TokuSetupCompiler.cmake
@@ -58,15 +58,16 @@ endfunction(maybe_add_gcov_to_libraries)
 
 include(CheckCCompilerFlag)
 
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
 ## adds a compiler flag if the compiler supports it
-function(set_cflags_if_supported)
+macro(set_cflags_if_supported)
   foreach(flag ${ARGN})
     check_c_compiler_flag(${flag} HAVE_${flag})
     if (HAVE_${flag})
       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
     endif ()
   endforeach(flag)
-endfunction(set_cflags_if_supported)
+endmacro(set_cflags_if_supported)
 
 ## disable some warnings
 set_cflags_if_supported(
@@ -115,15 +116,11 @@ if (CMAKE_C_COMPILER_ID MATCHES Intel)
 
   ## set icc warnings
   set(WARN_CFLAGS
-    -Wall
-    -Werror
     -Wcheck  ## icc version of -Wextra
     )
 else()
   ## set gcc warnings
   set(WARN_CFLAGS
-    -Wall
-    -Werror
     -Wextra
     -Wcast-align
     -Wbad-function-cast
diff --git a/newbrt/logcursor.c b/newbrt/logcursor.c
index 0f3f7a79557..67385fbd7f3 100644
--- a/newbrt/logcursor.c
+++ b/newbrt/logcursor.c
@@ -164,7 +164,6 @@ int toku_logcursor_create(TOKULOGCURSOR *lc, const char *log_dir) {
 }
 
 int toku_logcursor_create_for_file(TOKULOGCURSOR *lc, const char *log_dir, const char *log_file) {
-    int failresult = 0;
     int r = lc_create(lc, log_dir);
     if ( r!=0 ) 
         return r;
diff --git a/newbrt/logger.c b/newbrt/logger.c
index 1a615105406..e2acb6c3bec 100644
--- a/newbrt/logger.c
+++ b/newbrt/logger.c
@@ -238,7 +238,6 @@ toku_logger_close_rollback(TOKULOGGER logger, BOOL recovery_failed) {
             assert(!h->dirty); // it should not have been dirtied by the toku_brt_is_empty test.
         }
 
-        char *error_string_ignore = NULL;
         r = toku_brt_close(brt_to_close, FALSE, ZERO_LSN);
         //Set as dealt with already.
         logger->rollback_cachefile = NULL;
diff --git a/newbrt/tests/logfilemgr-create-destroy.c b/newbrt/tests/logfilemgr-create-destroy.c
index 06c823ac083..bdc302edc21 100644
--- a/newbrt/tests/logfilemgr-create-destroy.c
+++ b/newbrt/tests/logfilemgr-create-destroy.c
@@ -1,7 +1,7 @@
 #include "test.h"
 #include "logfilemgr.h"
 
-int test_main(int argc, const char *argv[]) {
+int test_main(int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) {
     int r;
 
     TOKULOGFILEMGR lfm = NULL;
diff --git a/newbrt/tests/logfilemgr-print.c b/newbrt/tests/logfilemgr-print.c
index b6155782f2e..72ecd464ba5 100644
--- a/newbrt/tests/logfilemgr-print.c
+++ b/newbrt/tests/logfilemgr-print.c
@@ -1,7 +1,7 @@
 #include "test.h"
 #include "logfilemgr.h"
 
-int test_main(int argc, const char *argv[]) {
+int test_main(int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) {
     int r;
 
     TOKULOGFILEMGR lfm = NULL;
diff --git a/portability/tests/test-rwlock.c b/portability/tests/test-rwlock.c
index 0ec9d6ce8f9..4061051de1a 100644
--- a/portability/tests/test-rwlock.c
+++ b/portability/tests/test-rwlock.c
@@ -93,7 +93,7 @@ void sequential_consistency (void) {
 // That's probably good enough for us, since we'll have a barrier instruction anywhere it matters.
 volatile int val = 0;
 
-/* not static */
+static
 void time_nop (void) {
     struct timeval start,end;
     for (int t=0; t<T; t++) {
@@ -113,7 +113,7 @@ void time_nop (void) {
     }
 }
 
-/* not static */
+static
 void time_fcall (void) {
     struct timeval start,end;
     for (int t=0; t<T; t++) {
@@ -129,15 +129,15 @@ void time_fcall (void) {
     }
 }
 
-/* not static */
+static
 void time_cas (void) {
-    volatile int64_t val = 0;
+    volatile int64_t myval = 0;
     struct timeval start,end;
     for (int t=0; t<T; t++) {
 	gettimeofday(&start, NULL);
 	for (int i=0; i<N; i++) {
-	    { int r = __sync_val_compare_and_swap(&val, 0, 1);  assert(r==0); }
-	    { int r = __sync_val_compare_and_swap(&val, 1, 0);  assert(r==1); }
+	    { int r = __sync_val_compare_and_swap(&myval, 0, 1);  assert(r==0); }
+	    { int r = __sync_val_compare_and_swap(&myval, 1, 0);  assert(r==1); }
 	}
 	gettimeofday(&end,   NULL);
 	double diff = 1e9*toku_tdiff(&end, &start)/N;
@@ -148,7 +148,7 @@ void time_cas (void) {
 }
 
 
-/* not static */
+static
 void time_pthread_mutex (void) {
     pthread_mutex_t mutex;
     { int r = pthread_mutex_init(&mutex, NULL); assert(r==0); }
@@ -170,7 +170,7 @@ void time_pthread_mutex (void) {
     { int r = pthread_mutex_destroy(&mutex);    assert(r==0); }
 }
 
-/* not static */
+static
 void time_pthread_rwlock (void) {
     pthread_rwlock_t mutex;
     { int r = pthread_rwlock_init(&mutex, NULL); assert(r==0); }
@@ -205,7 +205,7 @@ static void newbrt_rwlock_unlock (RWLOCK rwlock, toku_pthread_mutex_t *mutex) {
 }
 
 // Time the read lock that's in newbrt/rwlock.h
-/* not static */
+static
 void time_newbrt_rwlock (void) {
     struct rwlock rwlock;
     toku_pthread_mutex_t external_mutex;
@@ -232,7 +232,7 @@ void time_newbrt_rwlock (void) {
 }
 
 // Time the read lock that's in newbrt/rwlock.h, assuming the mutex is already held.
-/* not static*/
+static
 void time_newbrt_prelocked_rwlock (void) {
     struct rwlock rwlock;
     toku_pthread_mutex_t external_mutex;
@@ -260,7 +260,7 @@ void time_newbrt_prelocked_rwlock (void) {
     { int r = pthread_mutex_destroy(&external_mutex);    assert(r==0); }
 }
 
-/* not static*/
+static
 void time_toku_fair_rwlock (void) {
     toku_fair_rwlock_t mutex;
     { int r = toku_fair_rwlock_init(&mutex);                  assert(r==0); }
@@ -282,7 +282,7 @@ void time_toku_fair_rwlock (void) {
     { int r = toku_fair_rwlock_destroy(&mutex);                  assert(r==0); }
 }
 
-/* not static*/
+static
 void time_toku_cv_fair_rwlock (void) {
     toku_cv_fair_rwlock_t mutex;
     { int r = toku_cv_fair_rwlock_init(&mutex);                  assert(r==0); }
diff --git a/src/loader.c b/src/loader.c
index 842aa09644f..a2c8e8c509d 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -24,6 +24,7 @@
 #include "ydb_load.h"
 #include <newbrt/checkpoint.h>
 #include <newbrt/brt-internal.h>
+#include <newbrt/brt_header.h>
 #include "ydb_db.h"
 
 
diff --git a/src/lock_tree/tests/test_conflict_read_table_write.c b/src/lock_tree/tests/test_conflict_read_table_write.c
index d19968a0a37..ba5046d0620 100644
--- a/src/lock_tree/tests/test_conflict_read_table_write.c
+++ b/src/lock_tree/tests/test_conflict_read_table_write.c
@@ -9,12 +9,6 @@
 
 #include "test.h"
 
-static void sortit(txnid_set *txns) {
-    size_t n = txnid_set_size(txns);
-    for (size_t i = 1; i < n; i++)
-        assert(txnid_set_get(txns, i) > txnid_set_get(txns, i-1));
-}
-
 int main(int argc, const char *argv[]) {
     int r;
 
@@ -53,8 +47,6 @@ int main(int argc, const char *argv[]) {
 
     DBT key_l; dbt_init(&key_l, "L", 1);
 
-    txnid_set conflicts; 
-
     const TXNID txn_a = 1;
     toku_lock_request a_r_t; toku_lock_request_init(&a_r_t, txn_a, toku_lt_neg_infinity, toku_lt_infinity, LOCK_REQUEST_READ);
 
diff --git a/src/ydb.c b/src/ydb.c
index 594690a8a8b..7cf28fbb6e4 100644
--- a/src/ydb.c
+++ b/src/ydb.c
@@ -34,6 +34,7 @@ const char *toku_copyright_string = "Copyright (c) 2007-2009 Tokutek Inc.  All r
 #include "ydb_load.h"
 #include <newbrt/brtloader.h>
 #include <newbrt/log_header.h>
+#include <newbrt/brt_header.h>
 #include "ydb_cursor.h"
 #include "ydb_row_lock.h"
 #include "ydb_env_func.h"
-- 
2.30.9