From: David Reiss Date: Sat, 9 Feb 2008 02:51:43 +0000 (+0000) Subject: Thrift: Fix a bug with local reflection and namespaces. X-Git-Tag: 0.2.0~1000 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=407c9e7865ba63409bb842b9286f18fb3d19abc5;p=common%2Fthrift.git Thrift: Fix a bug with local reflection and namespaces. Summary: References to "local reflections" in other thrift files were not given namespace prefixes, give undefined symbol errors. This change distinguishes between relfection names being generated for declarations (not namespaced) and those that could be external references (namespaced). Reviewed By: mcslee Test Plan: Got the following files to build and link correctly with -dense. ==> test1.thrift <== cpp_namespace ns enum foo { bar } ==> test2.thrift <== include "test1.thrift" enum dummy_enum_workaround { I_AM_A_WORKAROUND } struct baz { 1: test1.foo qux } Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665472 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 011f5eb6..eb4b1dcf 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -659,7 +659,7 @@ void t_cpp_generator::generate_local_reflection(std::ofstream& out, indent_up(); for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { indent(out) << "&" << - local_reflection_name("typespec", (*m_iter)->get_type()) << "," << endl; + local_reflection_name("typespec", (*m_iter)->get_type(), true) << "," << endl; } indent(out) << "&" << local_reflection_name("typespec", g_type_void) << "," << endl; @@ -2861,7 +2861,7 @@ string t_cpp_generator::type_to_enum(t_type* type) { /** * Returns the symbol name of the local reflection of a type. */ -string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype) { +string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype, bool external) { ttype = get_true_type(ttype); // We have to use the program name as part of the identifier because @@ -2870,6 +2870,7 @@ string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype) // trlo = Thrift Reflection LOcal. string prog; string name; + string nspace; // TODO(dreiss): Would it be better to pregenerate the base types // and put them in Thrift.{h,cpp} ? @@ -2891,7 +2892,13 @@ string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype) name = ttype->get_ascii_fingerprint(); } - return string() + "trlo_" + prefix + "_" + prog + "_" + name; + if (external && + ttype->get_program() != NULL && + ttype->get_program() != program_) { + nspace = namespace_prefix(ttype->get_program()->get_cpp_namespace()); + } + + return nspace + "trlo_" + prefix + "_" + prog + "_" + name; } string t_cpp_generator::get_include_prefix(const t_program& program) const { diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h index bdbaf7d6..ac11e3d3 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.h +++ b/compiler/cpp/src/generate/t_cpp_generator.h @@ -150,7 +150,7 @@ class t_cpp_generator : public t_oop_generator { std::string function_signature(t_function* tfunction, std::string prefix="", bool name_params=true); std::string argument_list(t_struct* tstruct, bool name_params=true); std::string type_to_enum(t_type* ttype); - std::string local_reflection_name(const char*, t_type* ttype); + std::string local_reflection_name(const char*, t_type* ttype, bool external=false); // These handles checking gen_dense_ and checking for duplicates. void generate_local_reflection(std::ofstream& out, t_type* ttype, bool is_definition);