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 2015/08/03 22:30:34 UTC
[1/5] thrift git commit: THRIFT-3288 c_glib: Unit tests: Enable
warnings, improve automake-variable use
Repository: thrift
Updated Branches:
refs/heads/master 03f3f5510 -> b28e3ccdc
THRIFT-3288 c_glib: Unit tests: Enable warnings, improve automake-variable use
This change
- Enables the same comprehensive set of warnings ("-Wall -Wextra
-pedantic") specified for the unit tests for C++ and
- Changes the use of automake variables (e.g. AM_CPPFLAGS) to more
closely match their intended use, as specified in the automake
documentation.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/db3646fa
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/db3646fa
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/db3646fa
Branch: refs/heads/master
Commit: db3646faefcd78cebd9f3f288b71590d2d765574
Parents: 03f3f55
Author: Simon South <ss...@simonsouth.com>
Authored: Sat Aug 1 12:18:12 2015 +0000
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Aug 3 22:10:22 2015 +0200
----------------------------------------------------------------------
lib/c_glib/test/Makefile.am | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/db3646fa/lib/c_glib/test/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/Makefile.am b/lib/c_glib/test/Makefile.am
index 2a38878..0de7d2d 100755
--- a/lib/c_glib/test/Makefile.am
+++ b/lib/c_glib/test/Makefile.am
@@ -32,12 +32,12 @@ BUILT_SOURCES = \
gen-c_glib/t_test_thrift_test.h \
gen-c_glib/t_test_thrift_test_types.h
-AM_CPPFLAGS = -g -Wall -I../src $(GLIB_CFLAGS)
+AM_CPPFLAGS = -I../src
+AM_CFLAGS = -g -Wall -Wextra -pedantic $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) \
+ @GCOV_CFLAGS@
+AM_CXXFLAGS = $(AM_CFLAGS)
AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@
-CFLAGS = @GCOV_CFLAGS@
-CXXFLAGS = -g
-
check_PROGRAMS = \
testapplicationexception \
testtransportsocket \
[4/5] thrift git commit: THRIFT-3288 c_glib: Compiler: Gently
refactor functions
Posted by ro...@apache.org.
THRIFT-3288 c_glib: Compiler: Gently refactor functions
This change gently refactors a handful of recently modified
functions to
- Wrap lines at 80 columns,
- Improve readability (making the layout of the compiler's source
code more closely match that of the code it's generating),
- Use more consistently the indent_up/indent_down and
scope_up/scope_down helper functions rather than embedding
formatting characters directly, and
- Improve slightly the formatting of the generated code.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b28e3ccd
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b28e3ccd
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b28e3ccd
Branch: refs/heads/master
Commit: b28e3ccdcbd31ff4975f9b22c3d6622b7d35bb21
Parents: 38e7155
Author: Simon South <ss...@simonsouth.com>
Authored: Mon Aug 3 11:11:29 2015 +0000
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Aug 3 22:10:23 2015 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_c_glib_generator.cc | 362 ++++++++++++-------
1 file changed, 238 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/b28e3ccd/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 7bf30e3..382a7ec 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -968,25 +968,38 @@ void t_c_glib_generator::generate_const_initializer(string name,
}
}
if (field_type == NULL) {
- throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
+ throw "type error: " + type->get_name() + " has no field "
+ + v_iter->first->get_string();
}
field_name = tmp(field_name);
- generate_const_initializer(name + "_constant_" + field_name, field_type, v_iter->second);
+ generate_const_initializer(name + "_constant_" + field_name,
+ field_type,
+ v_iter->second);
initializers << " constant->" << v_iter->first->get_string() << " = "
- << constant_value(name + "_constant_" + field_name, field_type, v_iter->second)
- << ";" << endl << " constant->__isset_" << v_iter->first->get_string()
+ << constant_value(name + "_constant_" + field_name,
+ field_type,
+ v_iter->second) << ";" << endl
+ << " constant->__isset_" << v_iter->first->get_string()
<< " = TRUE;" << endl;
}
// implement the initializer
- f_types_impl_ << "static " << this->nspace << type->get_name() << " *" << endl
- << this->nspace_lc << name_lc << "_constant (void)" << endl << "{" << endl
- << " static " << this->nspace << type->get_name() << " *constant = NULL;" << endl
- << " if (constant == NULL)" << endl << " {" << endl
- << " constant = g_object_new (" << this->nspace_uc << "TYPE_" << type_uc
- << ", NULL);" << endl << initializers.str() << endl << " }" << endl
- << " return constant;" << endl << "}" << endl << endl;
+ f_types_impl_ << "static " << this->nspace << type->get_name() << " *"
+ << endl
+ << this->nspace_lc << name_lc << "_constant (void)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << indent() << "static " << this->nspace << type->get_name()
+ << " *constant = NULL;" << endl
+ << indent() << "if (constant == NULL)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << indent() << "constant = g_object_new (" << this->nspace_uc
+ << "TYPE_" << type_uc << ", NULL);" << endl
+ << initializers.str();
+ scope_down(f_types_impl_);
+ f_types_impl_ << indent() << "return constant;" << endl;
+ scope_down(f_types_impl_);
+ f_types_impl_ << endl;
} else if (type->is_list()) {
string list_type = "GPtrArray *";
// TODO: This initialization should contain a free function for container
@@ -1029,20 +1042,34 @@ void t_c_glib_generator::generate_const_initializer(string name,
generate_const_initializer(fname, etype, (*v_iter));
if (list_variable) {
initializers << " " << type_name(etype) << " " << fname << " = "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl;
- appenders << " " << list_appender << "(constant, " << fname << ");" << endl;
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ";"
+ << endl;
+ appenders << " " << list_appender << "(constant, " << fname << ");"
+ << endl;
} else {
appenders << " " << list_appender << "(constant, "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ");" << endl;
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ");"
+ << endl;
}
}
- f_types_impl_ << "static " << list_type << endl << this->nspace_lc << name_lc
- << "_constant (void)" << endl << "{" << endl << " static " << list_type
- << " constant = NULL;" << endl << " if (constant == NULL)" << endl << " {"
- << endl << initializers.str() << endl << " constant = "
- << list_initializer << endl << appenders.str() << " }" << endl
- << " return constant;" << endl << "}" << endl << endl;
+ f_types_impl_ << "static " << list_type << endl
+ << this->nspace_lc << name_lc << "_constant (void)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << indent() << "static " << list_type << " constant = NULL;"
+ << endl
+ << indent() << "if (constant == NULL)" << endl;
+ scope_up(f_types_impl_);
+ if (!initializers.str().empty()) {
+ f_types_impl_ << initializers.str()
+ << endl;
+ }
+ f_types_impl_ << indent() << "constant = " << list_initializer << endl
+ << appenders.str();
+ scope_down(f_types_impl_);
+ f_types_impl_ << indent() << "return constant;" << endl;
+ scope_down(f_types_impl_);
+ f_types_impl_ << endl;
} else if (type->is_set()) {
t_type* etype = ((t_set*)type)->get_elem_type();
const vector<t_const_value*>& val = value->get_list();
@@ -1054,18 +1081,29 @@ void t_c_glib_generator::generate_const_initializer(string name,
string fname = tmp(name);
generate_const_initializer(fname, etype, (*v_iter));
initializers << " " << type_name(etype) << " " << fname << " = "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl;
- appenders << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
- << endl;
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ";"
+ << endl;
+ appenders << " g_hash_table_insert (constant, &" << fname << ", &"
+ << fname << ");" << endl;
}
- f_types_impl_ << "static GHashTable *" << endl << this->nspace_lc << name_lc
- << "_constant (void)" << endl << "{" << endl
- << " static GHashTable *constant = NULL;" << endl << " if (constant == NULL)"
- << endl << " {" << endl << initializers.str() << endl <<
- // TODO: This initialization should contain a free function for elements
- " constant = g_hash_table_new (NULL, NULL);" << endl << appenders.str()
- << " }" << endl << " return constant;" << endl << "}" << endl << endl;
+ f_types_impl_ << "static GHashTable *" << endl
+ << this->nspace_lc << name_lc << "_constant (void)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << indent() << "static GHashTable *constant = NULL;" << endl
+ << indent() << "if (constant == NULL)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << initializers.str()
+ << endl
+ // TODO: This initialization should contain a free function
+ // for elements
+ << indent() << "constant = g_hash_table_new (NULL, NULL);"
+ << endl
+ << appenders.str();
+ scope_down(f_types_impl_);
+ f_types_impl_ << indent() << "return constant;" << endl;
+ scope_down(f_types_impl_);
+ f_types_impl_ << endl;
} else if (type->is_map()) {
t_type* ktype = ((t_map*)type)->get_key_type();
t_type* vtype = ((t_map*)type)->get_val_type();
@@ -1082,20 +1120,33 @@ void t_c_glib_generator::generate_const_initializer(string name,
generate_const_initializer(vname, vtype, (*v_iter));
initializers << " " << type_name(ktype) << " " << kname << " = "
- << constant_value(kname, (t_type*)ktype, (*v_iter)) << ";" << endl << " "
- << type_name(vtype) << " " << vname << " = "
- << constant_value(vname, (t_type*)vtype, (*v_iter)) << ";" << endl;
- appenders << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
+ << constant_value(kname, (t_type*)ktype, (*v_iter)) << ";"
+ << endl
+ << " " << type_name(vtype) << " " << vname << " = "
+ << constant_value(vname, (t_type*)vtype, (*v_iter)) << ";"
+ << endl;
+ appenders << " g_hash_table_insert (constant, &" << fname << ", &"
+ << fname << ");"
<< endl;
}
- f_types_impl_ << "static GHashTable *" << endl << this->nspace_lc << name_lc
- << "_constant (void)" << endl << "{" << endl
- << " static GHashTable *constant = NULL;" << endl << " if (constant == NULL)"
- << endl << " {" << endl << initializers.str() << endl <<
- // TODO: This initialization should contain a free function for elements
- " constant = g_hash_table_new (NULL, NULL);" << endl << appenders.str()
- << " }" << endl << " return constant;" << endl << "}" << endl << endl;
+ f_types_impl_ << "static GHashTable *" << endl
+ << this->nspace_lc << name_lc << "_constant (void)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << indent() << "static GHashTable *constant = NULL;" << endl
+ << indent() << "if (constant == NULL)" << endl;
+ scope_up(f_types_impl_);
+ f_types_impl_ << initializers.str()
+ << endl
+ // TODO: This initialization should contain a free function
+ // for elements
+ << indent() << "constant = g_hash_table_new (NULL, NULL);"
+ << endl
+ << appenders.str();
+ scope_down(f_types_impl_);
+ f_types_impl_ << indent() << "return constant;" << endl;
+ scope_down(f_types_impl_);
+ f_types_impl_ << endl;
}
}
@@ -1646,17 +1697,17 @@ void t_c_glib_generator::generate_service_client(t_service* tservice) {
}
// create the interface initializer
- f_service_ << "static void" << endl << this->nspace_lc << service_name_lc
- << "_if_interface_init (" << this->nspace << service_name_ << "IfInterface *iface)"
- << endl;
+ f_service_ << "static void" << endl
+ << this->nspace_lc << service_name_lc << "_if_interface_init ("
+ << this->nspace << service_name_ << "IfInterface *iface)" << endl;
scope_up(f_service_);
if (functions.size() > 0) {
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
/* make the function name C friendly */
string funname = initial_caps_to_underscores((*f_iter)->get_name());
- f_service_ << " iface->" << funname << " = " << this->nspace_lc << service_name_lc
- << "_client_" << funname << ";" << endl;
+ f_service_ << indent() << "iface->" << funname << " = " << this->nspace_lc
+ << service_name_lc << "_client_" << funname << ";" << endl;
}
}
else {
@@ -1666,16 +1717,19 @@ void t_c_glib_generator::generate_service_client(t_service* tservice) {
f_service_ << endl;
// create the client instance initializer
- f_service_ << "static void" << endl << this->nspace_lc << service_name_lc << "_client_init ("
- << this->nspace << service_name_ << "Client *client)" << endl << "{" << endl;
+ f_service_ << "static void" << endl
+ << this->nspace_lc << service_name_lc << "_client_init ("
+ << this->nspace << service_name_ << "Client *client)" << endl;
+ scope_up(f_service_);
if (!extends_service) {
- f_service_ << " client->input_protocol = NULL;" << endl << " client->output_protocol = NULL;"
- << endl;
+ f_service_ << indent() << "client->input_protocol = NULL;" << endl
+ << indent() << "client->output_protocol = NULL;" << endl;
}
else {
- f_service_ << " THRIFT_UNUSED_VAR (client);" << endl;
+ f_service_ << indent() << "THRIFT_UNUSED_VAR (client);" << endl;
}
- f_service_ << "}" << endl << endl;
+ scope_down(f_service_);
+ f_service_ << endl;
// create the client class initializer
f_service_ << "static void" << endl << this->nspace_lc << service_name_lc
@@ -1909,11 +1963,14 @@ void t_c_glib_generator::generate_service_handler(t_service* tservice) {
f_service_ << endl;
// Generate the handler class initializer
- f_service_ << "static void" << endl << class_name_lc << "_class_init (" << class_name
- << "Class *cls)" << endl;
+ f_service_ << "static void" << endl
+ << class_name_lc << "_class_init (" << class_name << "Class *cls)"
+ << endl;
scope_up(f_service_);
if (functions.size() > 0) {
- for (function_iter = functions.begin(); function_iter != functions.end(); ++function_iter) {
+ for (function_iter = functions.begin();
+ function_iter != functions.end();
+ ++function_iter) {
string function_name = (*function_iter)->get_name();
string method_name = initial_caps_to_underscores(function_name);
@@ -3639,36 +3696,47 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
*/
out << indent() << "GList *key_list = NULL, *iter = NULL;" << endl
<< indent() << tkey_name << tkey_ptr << "* keys;" << endl
- << indent() << "int i=0, key_count;" << endl
+ << 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 << indent() << " return " << error_ret << ";" << endl
- << indent() << "xfer += ret;" << endl
+ << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", (gint32) "
+ << length << ", 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
<< ", 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
- << ", key_count);" << endl << indent()
- << "for (iter = g_list_first (key_list); iter; iter = iter->next)" << endl << indent()
- << "{" << endl << indent() << " keys[i++] = (" << tkey_name << tkey_ptr << ") iter->data;"
- << endl << indent() << "}" << endl << indent() << "g_list_free (key_list);" << endl << endl
+ << ", key_count);" << endl
+ << indent() << "for (iter = g_list_first (key_list); iter; "
+ "iter = iter->next)" << endl;
+ indent_up();
+ out << indent() << "keys[i++] = (" << tkey_name << tkey_ptr
+ << ") iter->data;" << endl;
+ indent_down();
+ out << indent() << "g_list_free (key_list);" << endl
+ << endl
<< indent() << "for (i = 0; i < key_count; ++i)" << endl;
-
scope_up(out);
- out << indent() << keyname << " = keys[i];" << endl << indent() << valname << " = ("
- << tval_name << tval_ptr << ") g_hash_table_lookup (((GHashTable *) " << prefix
- << "), (gpointer) " << keyname << ");" << endl << endl;
+ out << indent() << keyname << " = keys[i];" << endl
+ << indent() << valname << " = (" << tval_name << tval_ptr
+ << ") g_hash_table_lookup (((GHashTable *) " << prefix
+ << "), (gpointer) " << keyname << ");" << endl
+ << endl;
generate_serialize_map_element(out,
(t_map*)ttype,
tkey_ptr + " " + keyname,
tval_ptr + " " + valname,
error_ret);
scope_down(out);
-
- out << indent() << "if ((ret = thrift_protocol_write_map_end (protocol, error)) < 0)" << endl
- << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;"
- << endl;
+ out << indent() << "if ((ret = thrift_protocol_write_map_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ 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();
@@ -3676,51 +3744,71 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
string telem_ptr = telem->is_string() || !telem->is_base_type() ? "" : "*";
out << indent() << "GList *key_list = NULL, *iter = NULL;" << endl
<< indent() << telem_name << telem_ptr << "* keys;" << endl
- << indent() << "int i=0, key_count;" << endl
- << indent() << telem_name << telem_ptr
- << " elem;" << endl << indent() << "gpointer value;" << endl << indent()
- << "THRIFT_UNUSED_VAR (value);" << endl << endl
+ << indent() << "int i = 0, key_count;" << endl
+ << indent() << telem_name << telem_ptr << " elem;" << endl
+ << indent() << "gpointer value;" << endl
+ << 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 << indent()
- << " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl << indent()
- << "g_hash_table_foreach ((GHashTable *) " << prefix
+ << type_to_enum(telem) << ", (gint32) " << length << ", 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
<< ", 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
- << ", key_count);" << endl << indent()
- << "for (iter = g_list_first (key_list); iter; iter = iter->next)" << endl << indent()
- << "{" << endl << indent() << " keys[i++] = (" << telem_name << telem_ptr
- << ") iter->data;" << endl << indent() << "}" << endl << indent()
- << "g_list_free (key_list);" << endl << endl << indent() << "for (i=0; i<key_count; ++i)"
- << endl;
-
+ << ", key_count);" << endl
+ << indent() << "for (iter = g_list_first (key_list); iter; "
+ "iter = iter->next)" << endl;
+ indent_up();
+ out << indent() << "keys[i++] = (" << telem_name << telem_ptr
+ << ") iter->data;" << endl;
+ indent_down();
+ out << indent() << "g_list_free (key_list);" << endl
+ << endl
+ << indent() << "for (i = 0; i < key_count; ++i)" << endl;
scope_up(out);
- out << indent() << "elem = keys[i];" << endl << indent()
- << "value = (gpointer) g_hash_table_lookup (((GHashTable *) " << prefix
- << "), (gpointer) elem);" << endl << endl;
- generate_serialize_set_element(out, (t_set*)ttype, telem_ptr + "elem", error_ret);
- scope_down(out);
-
- out << indent() << "if ((ret = thrift_protocol_write_set_end (protocol, error)) < 0)" << endl
- << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;"
+ out << indent() << "elem = keys[i];" << endl
+ << indent() << "value = (gpointer) g_hash_table_lookup "
+ "(((GHashTable *) " << prefix << "), (gpointer) elem);" << endl
<< endl;
+ generate_serialize_set_element(out,
+ (t_set*)ttype,
+ telem_ptr + "elem",
+ error_ret);
+ scope_down(out);
+ out << indent() << "if ((ret = thrift_protocol_write_set_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl;
} else if (ttype->is_list()) {
string length = prefix + "->len";
string i = tmp("i");
out << indent() << "guint " << i << ";" << endl
+ << endl
<< indent() << "if ((ret = thrift_protocol_write_list_begin (protocol, "
- << type_to_enum(((t_list*)ttype)->get_elem_type()) << ", (gint32) " << length
- << ", error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl
- << indent() << "xfer += ret;" << endl
- << indent() << "for (" << i << "=0; " << i << "<" << length << "; " << i << "++)" << endl;
-
+ << type_to_enum(((t_list*)ttype)->get_elem_type()) << ", (gint32) "
+ << length << ", error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl
+ << indent() << "for (" << i << " = 0; " << i << " < " << length << "; "
+ << i << "++)" << endl;
scope_up(out);
generate_serialize_list_element(out, (t_list*)ttype, prefix, i, error_ret);
scope_down(out);
-
- out << indent() << "if ((ret = thrift_protocol_write_list_end (protocol, error)) < 0)" << endl
- << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;"
- << endl;
+ out << indent() << "if ((ret = thrift_protocol_write_list_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl;
}
scope_down(out);
@@ -3958,10 +4046,14 @@ void t_c_glib_generator::generate_deserialize_container(ofstream& out,
<< indent() << "ThriftType key_type;" << endl
<< indent() << "ThriftType value_type;" << endl
<< endl
- << indent() << "/* read the map begin marker */" << endl << indent()
- << "if ((ret = thrift_protocol_read_map_begin (protocol, &key_type, &value_type, &size, "
- "error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl << indent()
- << "xfer += ret;" << endl << endl;
+ << indent() << "/* read the map begin marker */" << endl
+ << indent() << "if ((ret = thrift_protocol_read_map_begin (protocol, "
+ "&key_type, &value_type, &size, error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl
+ << endl;
// iterate over map elements
out << indent() << "/* iterate through each of the map's fields */" << endl
@@ -3972,50 +4064,72 @@ void t_c_glib_generator::generate_deserialize_container(ofstream& out,
out << endl;
// read map end
- out << indent() << "/* read the map end marker */" << endl << indent()
- << "if ((ret = thrift_protocol_read_map_end (protocol, error)) < 0)" << endl << indent()
- << " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl;
+ out << indent() << "/* read the map end marker */" << endl
+ << indent() << "if ((ret = thrift_protocol_read_map_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl;
} else if (ttype->is_set()) {
out << indent() << "guint32 size;" << endl
<< indent() << "guint32 i;" << endl
<< indent() << "ThriftType element_type;" << endl
<< endl
- << indent()
- << "if ((ret = thrift_protocol_read_set_begin (protocol, &element_type, &size, error)) < 0)"
- << endl << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;"
- << endl << endl;
+ << indent() << "if ((ret = thrift_protocol_read_set_begin (protocol, "
+ "&element_type, &size, error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl
+ << endl;
// iterate over the elements
out << indent() << "/* iterate through the set elements */" << endl
<< indent() << "for (i = 0; i < size; ++i)" << endl;
-
scope_up(out);
generate_deserialize_set_element(out, (t_set*)ttype, prefix, error_ret);
scope_down(out);
// read set end
- out << indent() << "if ((ret = thrift_protocol_read_set_end (protocol, error)) < 0)" << endl
- << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl
+ out << indent() << "if ((ret = thrift_protocol_read_set_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl
<< endl;
} else if (ttype->is_list()) {
out << indent() << "guint32 size;" << endl
<< indent() << "guint32 i;" << endl
<< indent() << "ThriftType element_type;" << endl
<< endl
- << indent() << "if ((ret = thrift_protocol_read_list_begin (protocol, &element_type, "
- "&size, error)) < 0)" << endl << indent() << " return " << error_ret << ";"
- << endl << indent() << "xfer += ret;" << endl << endl;
+ << indent() << "if ((ret = thrift_protocol_read_list_begin (protocol, "
+ "&element_type,&size, error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl
+ << endl;
+ // iterate over the elements
out << indent() << "/* iterate through list elements */" << endl
<< indent() << "for (i = 0; i < size; i++)" << endl;
-
scope_up(out);
- generate_deserialize_list_element(out, (t_list*)ttype, prefix, "i", error_ret);
+ generate_deserialize_list_element(out,
+ (t_list*)ttype,
+ prefix,
+ "i",
+ error_ret);
scope_down(out);
- out << indent() << "if ((ret = thrift_protocol_read_list_end (protocol, error)) < 0)" << endl
- << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl
- << endl;
+ // read list end
+ out << indent() << "if ((ret = thrift_protocol_read_list_end (protocol, "
+ "error)) < 0)" << endl;
+ indent_up();
+ out << indent() << "return " << error_ret << ";" << endl;
+ indent_down();
+ out << indent() << "xfer += ret;" << endl;
}
scope_down(out);
[5/5] thrift git commit: THRIFT-3288 c_glib: Compiler: Don't mix
declarations and code
Posted by ro...@apache.org.
THRIFT-3288 c_glib: Compiler: Don't mix declarations and code
This change moves variable declarations to the top of code blocks
in the generated code, resolving a number of "ISO C90 forbids mixed
declarations and code" warnings when building the unit tests.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/c83a2b51
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/c83a2b51
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/c83a2b51
Branch: refs/heads/master
Commit: c83a2b5185799f287f1548e0dc21c4cdb7bba6cd
Parents: db3646f
Author: Simon South <ss...@simonsouth.com>
Authored: Sat Aug 1 14:33:17 2015 +0000
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Aug 3 22:10:23 2015 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_c_glib_generator.cc | 126 +++++++++++--------
1 file changed, 74 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/c83a2b51/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 6603fa1..807148d 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -998,6 +998,7 @@ void t_c_glib_generator::generate_const_initializer(string name,
const vector<t_const_value*>& val = value->get_list();
vector<t_const_value*>::const_iterator v_iter;
ostringstream initializers;
+ ostringstream appenders;
list_initializer = generate_new_array_from_type(etype);
if (etype->is_base_type()) {
@@ -1028,40 +1029,42 @@ void t_c_glib_generator::generate_const_initializer(string name,
generate_const_initializer(fname, etype, (*v_iter));
if (list_variable) {
initializers << " " << type_name(etype) << " " << fname << " = "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl << " "
- << list_appender << "(constant, " << fname << ");" << endl;
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl;
+ appenders << " " << list_appender << "(constant, " << fname << ");" << endl;
} else {
- initializers << " " << list_appender << "(constant, "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ");" << endl;
+ appenders << " " << list_appender << "(constant, "
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ");" << endl;
}
}
f_types_impl_ << "static " << list_type << endl << this->nspace_lc << name_lc
<< "_constant (void)" << endl << "{" << endl << " static " << list_type
<< " constant = NULL;" << endl << " if (constant == NULL)" << endl << " {"
- << endl << " constant = " << list_initializer << endl << initializers.str()
- << endl << " }" << endl << " return constant;" << endl << "}" << endl << endl;
+ << endl << initializers.str() << endl << " constant = "
+ << list_initializer << endl << appenders.str() << " }" << endl
+ << " return constant;" << endl << "}" << endl << endl;
} else if (type->is_set()) {
t_type* etype = ((t_set*)type)->get_elem_type();
const vector<t_const_value*>& val = value->get_list();
vector<t_const_value*>::const_iterator v_iter;
ostringstream initializers;
+ ostringstream appenders;
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
string fname = tmp(name);
generate_const_initializer(fname, etype, (*v_iter));
initializers << " " << type_name(etype) << " " << fname << " = "
- << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl
- << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
- << endl;
+ << constant_value(fname, (t_type*)etype, (*v_iter)) << ";" << endl;
+ appenders << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
+ << endl;
}
f_types_impl_ << "static GHashTable *" << endl << this->nspace_lc << name_lc
<< "_constant (void)" << endl << "{" << endl
<< " static GHashTable *constant = NULL;" << endl << " if (constant == NULL)"
- << endl << " {" << endl <<
+ << endl << " {" << endl << initializers.str() << endl <<
// TODO: This initialization should contain a free function for elements
- " constant = g_hash_table_new (NULL, NULL);" << endl << initializers.str() << endl
+ " constant = g_hash_table_new (NULL, NULL);" << endl << appenders.str()
<< " }" << endl << " return constant;" << endl << "}" << endl << endl;
} else if (type->is_map()) {
t_type* ktype = ((t_map*)type)->get_key_type();
@@ -1069,6 +1072,7 @@ void t_c_glib_generator::generate_const_initializer(string name,
const vector<t_const_value*>& val = value->get_list();
vector<t_const_value*>::const_iterator v_iter;
ostringstream initializers;
+ ostringstream appenders;
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
string fname = tmp(name);
@@ -1080,17 +1084,17 @@ void t_c_glib_generator::generate_const_initializer(string name,
initializers << " " << type_name(ktype) << " " << kname << " = "
<< constant_value(kname, (t_type*)ktype, (*v_iter)) << ";" << endl << " "
<< type_name(vtype) << " " << vname << " = "
- << constant_value(vname, (t_type*)vtype, (*v_iter)) << ";" << endl
- << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
- << endl;
+ << constant_value(vname, (t_type*)vtype, (*v_iter)) << ";" << endl;
+ appenders << " g_hash_table_insert (constant, &" << fname << ", &" << fname << ");"
+ << endl;
}
f_types_impl_ << "static GHashTable *" << endl << this->nspace_lc << name_lc
<< "_constant (void)" << endl << "{" << endl
<< " static GHashTable *constant = NULL;" << endl << " if (constant == NULL)"
- << endl << " {" << endl <<
+ << endl << " {" << endl << initializers.str() << endl <<
// TODO: This initialization should contain a free function for elements
- " constant = g_hash_table_new (NULL, NULL);" << endl << initializers.str() << endl
+ " constant = g_hash_table_new (NULL, NULL);" << endl << appenders.str()
<< " }" << endl << " return constant;" << endl << "}" << endl << endl;
}
}
@@ -3598,18 +3602,6 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
string keyname = tmp("key");
string valname = tmp("val");
- /*
- * Some ugliness here. To maximize backwards compatibility, we
- * avoid using GHashTableIter and instead get a GList of all keys,
- * then copy it into a array on the stack, and free it.
- * This is because we may exit early before we get a chance to free the
- * GList.
- */
- out << indent() << "if ((ret = thrift_protocol_write_map_begin (protocol, "
- << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", (gint32) " << length
- << ", error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl
- << indent() << "xfer += ret;" << endl << endl << indent()
- << "GList *key_list = NULL, *iter = NULL;" << endl;
declare_local_variable(out, tkey, keyname);
declare_local_variable(out, tval, valname);
@@ -3621,10 +3613,26 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
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 << indent() << tkey_name << tkey_ptr
- << " keys[g_list_length (key_list)];" << endl << indent()
- << "int i=0, key_count = g_list_length (key_list);" << endl << indent()
+ /*
+ * Some ugliness here. To maximize backwards compatibility, we
+ * avoid using GHashTableIter and instead get a GList of all keys,
+ * then copy it into a array on the stack, and free it.
+ * This is because we may exit early before we get a chance to free the
+ * GList.
+ */
+ out << indent() << "GList *key_list = NULL, *iter = NULL;" << endl
+ << indent() << tkey_name << tkey_ptr << "* keys;" << endl
+ << 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 << indent() << " return " << error_ret << ";" << endl
+ << indent() << "xfer += ret;" << 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
+ << ", key_count);" << endl << indent()
<< "for (iter = g_list_first (key_list); iter; iter = iter->next)" << endl << indent()
<< "{" << endl << indent() << " keys[i++] = (" << tkey_name << tkey_ptr << ") iter->data;"
<< endl << indent() << "}" << endl << indent() << "g_list_free (key_list);" << endl << endl
@@ -3649,16 +3657,20 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
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() ? "" : "*";
- out << indent() << "if ((ret = thrift_protocol_write_set_begin (protocol, "
+ out << indent() << "GList *key_list = NULL, *iter = NULL;" << endl
+ << indent() << telem_name << telem_ptr << "* keys;" << endl
+ << indent() << "int i=0, key_count;" << endl
+ << indent() << telem_name << telem_ptr
+ << " elem;" << endl << indent() << "gpointer value;" << endl << 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 << indent()
<< " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl << indent()
- << "GList *key_list = NULL, *iter = NULL;" << endl << indent() << telem_name << telem_ptr
- << " elem;" << endl << indent() << "gpointer value;" << endl << indent()
- << "THRIFT_UNUSED_VAR (value);" << endl << endl << indent()
<< "g_hash_table_foreach ((GHashTable *) " << prefix
- << ", thrift_hash_table_get_keys, &key_list);" << endl << indent() << telem_name
- << telem_ptr << " keys[g_list_length (key_list)];" << endl << indent()
- << "int i=0, key_count = g_list_length (key_list);" << endl << indent()
+ << ", 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
+ << ", key_count);" << endl << indent()
<< "for (iter = g_list_first (key_list); iter; iter = iter->next)" << endl << indent()
<< "{" << endl << indent() << " keys[i++] = (" << telem_name << telem_ptr
<< ") iter->data;" << endl << indent() << "}" << endl << indent()
@@ -3678,10 +3690,11 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
} else if (ttype->is_list()) {
string length = prefix + "->len";
string i = tmp("i");
- out << indent() << "if ((ret = thrift_protocol_write_list_begin (protocol, "
+ out << indent() << "guint " << i << ";" << endl
+ << indent() << "if ((ret = thrift_protocol_write_list_begin (protocol, "
<< type_to_enum(((t_list*)ttype)->get_elem_type()) << ", (gint32) " << length
<< ", error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl
- << indent() << "xfer += ret;" << endl << indent() << "guint " << i << ";" << endl
+ << indent() << "xfer += ret;" << endl
<< indent() << "for (" << i << "=0; " << i << "<" << length << "; " << i << "++)" << endl;
scope_up(out);
@@ -3923,16 +3936,19 @@ void t_c_glib_generator::generate_deserialize_container(ofstream& out,
scope_up(out);
if (ttype->is_map()) {
- out << indent() << "guint32 size;" << endl << indent() << "ThriftType key_type;" << endl
- << indent() << "ThriftType value_type;" << endl << endl << indent()
- << "/* read the map begin marker */" << endl << indent()
+ out << indent() << "guint32 size;" << endl
+ << indent() << "guint32 i;" << endl
+ << indent() << "ThriftType key_type;" << endl
+ << indent() << "ThriftType value_type;" << endl
+ << endl
+ << indent() << "/* read the map begin marker */" << endl << indent()
<< "if ((ret = thrift_protocol_read_map_begin (protocol, &key_type, &value_type, &size, "
"error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl << indent()
<< "xfer += ret;" << endl << endl;
// iterate over map elements
- out << indent() << "/* iterate through each of the map's fields */" << endl << indent()
- << "guint32 i;" << endl << indent() << "for (i = 0; i < size; i++)" << endl;
+ out << indent() << "/* iterate through each of the map's fields */" << endl
+ << indent() << "for (i = 0; i < size; i++)" << endl;
scope_up(out);
generate_deserialize_map_element(out, (t_map*)ttype, prefix, error_ret);
scope_down(out);
@@ -3943,15 +3959,18 @@ void t_c_glib_generator::generate_deserialize_container(ofstream& out,
<< "if ((ret = thrift_protocol_read_map_end (protocol, error)) < 0)" << endl << indent()
<< " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl;
} else if (ttype->is_set()) {
- out << indent() << "guint32 size;" << endl << indent() << "ThriftType element_type;" << endl
+ out << indent() << "guint32 size;" << endl
+ << indent() << "guint32 i;" << endl
+ << indent() << "ThriftType element_type;" << endl
+ << endl
<< indent()
<< "if ((ret = thrift_protocol_read_set_begin (protocol, &element_type, &size, error)) < 0)"
<< endl << indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;"
<< endl << endl;
// iterate over the elements
- out << indent() << "/* iterate through the set elements */" << endl << indent() << "guint32 i;"
- << endl << indent() << "for (i = 0; i < size; ++i)" << endl;
+ out << indent() << "/* iterate through the set elements */" << endl
+ << indent() << "for (i = 0; i < size; ++i)" << endl;
scope_up(out);
generate_deserialize_set_element(out, (t_set*)ttype, prefix, error_ret);
@@ -3962,13 +3981,16 @@ void t_c_glib_generator::generate_deserialize_container(ofstream& out,
<< indent() << " return " << error_ret << ";" << endl << indent() << "xfer += ret;" << endl
<< endl;
} else if (ttype->is_list()) {
- out << indent() << "guint32 size;" << endl << indent() << "ThriftType element_type;" << endl
+ out << indent() << "guint32 size;" << endl
+ << indent() << "guint32 i;" << endl
+ << indent() << "ThriftType element_type;" << endl
+ << endl
<< indent() << "if ((ret = thrift_protocol_read_list_begin (protocol, &element_type, "
"&size, error)) < 0)" << endl << indent() << " return " << error_ret << ";"
<< endl << indent() << "xfer += ret;" << endl << endl;
- out << indent() << "/* iterate through list elements */" << endl << indent() << "guint32 i;"
- << endl << indent() << "for (i = 0; i < size; i++)" << endl;
+ out << indent() << "/* iterate through list elements */" << endl
+ << indent() << "for (i = 0; i < size; i++)" << endl;
scope_up(out);
generate_deserialize_list_element(out, (t_list*)ttype, prefix, "i", error_ret);
[2/5] thrift git commit: THRIFT-3288 c_glib: Compiler: Silence
unused-parameter warnings
Posted by ro...@apache.org.
THRIFT-3288 c_glib: Compiler: Silence unused-parameter warnings
This change modifies the generated class and interface initializers
so they don't generate "unused parameter" warnings when compiled.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7bc907a9
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7bc907a9
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7bc907a9
Branch: refs/heads/master
Commit: 7bc907a95931985792e11713eb38244259f1b926
Parents: c83a2b5
Author: Simon South <ss...@simonsouth.com>
Authored: Sat Aug 1 14:53:22 2015 +0000
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Aug 3 22:10:23 2015 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_c_glib_generator.cc | 49 +++++++++++++-------
1 file changed, 33 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/7bc907a9/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 807148d..7bf30e3 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -1648,15 +1648,22 @@ void t_c_glib_generator::generate_service_client(t_service* tservice) {
// create the interface initializer
f_service_ << "static void" << endl << this->nspace_lc << service_name_lc
<< "_if_interface_init (" << this->nspace << service_name_ << "IfInterface *iface)"
- << endl << "{" << endl;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- /* make the function name C friendly */
- string funname = initial_caps_to_underscores((*f_iter)->get_name());
+ << endl;
+ scope_up(f_service_);
+ if (functions.size() > 0) {
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
+ /* make the function name C friendly */
+ string funname = initial_caps_to_underscores((*f_iter)->get_name());
- f_service_ << " iface->" << funname << " = " << this->nspace_lc << service_name_lc
- << "_client_" << funname << ";" << endl;
+ f_service_ << " iface->" << funname << " = " << this->nspace_lc << service_name_lc
+ << "_client_" << funname << ";" << endl;
+ }
}
- f_service_ << "}" << endl << endl;
+ else {
+ f_service_ << indent() << "THRIFT_UNUSED_VAR (iface);" << endl;
+ }
+ scope_down(f_service_);
+ f_service_ << endl;
// create the client instance initializer
f_service_ << "static void" << endl << this->nspace_lc << service_name_lc << "_client_init ("
@@ -1879,11 +1886,16 @@ void t_c_glib_generator::generate_service_handler(t_service* tservice) {
<< "_if_interface_init (" << this->nspace << service_name_ << "IfInterface *iface)"
<< endl;
scope_up(f_service_);
- for (function_iter = functions.begin(); function_iter != functions.end(); ++function_iter) {
- string method_name = initial_caps_to_underscores((*function_iter)->get_name());
+ if (functions.size() > 0) {
+ for (function_iter = functions.begin(); function_iter != functions.end(); ++function_iter) {
+ string method_name = initial_caps_to_underscores((*function_iter)->get_name());
- f_service_ << indent() << "iface->" << method_name << " = " << class_name_lc << "_"
- << method_name << ";" << endl;
+ f_service_ << indent() << "iface->" << method_name << " = " << class_name_lc << "_"
+ << method_name << ";" << endl;
+ }
+ }
+ else {
+ f_service_ << "THRIFT_UNUSED_VAR (iface);" << endl;
}
scope_down(f_service_);
f_service_ << endl;
@@ -1900,12 +1912,17 @@ void t_c_glib_generator::generate_service_handler(t_service* tservice) {
f_service_ << "static void" << endl << class_name_lc << "_class_init (" << class_name
<< "Class *cls)" << endl;
scope_up(f_service_);
- for (function_iter = functions.begin(); function_iter != functions.end(); ++function_iter) {
- string function_name = (*function_iter)->get_name();
- string method_name = initial_caps_to_underscores(function_name);
+ if (functions.size() > 0) {
+ for (function_iter = functions.begin(); function_iter != functions.end(); ++function_iter) {
+ string function_name = (*function_iter)->get_name();
+ string method_name = initial_caps_to_underscores(function_name);
- // All methods are pure virtual and must be implemented by subclasses
- f_service_ << indent() << "cls->" << method_name << " = NULL;" << endl;
+ // All methods are pure virtual and must be implemented by subclasses
+ f_service_ << indent() << "cls->" << method_name << " = NULL;" << endl;
+ }
+ }
+ else {
+ f_service_ << indent() << "THRIFT_UNUSED_VAR (cls);" << endl;
}
scope_down(f_service_);
f_service_ << endl;
[3/5] thrift git commit: THRIFT-3288 c_glib: Build unit tests without
compiler warnings
Posted by ro...@apache.org.
THRIFT-3288 c_glib: Build unit tests without compiler warnings
These changes allow the unit tests for C (GLib) to build without
compiler warnings, even with additional warnings enabled. They
include
- Disabling string-function optimizations when glibc is used, as
these produce compiler warnings when a string function is used
within a call to assert ();
- Remove the "LL" suffix (added in C99) from 64-bit integer
literals;
- Replace C++-style ("//") comments with C-style equivalents;
- Remove unused constant declarations that generated warnings;
and
- Mark (or remove, from main ()) unused function parameters.
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/38e7155c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/38e7155c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/38e7155c
Branch: refs/heads/master
Commit: 38e7155c039f1dba6dd73a3114dd3a5ac7052418
Parents: 7bc907a
Author: Simon South <ss...@simonsouth.com>
Authored: Mon Aug 3 10:51:16 2015 +0000
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Aug 3 22:10:23 2015 +0200
----------------------------------------------------------------------
lib/c_glib/test/testbinaryprotocol.c | 12 ++++++++++--
lib/c_glib/test/testbufferedtransport.c | 3 ---
lib/c_glib/test/testframedtransport.c | 3 ---
lib/c_glib/test/testoptionalrequired.c | 4 ++--
lib/c_glib/test/testsimpleserver.c | 5 +++++
lib/c_glib/test/teststruct.c | 8 ++++++++
lib/c_glib/test/testthrifttestclient.cpp | 12 ++++++++++--
lib/c_glib/test/testtransportsocket.c | 3 ---
8 files changed, 35 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testbinaryprotocol.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testbinaryprotocol.c b/lib/c_glib/test/testbinaryprotocol.c
index c6de385..517fd25 100755
--- a/lib/c_glib/test/testbinaryprotocol.c
+++ b/lib/c_glib/test/testbinaryprotocol.c
@@ -17,6 +17,14 @@
* under the License.
*/
+/* Disable string-function optimizations when glibc is used, as these produce
+ compiler warnings about string length when a string function is used inside
+ a call to assert () */
+#include <features.h>
+#ifdef __GLIBC__
+#define __NO_STRING_INLINES 1
+#endif
+
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@@ -33,7 +41,7 @@
#define TEST_BYTE 123
#define TEST_I16 12345
#define TEST_I32 1234567890
-#define TEST_I64 123456789012345LL
+#define TEST_I64 123456789012345
#define TEST_DOUBLE 1234567890.123
#define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
#define TEST_PORT 51199
@@ -654,7 +662,7 @@ thrift_server_complex_types (const int port)
thrift_binary_protocol_read_string (protocol, &message_name, NULL);
g_object_unref (client);
- // TODO: investigate g_object_unref (tbp);
+ /* TODO: investigate g_object_unref (tbp); */
g_object_unref (tsocket);
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testbufferedtransport.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testbufferedtransport.c b/lib/c_glib/test/testbufferedtransport.c
index e4bee69..3203a66 100755
--- a/lib/c_glib/test/testbufferedtransport.c
+++ b/lib/c_glib/test/testbufferedtransport.c
@@ -31,9 +31,6 @@
#include "../src/thrift/c_glib/transport/thrift_buffered_transport.c"
-static const char TEST_ADDRESS[] = "localhost";
-static const short TEST_PORT = 64444;
-
static void thrift_server (const int port);
/* test object creation and destruction */
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testframedtransport.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testframedtransport.c b/lib/c_glib/test/testframedtransport.c
index 7261ff5..d50ff23 100755
--- a/lib/c_glib/test/testframedtransport.c
+++ b/lib/c_glib/test/testframedtransport.c
@@ -30,9 +30,6 @@
#include "../src/thrift/c_glib/transport/thrift_framed_transport.c"
-static const char TEST_ADDRESS[] = "localhost";
-static const short TEST_PORT = 64444;
-
static void thrift_server (const int port);
/* test object creation and destruction */
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testoptionalrequired.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testoptionalrequired.c b/lib/c_glib/test/testoptionalrequired.c
index 931d8be..ae0c3d2 100755
--- a/lib/c_glib/test/testoptionalrequired.c
+++ b/lib/c_glib/test/testoptionalrequired.c
@@ -74,7 +74,7 @@ test_simple (void)
s2 = g_object_new (T_TEST_TYPE_SIMPLE, NULL);
s3 = g_object_new (T_TEST_TYPE_SIMPLE, NULL);
- // write-to-read with optional fields
+ /* write-to-read with optional fields */
s1->im_optional = 10;
assert (s1->__isset_im_default == FALSE);
assert (s1->__isset_im_optional == FALSE);
@@ -174,7 +174,7 @@ test_tricky4 (void)
t2 = g_object_new (T_TEST_TYPE_TRICKY2, NULL);
t3 = g_object_new (T_TEST_TYPE_TRICKY3, NULL);
- // throws protocol exception
+ /* throws protocol exception */
write_to_read (THRIFT_STRUCT (t2), THRIFT_STRUCT (t3), NULL, &read_error);
assert (read_error != NULL);
g_error_free (read_error);
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testsimpleserver.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testsimpleserver.c b/lib/c_glib/test/testsimpleserver.c
index cb270b4..3af2eeb 100755
--- a/lib/c_glib/test/testsimpleserver.c
+++ b/lib/c_glib/test/testsimpleserver.c
@@ -53,6 +53,11 @@ gboolean
test_processor_process (ThriftProcessor *processor, ThriftProtocol *in,
ThriftProtocol *out, GError **error)
{
+ THRIFT_UNUSED_VAR (processor);
+ THRIFT_UNUSED_VAR (in);
+ THRIFT_UNUSED_VAR (out);
+ THRIFT_UNUSED_VAR (error);
+
return FALSE;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/teststruct.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/teststruct.c b/lib/c_glib/test/teststruct.c
index a1b3cc0..5d4baf3 100755
--- a/lib/c_glib/test/teststruct.c
+++ b/lib/c_glib/test/teststruct.c
@@ -51,6 +51,10 @@ gint32
thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
GError **error)
{
+ THRIFT_UNUSED_VAR (object);
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+
return 0;
}
@@ -58,6 +62,10 @@ gint32
thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
GError **error)
{
+ THRIFT_UNUSED_VAR (object);
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+
return 0;
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testthrifttestclient.cpp
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testthrifttestclient.cpp b/lib/c_glib/test/testthrifttestclient.cpp
index a80ddf3..e1737cd 100755
--- a/lib/c_glib/test/testthrifttestclient.cpp
+++ b/lib/c_glib/test/testthrifttestclient.cpp
@@ -191,6 +191,8 @@ 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");
Xtruct hello;
@@ -260,6 +262,10 @@ class TestHandler : public ThriftTestIf {
}
void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) {
+ THRIFT_UNUSED_VARIABLE (arg3);
+ THRIFT_UNUSED_VARIABLE (arg4);
+ THRIFT_UNUSED_VARIABLE (arg5);
+
printf("[C -> C++] testMulti()\n");
hello.string_thing = "Hello2";
@@ -582,11 +588,13 @@ test_thrift_client (void)
static void
bailout (int signum)
{
+ THRIFT_UNUSED_VARIABLE (signum);
+
exit (1);
}
int
-main (int argc, char **argv)
+main (void)
{
int status;
int pid = fork ();
@@ -607,7 +615,7 @@ main (int argc, char **argv)
sleep (1);
test_thrift_client ();
kill (pid, SIGINT);
- wait (&status) == pid;
+ assert (wait (&status) == pid);
}
return 0;
http://git-wip-us.apache.org/repos/asf/thrift/blob/38e7155c/lib/c_glib/test/testtransportsocket.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/test/testtransportsocket.c b/lib/c_glib/test/testtransportsocket.c
index bb1d47c..d91507f 100755
--- a/lib/c_glib/test/testtransportsocket.c
+++ b/lib/c_glib/test/testtransportsocket.c
@@ -70,9 +70,6 @@ my_send(int socket, const void *buffer, size_t length, int flags)
#undef recv
#undef send
-static const char TEST_ADDRESS[] = "localhost";
-static const short TEST_PORT = 64444;
-
static void thrift_socket_server (const int port);
/* test object creation and destruction */