You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2014/09/04 00:24:46 UTC
git commit: THRIFT-2690 c_glib: Incorrect behaviour when serializing
a map with typedef'd keys
Repository: thrift
Updated Branches:
refs/heads/master d62473c3b -> 0cc6d3c7b
THRIFT-2690
c_glib: Incorrect behaviour when serializing a map with typedef'd keys
Patch: Simon South
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/0cc6d3c7
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/0cc6d3c7
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/0cc6d3c7
Branch: refs/heads/master
Commit: 0cc6d3c7bd454ad701bf5652a58a49f689babfc5
Parents: d62473c
Author: Roger Meier <ro...@apache.org>
Authored: Thu Sep 4 00:24:17 2014 +0200
Committer: Roger Meier <ro...@apache.org>
Committed: Thu Sep 4 00:24:17 2014 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_c_glib_generator.cc | 13 +++++++++++--
lib/c_glib/test/testthrifttestclient.cpp | 2 +-
2 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/0cc6d3c7/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 632dbc7..96ce99e 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -2971,8 +2971,8 @@ void t_c_glib_generator::generate_serialize_container(ofstream &out,
t_type *tval = ((t_map *) ttype)->get_val_type();
string tkey_name = type_name (tkey);
string tval_name = type_name (tval);
- string tkey_ptr = tkey->is_string() || !tkey->is_base_type() ? "" : "*";
- string tval_ptr = tval->is_string() || !tval->is_base_type() ? "" : "*";
+ string tkey_ptr;
+ string tval_ptr;
string keyname = tmp("key");
string valname = tmp("val");
@@ -2993,6 +2993,15 @@ void t_c_glib_generator::generate_serialize_container(ofstream &out,
indent() << "GList *key_list = NULL, *iter = NULL;" << endl;
declare_local_variable(out, tkey, keyname);
declare_local_variable(out, tval, valname);
+
+ /* If either the key or value type is a typedef, find its underlying type so
+ we can correctly determine how to generate a pointer to it */
+ tkey = get_true_type(tkey);
+ tval = get_true_type(tval);
+
+ tkey_ptr = tkey->is_string() || !tkey->is_base_type() ? "" : "*";
+ tval_ptr = tval->is_string() || !tval->is_base_type() ? "" : "*";
+
out <<
indent() << "g_hash_table_foreach ((GHashTable *) " << prefix <<
", thrift_hash_table_get_keys, &key_list);" << endl <<
http://git-wip-us.apache.org/repos/asf/thrift/blob/0cc6d3c7/lib/c_glib/test/testthrifttestclient.cpp
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testthrifttestclient.cpp b/lib/c_glib/test/testthrifttestclient.cpp
index 48ece70..f4e3250 100755
--- a/lib/c_glib/test/testthrifttestclient.cpp
+++ b/lib/c_glib/test/testthrifttestclient.cpp
@@ -471,7 +471,7 @@ test_thrift_client (void)
// insanity
insanity_out = (TTestInsanity *) g_object_new (T_TEST_TYPE_INSANITY, NULL);
insanity_out->userMap = g_hash_table_new (NULL, NULL);
- g_hash_table_insert (insanity_out->userMap, &enum_out, &user_id_out);
+ g_hash_table_insert (insanity_out->userMap, GINT_TO_POINTER (enum_out), &user_id_out);
xtruct1 = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
xtruct1->byte_thing = 1;