From a3a8f83482386c2d79edd161d323a576fd5b36bc Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Wed, 1 Aug 2012 17:28:35 -0700 Subject: [PATCH] Fix "gcc -Wall" warnings for assoc-thrift code. Summary: Test Plan: Reviewers: CC: Task ID: # Blame Rev: --- thrift/assoc.h | 13 +++++++------ thrift/openhandles.h | 6 +++--- thrift/server_options.h | 7 +++---- thrift/server_utils.cpp | 7 ++++--- thrift/test/simpletest.cpp | 6 ++---- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/thrift/assoc.h b/thrift/assoc.h index 719f27d815..b4c75943f6 100644 --- a/thrift/assoc.h +++ b/thrift/assoc.h @@ -55,6 +55,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { int64_t id2, AssocVisibility visibility, bool update_count, const Text& wormhole_comment) { printf("taoAssocDelete\n"); + return 0; } void taoAssocRangeGet(std::vector & _return, @@ -254,7 +255,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { assocType, id1, 0, 0, 0, 0, Tleveldb::UNUSED1); } if (value.size() != sizeof(int64_t)) { - printf("expected %lld got %lld\n", sizeof(int64_t), value.size()); + printf("expected %ld got %ld\n", sizeof(int64_t), value.size()); throw generate_exception(tableName, Code::kNotFound, "Bad sizes for count ", assocType, id1, 0, 0, 0, 0, Tleveldb::UNUSED1); @@ -286,7 +287,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { char* keybuf = &dummy[0]; int rowkeysize = makeRowKey(keybuf, id1, assocType); - for (int index = 0; index < id2s.size(); index++) { + for (unsigned int index = 0; index < id2s.size(); index++) { int64_t id2 = id2s[index]; // query column 'm'$id2 @@ -308,7 +309,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { continue; } ASSERT_NE(ts, 0); - printf("XXX ts = %lld\n", ts); + printf("XXX ts = %ld\n", ts); // this assoc is visible, scan 'p'$ts$id2 to retrieve payload. keysize = appendRowKeyForPayload(rowkeysize, keybuf, ts, id2); @@ -406,7 +407,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { // inline char* copy_int64_switch_endian(char* dest, int64_t id) { char* src = (char *)&id + sizeof(id) - 1; - for (int i = 0; i < sizeof(id); i++) { + for (unsigned int i = 0; i < sizeof(id); i++) { *dest++ = *src--; } return dest; @@ -415,7 +416,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { // extracts a int64 type from the char stream. Swaps endianness. inline void extract_int64(int64_t* dest, char* src) { src += sizeof(int64_t) - 1; - for (int i = 0; i < sizeof(uint64_t); i++) { + for (unsigned int i = 0; i < sizeof(uint64_t); i++) { *dest++ = *src--; } } @@ -434,7 +435,7 @@ class AssocServiceHandler : virtual public AssocServiceIf { int64_t ts, AssocVisibility vis) { char result[1024]; sprintf(result, - "id1=%d assocType=%d id2=%d id1Type=%d id2Type=%d ts=%d vis=%d ", + "id1=%ld assocType=%ld id2=%ld id1Type=%ld id2Type=%ld ts=%ld vis=%d ", id1, assocType, id2, id1Type, id2Type, ts, vis); fprintf(stderr, "assoc_server error table %s: %s errorCode=%d %s", tableName.c_str(), message, errorCode, result); diff --git a/thrift/openhandles.h b/thrift/openhandles.h index a08ce68e5b..5052862d3c 100644 --- a/thrift/openhandles.h +++ b/thrift/openhandles.h @@ -83,7 +83,7 @@ struct onehandle { const leveldb::Snapshot* lookupSnapshot(int64_t id) { auto p = snaplist.find(id); if (p == snaplist.end()) { - fprintf(stderr, "get:No snaphot with id %d\n", id); + fprintf(stderr, "get:No snaphot with id %ld\n", id); return NULL; } return p->second->lsnap; @@ -113,7 +113,7 @@ struct onehandle { leveldb::Iterator* lookupIterator(int64_t id) { auto p = iterlist.find(id); if (p == iterlist.end()) { - fprintf(stderr, "lookupIterator:No iterator with id %d\n", id); + fprintf(stderr, "lookupIterator:No iterator with id %ld\n", id); return NULL; } return p->second->liter; @@ -144,7 +144,7 @@ class OpenHandles { // Inserts a new database into the list. // If the database is already open, increase refcount. // If the database is not already open, open and insert into list. - int64_t add(leveldb::Options& options, Text dbname, std::string dbdir) { + void add(leveldb::Options& options, Text dbname, std::string dbdir) { struct onehandle* found = head_[dbname]; if (found == NULL) { found = new onehandle; diff --git a/thrift/server_options.h b/thrift/server_options.h index 5967de0abb..40a16edd1a 100644 --- a/thrift/server_options.h +++ b/thrift/server_options.h @@ -62,16 +62,15 @@ public: // otherwise returns false. bool parseOptions(int argc, char** argv) { int n; - long l; + uint64_t l; char junk; - char* cports = NULL; for (int i = 1; i < argc; i++) { if (sscanf(argv[i], "--port=%d%c", &n, &junk) == 1) { port_ = n; } else if (sscanf(argv[i], "--threads=%d%c", &n, &junk) == 1) { num_threads_ = n; - } else if (sscanf(argv[i], "--cache_size=%ld%c", &n, &junk) == 1) { - cache_size_ = n; + } else if (sscanf(argv[i], "--cache_size=%ld%c", &l, &junk) == 1) { + cache_size_ = l; } else if (sscanf(argv[i], "--cache_numshardbits=%d%c", &n, &junk) == 1) { cache_numshardbits_ = n; } else if (strncmp(argv[i], "--hostname=", 10) == 0) { diff --git a/thrift/server_utils.cpp b/thrift/server_utils.cpp index b4ab6d9764..f015db68b9 100644 --- a/thrift/server_utils.cpp +++ b/thrift/server_utils.cpp @@ -131,7 +131,7 @@ class DBHandler : virtual public DBIf { leveldb::WriteBatch lbatch; woptions.sync = options.sync; leveldb::Slice key, value; - for (int i = 0; i < batch.size(); i++) { + for (unsigned int i = 0; i < batch.size(); i++) { kv one = batch[i]; key.data_ = one.key.data.data(); key.size_ = one.key.size; @@ -374,10 +374,10 @@ class DBHandler : virtual public DBIf { // check special ranges. if (start->size_ == 0) { - start == NULL; + start = NULL; } if (stop->size_ == 0) { - stop == NULL; + stop = NULL; } db->CompactRange(start, stop); return Code::kOk; @@ -392,6 +392,7 @@ class DBHandler : virtual public DBIf { static void* startOneService(void *arg) { TSimpleServer* t = (TSimpleServer *)arg; t->serve(); + return NULL; } diff --git a/thrift/test/simpletest.cpp b/thrift/test/simpletest.cpp index a4a4253a0b..135449e39f 100644 --- a/thrift/test/simpletest.cpp +++ b/thrift/test/simpletest.cpp @@ -26,13 +26,11 @@ static DBHandle dbhandle; static DBClient* dbclient; static AssocServiceClient* aclient; static const Text dbname = "test-dhruba"; -static pthread_t serverThread; static int ARGC; static char** ARGV; static void cleanupDir(std::string dir) { // remove old data, if any - int ret = unlink(dir.c_str()); char* cleanup = new char[100]; snprintf(cleanup, 100, "rm -rf %s", dir.c_str()); system(cleanup); @@ -247,10 +245,10 @@ static void testAssocs() { aclient->taoAssocGet(readback, dbname, assocType, id1, id2list); printf("AssocGet suceeded.\n"); - printf("size = %lld\n", readback.size()); + printf("size = %lu\n", readback.size()); ASSERT_EQ(1, readback.size()); ASSERT_EQ(id1Type, readback[0].id1Type); - printf("XXX %lld %lld\n", id1Type, readback[0].id1Type); + printf("XXX %ld %ld\n", id1Type, readback[0].id1Type); ASSERT_EQ(id2Type, readback[0].id2Type); ASSERT_EQ(ts, readback[0].time); ASSERT_EQ(dataVersion, readback[0].dataVersion);