You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/01/02 18:59:09 UTC

[7/9] thrift git commit: THRIFT-3383 i64 related warnings

THRIFT-3383 i64 related warnings

This closes #764


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/bf8f7b42
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/bf8f7b42
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/bf8f7b42

Branch: refs/heads/master
Commit: bf8f7b425ee24269ae71c5431362d17a5ca475ef
Parents: 56cf779
Author: Simon South <si...@simonsouth.com>
Authored: Wed Dec 23 20:29:29 2015 -0500
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Jan 3 02:55:03 2016 +0900

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_c_glib_generator.cc |  4 +-
 lib/c_glib/test/testbinaryprotocol.c            |  2 +-
 lib/c_glib/test/testdebugproto.c                | 44 +++++----
 lib/c_glib/test/testoptionalrequired.c          |  2 +-
 lib/c_glib/test/testserialization.c             | 18 ++--
 lib/c_glib/test/testthrifttestclient.cpp        | 97 ++++++++++----------
 6 files changed, 90 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/compiler/cpp/src/generate/t_c_glib_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc
index 22d7914..0eefeb6 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -808,9 +808,11 @@ string t_c_glib_generator::constant_value(string name, t_type* type, t_const_val
     case t_base_type::TYPE_I8:
     case t_base_type::TYPE_I16:
     case t_base_type::TYPE_I32:
-    case t_base_type::TYPE_I64:
       render << value->get_integer();
       break;
+    case t_base_type::TYPE_I64:
+      render << "G_GINT64_CONSTANT (" << value->get_integer() << ")";
+      break;
     case t_base_type::TYPE_DOUBLE:
       if (value->get_type() == t_const_value::CV_INTEGER) {
         render << value->get_integer();

http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/lib/c_glib/test/testbinaryprotocol.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testbinaryprotocol.c b/lib/c_glib/test/testbinaryprotocol.c
index fa1d447..96b2019 100755
--- a/lib/c_glib/test/testbinaryprotocol.c
+++ b/lib/c_glib/test/testbinaryprotocol.c
@@ -41,7 +41,7 @@
 #define TEST_BYTE 123
 #define TEST_I16 12345
 #define TEST_I32 1234567890
-#define TEST_I64 123456789012345
+#define TEST_I64 G_GINT64_CONSTANT (123456789012345)
 #define TEST_DOUBLE 1234567890.123
 #define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
 #define TEST_PORT 51199

http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/lib/c_glib/test/testdebugproto.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testdebugproto.c b/lib/c_glib/test/testdebugproto.c
index 703dff0..47ac588 100644
--- a/lib/c_glib/test/testdebugproto.c
+++ b/lib/c_glib/test/testdebugproto.c
@@ -146,7 +146,7 @@ test_structs_one_of_each_initialize_default_values (void)
 
   g_assert_cmpint (a_bite,    ==, 0x7f);
   g_assert_cmpint (integer16, ==, 0x7fff);
-  g_assert_cmpint (integer64, ==, 10000000000);
+  g_assert_cmpint (integer64, ==, G_GINT64_CONSTANT (10000000000));
 
   g_assert (byte_list != NULL);
   g_assert_cmpint (byte_list->len, ==, 3);
@@ -179,8 +179,11 @@ test_structs_one_of_each_initialize_specified_values (void)
   static const gint16 initial_i16_list[5] = { 4181, 6765, 10946, 17711, 28657 };
   static const gint64 initial_i64_list[5] =
     {
-      1100087778366101931, 1779979416004714189, 2880067194370816120,
-      4660046610375530309, 7540113804746346429
+      G_GINT64_CONSTANT (1100087778366101931),
+      G_GINT64_CONSTANT (1779979416004714189),
+      G_GINT64_CONSTANT (2880067194370816120),
+      G_GINT64_CONSTANT (4660046610375530309),
+      G_GINT64_CONSTANT (7540113804746346429)
     };
   static const guint8 initial_base64[8] =
     {
@@ -216,22 +219,23 @@ test_structs_one_of_each_initialize_specified_values (void)
   g_array_append_vals (i64_list, initial_i64_list, 5);
 
   /* All of OneOfEach's properties can be set at construction... */
-  one_of_each = g_object_new (T_TEST_TYPE_ONE_OF_EACH,
-                              "im_true",          TRUE,
-                              "im_false",         FALSE,
-                              "a_bite",           0x50,
-                              "integer16",        0x7e57,
-                              "integer32",        0xdeadbeef,
-                              "integer64",        0xfa15efacade15bad,
-                              "double_precision", M_PI,
-                              "some_characters",  "Debug THIS!",
-                              "zomg_unicode",     "\xd7\n\a\t",
-                              "what_who",         TRUE,
-                              "base64",           base64,
-                              "byte_list",        byte_list,
-                              "i16_list",         i16_list,
-                              "i64_list",         i64_list,
-                              NULL);
+  one_of_each =
+    g_object_new (T_TEST_TYPE_ONE_OF_EACH,
+                  "im_true",          TRUE,
+                  "im_false",         FALSE,
+                  "a_bite",           0x50,
+                  "integer16",        0x7e57,
+                  "integer32",        0xdeadbeef,
+                  "integer64",        G_GINT64_CONSTANT (0xfa15efacade15bad),
+                  "double_precision", M_PI,
+                  "some_characters",  "Debug THIS!",
+                  "zomg_unicode",     "\xd7\n\a\t",
+                  "what_who",         TRUE,
+                  "base64",           base64,
+                  "byte_list",        byte_list,
+                  "i16_list",         i16_list,
+                  "i64_list",         i64_list,
+                  NULL);
   g_assert (one_of_each != NULL);
 
   g_array_unref (i64_list);
@@ -267,7 +271,7 @@ test_structs_one_of_each_initialize_specified_values (void)
   g_assert_cmphex (a_bite,    ==, 0x50);
   g_assert_cmphex (integer16, ==, 0x7e57);
   g_assert_cmphex (integer32, ==, (gint32)0xdeadbeef);
-  g_assert_cmphex (integer64, ==, 0xfa15efacade15bad);
+  g_assert_cmphex (integer64, ==, G_GINT64_CONSTANT (0xfa15efacade15bad));
 
   g_assert_cmpfloat (double_precision, ==, M_PI);
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/lib/c_glib/test/testoptionalrequired.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testoptionalrequired.c b/lib/c_glib/test/testoptionalrequired.c
index cfc96a2..60d8afd 100755
--- a/lib/c_glib/test/testoptionalrequired.c
+++ b/lib/c_glib/test/testoptionalrequired.c
@@ -201,7 +201,7 @@ test_non_set_binary (void)
   g_assert(!error);
   write_to_read (THRIFT_STRUCT (b2), THRIFT_STRUCT (b1), NULL, &error);
   g_assert(!error);
-  // OK. No segfault
+  /* OK. No segfault */
 
   g_object_unref (b1);
   g_object_unref (b2);

http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/lib/c_glib/test/testserialization.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testserialization.c b/lib/c_glib/test/testserialization.c
index 9fc6357..67d411d 100644
--- a/lib/c_glib/test/testserialization.c
+++ b/lib/c_glib/test/testserialization.c
@@ -14,12 +14,14 @@ static void enum_constants_read_write() {
   TTestEnumTestStruct* src = T_TEST_ENUM_TEST;
   TTestEnumTestStruct* dst = g_object_new(T_TEST_TYPE_ENUM_TEST_STRUCT, NULL);
   TTestEnumTestStructClass* cls = T_TEST_ENUM_TEST_STRUCT_GET_CLASS(src);
+  int write_len;
+  int read_len;
 
-  int write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
+  write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
   g_assert(!error);
   g_assert(write_len > 0);
 
-  int read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
+  read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
   g_assert(!error);
   g_assert_cmpint(write_len, ==, read_len);
 
@@ -37,12 +39,14 @@ static void struct_constants_read_write() {
   TTestCompactProtoTestStruct* src = T_TEST_COMPACT_TEST;
   TTestCompactProtoTestStruct* dst = g_object_new(T_TEST_TYPE_COMPACT_PROTO_TEST_STRUCT, NULL);
   TTestCompactProtoTestStructClass* cls = T_TEST_COMPACT_PROTO_TEST_STRUCT_GET_CLASS(src);
+  int write_len;
+  int read_len;
 
-  int write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
+  write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
   g_assert(!error);
   g_assert(write_len > 0);
 
-  int read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
+  read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
   g_assert(!error);
   g_assert_cmpint(write_len, ==, read_len);
 
@@ -60,12 +64,14 @@ static void struct_read_write_length_should_equal() {
   TTestBonk* src = g_object_new(T_TEST_TYPE_BONK, NULL);
   TTestBonk* dst = g_object_new(T_TEST_TYPE_BONK, NULL);
   TTestBonkClass* cls = T_TEST_BONK_GET_CLASS(src);
+  int write_len;
+  int read_len;
 
-  int write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
+  write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
   g_assert(!error);
   g_assert(write_len > 0);
 
-  int read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
+  read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
   g_assert(!error);
   g_assert_cmpint(write_len, ==, read_len);
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/bf8f7b42/lib/c_glib/test/testthrifttestclient.cpp
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testthrifttestclient.cpp b/lib/c_glib/test/testthrifttestclient.cpp
index e618fe9..7681cf5 100755
--- a/lib/c_glib/test/testthrifttestclient.cpp
+++ b/lib/c_glib/test/testthrifttestclient.cpp
@@ -59,128 +59,130 @@ class TestHandler : public ThriftTestIf {
   TestHandler() {}
 
   void testVoid() {
-    printf("[C -> C++] testVoid()\n");
+    cout << "[C -> C++] testVoid()" << endl;
   }
 
   void testString(string& out, const string &thing) {
-    printf("[C -> C++] testString(\"%s\")\n", thing.c_str());
+    cout << "[C -> C++] testString(\"" << thing << "\")" << endl;
     out = thing;
   }
 
   bool testBool(const bool thing) {
-    printf("[C -> C++] testBool(%s)\n", thing ? "true" : "false");
+    cout << "[C -> C++] testBool(" << (thing ? "true" : "false") << ")" << endl;
     return thing;
   }
   int8_t testByte(const int8_t thing) {
-    printf("[C -> C++] testByte(%d)\n", (int)thing);
+    cout << "[C -> C++] testByte(" << (int)thing << ")" << endl;
     return thing;
   }
   int32_t testI32(const int32_t thing) {
-    printf("[C -> C++] testI32(%d)\n", thing);
+    cout << "[C -> C++] testI32(" << thing << ")" << endl;
     return thing;
   }
 
   int64_t testI64(const int64_t thing) {
-    printf("[C -> C++] testI64(%ld)\n", thing);
+    cout << "[C -> C++] testI64(" << thing << ")" << endl;
     return thing;
   }
 
   double testDouble(const double thing) {
-    printf("[C -> C++] testDouble(%lf)\n", thing);
+    cout.precision(6);
+    cout << "[C -> C++] testDouble(" << fixed << thing << ")" << endl;
     return thing;
   }
 
   void testBinary(string& out, const string &thing) {
-    printf("[C -> C++] testBinary(\"%s\")\n", thing.c_str());
+    cout << "[C -> C++] testBinary(\"" << thing << "\")" << endl;
     out = thing;
   }
 
   void testStruct(Xtruct& out, const Xtruct &thing) {
-    printf("[C -> C++] testStruct({\"%s\", %d, %d, %ld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
+    cout << "[C -> C++] testStruct({\"" << thing.string_thing << "\", " << (int)thing.byte_thing << ", " << thing.i32_thing << ", " << thing.i64_thing << "})" << endl;
     out = thing;
   }
 
   void testNest(Xtruct2& out, const Xtruct2& nest) {
     const Xtruct &thing = nest.struct_thing;
-    printf("[C -> C++] testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
+    cout << "[C -> C++] testNest({" << (int)nest.byte_thing << ", {\"" << thing.string_thing << "\", " << (int)thing.byte_thing << ", " << thing.i32_thing << ", " << thing.i64_thing << "}, " << nest.i32_thing << "})" << endl;
     out = nest;
   }
 
   void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
-    printf("[C -> C++] testMap({");
+    cout << "[C -> C++] testMap({";
     map<int32_t, int32_t>::const_iterator m_iter;
     bool first = true;
     for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
       if (first) {
         first = false;
       } else {
-        printf(", ");
+        cout << ", ";
       }
-      printf("%d => %d", m_iter->first, m_iter->second);
+      cout << m_iter->first << " => " << m_iter->second;
     }
-    printf("})\n");
+    cout << "})" << endl;
     out = thing;
   }
 
   void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) {
-    printf("[C -> C++] testStringMap({");
+    cout << "[C -> C++] testStringMap({";
     map<std::string, std::string>::const_iterator m_iter;
     bool first = true;
     for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
       if (first) {
         first = false;
       } else {
-        printf(", ");
+        cout << ", ";
       }
-      printf("\"%s\" => \"%s\"", (m_iter->first).c_str(), (m_iter->second).c_str());
+      cout << "\"" << m_iter->first << "\" => \"" << m_iter->second << "\"";
     }
-    printf("})\n");
+    cout << "})" << endl;
     out = thing;
   }
 
 
   void testSet(set<int32_t> &out, const set<int32_t> &thing) {
-    printf("[C -> C++] testSet({");
+    cout << "[C -> C++] testSet({";
     set<int32_t>::const_iterator s_iter;
     bool first = true;
     for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
       if (first) {
         first = false;
       } else {
-        printf(", ");
+        cout << ", ";
       }
-      printf("%d", *s_iter);
+      cout << *s_iter;
     }
-    printf("})\n");
+    cout << "})" << endl;
     out = thing;
   }
 
   void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
-    printf("[C -> C++] testList({");
+    cout << "[C -> C++] testList({";
     vector<int32_t>::const_iterator l_iter;
     bool first = true;
     for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
       if (first) {
         first = false;
-      } else {        printf(", ");
+      } else {
+        cout << ", ";
       }
-      printf("%d", *l_iter);
+      cout << *l_iter;
     }
-    printf("})\n");
+    cout << "})" << endl;
     out = thing;
   }
 
   Numberz::type testEnum(const Numberz::type thing) {
-    printf("[C -> C++] testEnum(%d)\n", thing);
+    cout << "[C -> C++] testEnum(" << thing << ")" << endl;
     return thing;
   }
 
   UserId testTypedef(const UserId thing) {
-    printf("[C -> C++] testTypedef(%ld)\n", thing);
+    cout << "[C -> C++] testTypedef(" << thing << ")" << endl;
     return thing;  }
 
   void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
-    printf("[C -> C++] testMapMap(%d)\n", hello);
+    cout << "[C -> C++] testMapMap(" << hello << ")" << endl;
 
     map<int32_t,int32_t> pos;
     map<int32_t,int32_t> neg;
@@ -197,7 +199,7 @@ class TestHandler : public ThriftTestIf {
   void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
     THRIFT_UNUSED_VARIABLE (argument);
 
-    printf("[C -> C++] testInsanity()\n");
+    cout << "[C -> C++] testInsanity()" << endl;
 
     Xtruct hello;
     hello.string_thing = "Hello2";
@@ -230,37 +232,36 @@ class TestHandler : public ThriftTestIf {
     insane.insert(make_pair(1, first_map));
     insane.insert(make_pair(2, second_map));
 
-    printf("return");
-    printf(" = {");
+    cout << "return = {";
     map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
     for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
-      printf("%ld => {", i_iter->first);
+      cout << i_iter->first << " => {";
       map<Numberz::type,Insanity>::const_iterator i2_iter;
       for (i2_iter = i_iter->second.begin();
            i2_iter != i_iter->second.end();
            ++i2_iter) {
-        printf("%d => {", i2_iter->first);
+        cout << i2_iter->first << " => {";
         map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
         map<Numberz::type, UserId>::const_iterator um;
-        printf("{");
+        cout << "{";
         for (um = userMap.begin(); um != userMap.end(); ++um) {
-          printf("%d => %ld, ", um->first, um->second);
+          cout << um->first << " => " << um->second << ", ";
         }
-        printf("}, ");
+        cout << "}, ";
 
         vector<Xtruct> xtructs = i2_iter->second.xtructs;
         vector<Xtruct>::const_iterator x;
-        printf("{");
+        cout << "{";
         for (x = xtructs.begin(); x != xtructs.end(); ++x) {
-          printf("{\"%s\", %d, %d, %ld}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
+          cout << "{\"" << x->string_thing << "\", " << (int)x->byte_thing << ", " << x->i32_thing << ", " << x->i64_thing << "}, ";
         }
-        printf("}");
+        cout << "}";
 
-        printf("}, ");
+        cout << "}, ";
       }
-      printf("}, ");
+      cout << "}, ";
     }
-    printf("}\n");
+    cout << "}" << endl;
 
 
   }
@@ -270,7 +271,7 @@ class TestHandler : public ThriftTestIf {
     THRIFT_UNUSED_VARIABLE (arg4);
     THRIFT_UNUSED_VARIABLE (arg5);
 
-    printf("[C -> C++] testMulti()\n");
+    cout << "[C -> C++] testMulti()" << endl;
 
     hello.string_thing = "Hello2";
     hello.byte_thing = arg0;
@@ -281,7 +282,7 @@ class TestHandler : public ThriftTestIf {
   void testException(const std::string &arg)
     throw(Xception, apache::thrift::TException)
   {
-    printf("[C -> C++] testException(%s)\n", arg.c_str());
+    cout << "[C -> C++] testException(" << arg << ")" << endl;
     if (arg.compare("Xception") == 0) {
       Xception e;
       e.errorCode = 1001;
@@ -299,7 +300,7 @@ class TestHandler : public ThriftTestIf {
 
   void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
 
-    printf("[C -> C++] testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
+    cout << "[C -> C++] testMultiException(" << arg0 << ", " << arg1 << ")" << endl;
 
     if (arg0.compare("Xception") == 0) {
       Xception e;
@@ -318,9 +319,9 @@ class TestHandler : public ThriftTestIf {
   }
 
   void testOneway(int sleepFor) {
-    printf("testOneway(%d): Sleeping...\n", sleepFor);
+    cout << "testOneway(" << sleepFor << "): Sleeping..." << endl;
     sleep(sleepFor);
-    printf("testOneway(%d): done sleeping!\n", sleepFor);
+    cout << "testOneway(" << sleepFor << "): done sleeping!" << endl;
   }
 };