You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by cl...@apache.org on 2010/11/04 21:35:15 UTC

svn commit: r1031222 - in /thrift/trunk/lib/cpp: src/concurrency/ src/transport/ test/

Author: clavoie
Date: Thu Nov  4 20:35:15 2010
New Revision: 1031222

URL: http://svn.apache.org/viewvc?rev=1031222&view=rev
Log:
THRIFT-916: Fix warnings in C++ when compiling with -Wall.

Modified:
    thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp
    thrift/trunk/lib/cpp/src/concurrency/TimerManager.cpp
    thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
    thrift/trunk/lib/cpp/src/transport/TZlibTransport.cpp
    thrift/trunk/lib/cpp/src/transport/TZlibTransport.h
    thrift/trunk/lib/cpp/test/TBufferBaseTest.cpp
    thrift/trunk/lib/cpp/test/TFileTransportTest.cpp
    thrift/trunk/lib/cpp/test/TransportTest.cpp
    thrift/trunk/lib/cpp/test/ZlibTest.cpp

Modified: thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp (original)
+++ thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp Thu Nov  4 20:35:15 2010
@@ -339,7 +339,6 @@ class ThreadManager::Worker: public Runn
   void ThreadManager::Impl::addWorker(size_t value) {
   std::set<shared_ptr<Thread> > newThreads;
   for (size_t ix = 0; ix < value; ix++) {
-    class ThreadManager::Worker;
     shared_ptr<ThreadManager::Worker> worker = shared_ptr<ThreadManager::Worker>(new ThreadManager::Worker(this));
     newThreads.insert(threadFactory_->newThread(worker));
   }

Modified: thrift/trunk/lib/cpp/src/concurrency/TimerManager.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/concurrency/TimerManager.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/concurrency/TimerManager.cpp (original)
+++ thrift/trunk/lib/cpp/src/concurrency/TimerManager.cpp Thu Nov  4 20:35:15 2010
@@ -60,7 +60,6 @@ class TimerManager::Task : public Runnab
 
  private:
   shared_ptr<Runnable> runnable_;
-  class TimerManager::Dispatcher;
   friend class TimerManager::Dispatcher;
   STATE state_;
 };

Modified: thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp (original)
+++ thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp Thu Nov  4 20:35:15 2010
@@ -741,8 +741,10 @@ bool TFileTransport::isEventCorrupted() 
   } else if( ((offset_ + readState_.bufferPtr_ - 4)/chunkSize_) !=
              ((offset_ + readState_.bufferPtr_ + readState_.event_->eventSize_ - 1)/chunkSize_) ) {
     // 3. size indicates that event crosses chunk boundary
-    T_ERROR("Read corrupt event. Event crosses chunk boundary. Event size:%u  Offset:%ld",
-            readState_.event_->eventSize_, offset_ + readState_.bufferPtr_ + 4);
+    T_ERROR("Read corrupt event. Event crosses chunk boundary. Event size:%u  Offset:%lld",
+            readState_.event_->eventSize_,
+            (long long int) (offset_ + readState_.bufferPtr_ + 4));
+
     return true;
   }
 
@@ -781,8 +783,9 @@ void TFileTransport::performRecovery() {
       readState_.resetState(readState_.lastDispatchPtr_);
       currentEvent_ = NULL;
       char errorMsg[1024];
-      sprintf(errorMsg, "TFileTransport: log file corrupted at offset: %lu",
-              offset_ + readState_.lastDispatchPtr_);
+      sprintf(errorMsg, "TFileTransport: log file corrupted at offset: %lld",
+              (long long int) (offset_ + readState_.lastDispatchPtr_));
+              
       GlobalOutput(errorMsg);
       throw TTransportException(errorMsg);
     }
@@ -815,7 +818,7 @@ void TFileTransport::seekToChunk(int32_t
 
   // cannot seek past EOF
   bool seekToEnd = false;
-  uint32_t minEndOffset = 0;
+  off_t minEndOffset = 0;
   if (chunk >= numChunks) {
     T_DEBUG("Trying to seek past EOF. Seeking to EOF instead...");
     seekToEnd = true;

Modified: thrift/trunk/lib/cpp/src/transport/TZlibTransport.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/transport/TZlibTransport.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/transport/TZlibTransport.cpp (original)
+++ thrift/trunk/lib/cpp/src/transport/TZlibTransport.cpp Thu Nov  4 20:35:15 2010
@@ -131,14 +131,14 @@ inline int TZlibTransport::readAvail() {
 }
 
 uint32_t TZlibTransport::read(uint8_t* buf, uint32_t len) {
-  int need = len;
+  uint32_t need = len;
 
   // TODO(dreiss): Skip urbuf on big reads.
 
   while (true) {
     // Copy out whatever we have available, then give them the min of
     // what we have and what they want, then advance indices.
-    int give = std::min(readAvail(), need);
+    int give = std::min((uint32_t) readAvail(), need);
     memcpy(buf, urbuf_ + urpos_, give);
     need -= give;
     buf += give;
@@ -233,12 +233,12 @@ void TZlibTransport::write(const uint8_t
 
   // zlib's "deflate" function has enough logic in it that I think
   // we're better off (performance-wise) buffering up small writes.
-  if ((int)len > MIN_DIRECT_DEFLATE_SIZE) {
+  if (len > MIN_DIRECT_DEFLATE_SIZE) {
     flushToZlib(uwbuf_, uwpos_, Z_NO_FLUSH);
     uwpos_ = 0;
     flushToZlib(buf, len, Z_NO_FLUSH);
   } else if (len > 0) {
-    if (uwbuf_size_ - uwpos_ < (int)len) {
+    if (uwbuf_size_ - uwpos_ < len) {
       flushToZlib(uwbuf_, uwpos_, Z_NO_FLUSH);
       uwpos_ = 0;
     }

Modified: thrift/trunk/lib/cpp/src/transport/TZlibTransport.h
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/transport/TZlibTransport.h?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/transport/TZlibTransport.h (original)
+++ thrift/trunk/lib/cpp/src/transport/TZlibTransport.h Thu Nov  4 20:35:15 2010
@@ -226,7 +226,7 @@ class TZlibTransport : public TVirtualTr
  protected:
   // Writes smaller than this are buffered up.
   // Larger (or equal) writes are dumped straight to zlib.
-  static const int MIN_DIRECT_DEFLATE_SIZE = 32;
+  static const uint32_t MIN_DIRECT_DEFLATE_SIZE = 32;
 
   boost::shared_ptr<TTransport> transport_;
 
@@ -238,10 +238,10 @@ class TZlibTransport : public TVirtualTr
   /// True iff we have finished the output stream.
   bool output_finished_;
 
-  int urbuf_size_;
-  int crbuf_size_;
-  int uwbuf_size_;
-  int cwbuf_size_;
+  uint32_t urbuf_size_;
+  uint32_t crbuf_size_;
+  uint32_t uwbuf_size_;
+  uint32_t cwbuf_size_;
 
   uint8_t* urbuf_;
   uint8_t* crbuf_;

Modified: thrift/trunk/lib/cpp/test/TBufferBaseTest.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/test/TBufferBaseTest.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/test/TBufferBaseTest.cpp (original)
+++ thrift/trunk/lib/cpp/test/TBufferBaseTest.cpp Thu Nov  4 20:35:15 2010
@@ -164,7 +164,7 @@ void init_data() {
 
   // Repeatability.  Kind of.
   std::srand(42);
-  for (int i = 0; i < (int)(sizeof(data)/sizeof(data[0])); ++i) {
+  for (size_t i = 0; i < (sizeof(data)/sizeof(data[0])); ++i) {
     data[i] = (uint8_t)rand();
   }
 
@@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE( test_BufferedTrans
     1<<14, 1<<17,
   };
 
-  for (int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
+  for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
     int size = sizes[i];
     for (int d1 = 0; d1 < 3; d1++) {
       shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
@@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE( test_BufferedTrans
     1<<14, 1<<17,
   };
 
-  for (int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
+  for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
     int size = sizes[i];
     for (int d1 = 0; d1 < 3; d1++) {
       shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(data, sizeof(data)));
@@ -462,7 +462,7 @@ BOOST_AUTO_TEST_CASE( test_BufferedTrans
     1<<14, 1<<17,
   };
 
-  for (int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
+  for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
     int size = sizes[i];
     for (int d1 = 0; d1 < 3; d1++) {
       shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(data, sizeof(data)));
@@ -496,7 +496,7 @@ BOOST_AUTO_TEST_CASE( test_FramedTranspo
     1<<14, 1<<17,
   };
 
-  for (int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
+  for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
     int size = sizes[i];
     for (int d1 = 0; d1 < 3; d1++) {
       shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
@@ -559,9 +559,9 @@ BOOST_AUTO_TEST_CASE( test_FramedTranspo
 
   int probs[] = { 1, 2, 4, 8, 16, 32, };
 
-  for (int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
+  for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
     int size = sizes[i];
-    for (int j = 0; j < sizeof (probs) / sizeof (probs[0]); j++) {
+    for (size_t j = 0; j < sizeof (probs) / sizeof (probs[0]); j++) {
       int prob = probs[j];
       for (int d1 = 0; d1 < 3; d1++) {
         shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
@@ -592,7 +592,7 @@ BOOST_AUTO_TEST_CASE( test_FramedTranspo
         int read_offset = 0;
         int read_index = 0;
 
-        for (int k = 0; k < flush_sizes.size(); k++) {
+        for (unsigned int k = 0; k < flush_sizes.size(); k++) {
           int fsize = flush_sizes[k];
           // We are exploiting an implementation detail of TFramedTransport.
           // The read buffer starts empty and it will never do more than one

Modified: thrift/trunk/lib/cpp/test/TFileTransportTest.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/test/TFileTransportTest.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/test/TFileTransportTest.cpp (original)
+++ thrift/trunk/lib/cpp/test/TFileTransportTest.cpp Thu Nov  4 20:35:15 2010
@@ -272,7 +272,8 @@ void test_flush_max_us_impl(uint32_t flu
   const FsyncLog::CallList* calls = log.getCalls();
   // We added 1 fsync call above.
   // Make sure TFileTransport called fsync at least once
-  BOOST_CHECK_GT(calls->size(), 1);
+  BOOST_CHECK_GT(calls->size(),
+                 static_cast<FsyncLog::CallList::size_type>(1));
 
   const struct timeval* prev_time = NULL;
   for (FsyncLog::CallList::const_iterator it = calls->begin();
@@ -346,9 +347,6 @@ void print_usage(FILE* f, const char* ar
 }
 
 void parse_args(int argc, char* argv[]) {
-  int seed;
-  int *seedptr = NULL;
-
   struct option long_opts[] = {
     { "help", false, NULL, 'h' },
     { "tmp-dir", true, NULL, 't' },

Modified: thrift/trunk/lib/cpp/test/TransportTest.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/test/TransportTest.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/test/TransportTest.cpp (original)
+++ thrift/trunk/lib/cpp/test/TransportTest.cpp Thu Nov  4 20:35:15 2010
@@ -575,8 +575,8 @@ void test_read_part_available() {
   transports.out->flush();
   set_trigger(3, transports.out, 1);
   uint32_t bytes_read = transports.in->read(read_buf, 10);
-  BOOST_CHECK_EQUAL(numTriggersFired, 0);
-  BOOST_CHECK_EQUAL(bytes_read, 9);
+  BOOST_CHECK_EQUAL(numTriggersFired, (unsigned int) 0);
+  BOOST_CHECK_EQUAL(bytes_read, (uint32_t) 9);
 
   clear_triggers();
 }
@@ -615,7 +615,7 @@ void test_read_partial_midframe() {
 
   // Now read 4 bytes, so that we are partway through the written data.
   uint32_t bytes_read = transports.in->read(read_buf, 4);
-  BOOST_CHECK_EQUAL(bytes_read, 4);
+  BOOST_CHECK_EQUAL(bytes_read, (uint32_t) 4);
 
   // Now attempt to read 10 bytes.  Only 9 more are available.
   //
@@ -628,13 +628,13 @@ void test_read_partial_midframe() {
   while (total_read < 9) {
     set_trigger(3, transports.out, 1);
     bytes_read = transports.in->read(read_buf, 10);
-    BOOST_REQUIRE_EQUAL(numTriggersFired, 0);
-    BOOST_REQUIRE_GT(bytes_read, 0);
+    BOOST_REQUIRE_EQUAL(numTriggersFired, (unsigned int) 0);
+    BOOST_REQUIRE_GT(bytes_read, (uint32_t) 0);
     total_read += bytes_read;
-    BOOST_REQUIRE_LE(total_read, 9);
+    BOOST_REQUIRE_LE(total_read, (uint32_t) 9);
   }
 
-  BOOST_CHECK_EQUAL(total_read, 9);
+  BOOST_CHECK_EQUAL(total_read, (uint32_t) 9);
 
   clear_triggers();
 }
@@ -656,7 +656,7 @@ void test_borrow_part_available() {
   set_trigger(3, transports.out, 1);
   uint32_t borrow_len = 10;
   const uint8_t* borrowed_buf = transports.in->borrow(read_buf, &borrow_len);
-  BOOST_CHECK_EQUAL(numTriggersFired, 0);
+  BOOST_CHECK_EQUAL(numTriggersFired, (unsigned int) 0);
   BOOST_CHECK(borrowed_buf == NULL);
 
   clear_triggers();
@@ -682,11 +682,11 @@ void test_read_none_available() {
   add_trigger(1, transports.out, 8);
   uint32_t bytes_read = transports.in->read(read_buf, 10);
   if (bytes_read == 0) {
-    BOOST_CHECK_EQUAL(numTriggersFired, 0);
+    BOOST_CHECK_EQUAL(numTriggersFired, (unsigned int) 0);
     clear_triggers();
   } else {
-    BOOST_CHECK_EQUAL(numTriggersFired, 1);
-    BOOST_CHECK_EQUAL(bytes_read, 2);
+    BOOST_CHECK_EQUAL(numTriggersFired, (unsigned int) 1);
+    BOOST_CHECK_EQUAL(bytes_read, (uint32_t) 2);
   }
 
   clear_triggers();
@@ -706,7 +706,7 @@ void test_borrow_none_available() {
   uint32_t borrow_len = 10;
   const uint8_t* borrowed_buf = transports.in->borrow(NULL, &borrow_len);
   BOOST_CHECK(borrowed_buf == NULL);
-  BOOST_CHECK_EQUAL(numTriggersFired, 0);
+  BOOST_CHECK_EQUAL(numTriggersFired, (unsigned int) 0);
 
   clear_triggers();
 }

Modified: thrift/trunk/lib/cpp/test/ZlibTest.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/test/ZlibTest.cpp?rev=1031222&r1=1031221&r2=1031222&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/test/ZlibTest.cpp (original)
+++ thrift/trunk/lib/cpp/test/ZlibTest.cpp Thu Nov  4 20:35:15 2010
@@ -234,7 +234,7 @@ void test_read_write_mix(const uint8_t* 
     }
     uint32_t got = zlib_trans->read(mirror.get() + tot, read_len);
     BOOST_REQUIRE_LE(got, expected_read_len);
-    BOOST_REQUIRE_NE(got, 0);
+    BOOST_REQUIRE_NE(got, (uint32_t) 0);
     tot += got;
   }
 
@@ -325,7 +325,7 @@ void test_no_write() {
     TZlibTransport w_zlib_trans(membuf);
   }
 
-  BOOST_CHECK_EQUAL(membuf->available_read(), 0);
+  BOOST_CHECK_EQUAL(membuf->available_read(), (uint32_t) 0);
 }
 
 /*