THRIFT-3632 c_glib testserialization fails with glib assertion Client: c_glib Patch: Nobuaki Sukegawa
This closes #865 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8b411a0c Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8b411a0c Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8b411a0c Branch: refs/heads/master Commit: 8b411a0c8f9f6dc4fa7f6660b5b15fe27a76741d Parents: 949e242 Author: Nobuaki Sukegawa <ns...@apache.org> Authored: Sun Feb 14 20:22:11 2016 +0900 Committer: Nobuaki Sukegawa <ns...@apache.org> Committed: Sun Feb 14 22:47:19 2016 +0900 ---------------------------------------------------------------------- compiler/cpp/src/generate/t_c_glib_generator.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/8b411a0c/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 6a349c4..3a3fe54 100644 --- a/compiler/cpp/src/generate/t_c_glib_generator.cc +++ b/compiler/cpp/src/generate/t_c_glib_generator.cc @@ -3773,7 +3773,6 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out, scope_up(out); if (ttype->is_map()) { - string length = "g_hash_table_size ((GHashTable *) " + prefix + ")"; t_type* tkey = ((t_map*)ttype)->get_key_type(); t_type* tval = ((t_map*)ttype)->get_val_type(); string tkey_name = type_name(tkey); @@ -3806,13 +3805,15 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out, << indent() << "int i = 0, key_count;" << endl << endl << indent() << "if ((ret = thrift_protocol_write_map_begin (protocol, " - << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", (gint32) " - << length << ", error)) < 0)" << endl; + << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", " << prefix << " ? " + << "(gint32) g_hash_table_size ((GHashTable *) " << prefix << ") : 0" + << ", error)) < 0)" << endl; indent_up(); out << indent() << "return " << error_ret << ";" << endl; indent_down(); out << indent() << "xfer += ret;" << endl - << indent() << "g_hash_table_foreach ((GHashTable *) " << prefix + << indent() << "if (" << prefix << ")" << endl + << indent() << " g_hash_table_foreach ((GHashTable *) " << prefix << ", thrift_hash_table_get_keys, &key_list);" << endl << indent() << "key_count = g_list_length (key_list);" << endl << indent() << "keys = g_newa (" << tkey_name << tkey_ptr @@ -3845,7 +3846,6 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out, indent_down(); out << indent() << "xfer += ret;" << endl; } else if (ttype->is_set()) { - string length = "g_hash_table_size ((GHashTable *) " + prefix + ")"; t_type* telem = ((t_set*)ttype)->get_elem_type(); string telem_name = type_name(telem); string telem_ptr = telem->is_string() || !telem->is_base_type() ? "" : "*"; @@ -3857,13 +3857,15 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out, << indent() << "THRIFT_UNUSED_VAR (value);" << endl << endl << indent() << "if ((ret = thrift_protocol_write_set_begin (protocol, " - << type_to_enum(telem) << ", (gint32) " << length << ", error)) < 0)" - << endl; + << type_to_enum(telem) << ", " << prefix << " ? " + << "(gint32) g_hash_table_size ((GHashTable *) " << prefix << ") : 0" + << ", error)) < 0)" << endl; indent_up(); out << indent() << "return " << error_ret << ";" << endl; indent_down(); out << indent() << "xfer += ret;" << endl - << indent() << "g_hash_table_foreach ((GHashTable *) " << prefix + << indent() << "if (" << prefix << ")" << endl + << indent() << " g_hash_table_foreach ((GHashTable *) " << prefix << ", thrift_hash_table_get_keys, &key_list);" << endl << indent() << "key_count = g_list_length (key_list);" << endl << indent() << "keys = g_newa (" << telem_name << telem_ptr @@ -3894,7 +3896,7 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out, indent_down(); out << indent() << "xfer += ret;" << endl; } else if (ttype->is_list()) { - string length = prefix + "->len"; + string length = "(" + prefix + " ? " + prefix + "->len : 0)"; string i = tmp("i"); out << indent() << "guint " << i << ";" << endl << endl