Repository: thrift
Updated Branches:
  refs/heads/master 5b7895886 -> 1c99e7079


THRIFT-2404 emit warning on (typically inefficient) list<byte>

Patch: Jens Geyer


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

Branch: refs/heads/master
Commit: 6fe77e8e660139dbe7ad2b52e5ca3d0e5a0de7ca
Parents: 5b78958
Author: Jens Geyer <[email protected]>
Authored: Sun Mar 16 16:48:53 2014 +0200
Committer: Jens Geyer <[email protected]>
Committed: Mon Mar 17 22:51:21 2014 +0200

----------------------------------------------------------------------
 compiler/cpp/src/main.cc    | 14 ++++++++++++++
 compiler/cpp/src/main.h     |  4 ++++
 compiler/cpp/src/thrifty.yy |  1 +
 3 files changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/6fe77e8e/compiler/cpp/src/main.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 781db3b..e1c9394 100755
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -661,6 +661,20 @@ void generate_all_fingerprints(t_program* program) {
   */
 }
 
+
+/**
+ * Emits a warning on list<byte>, binary type is typically a much better 
choice.
+ */
+void check_for_list_of_bytes(t_type* list_elem_type) {
+  if((g_parse_mode == PROGRAM) && (list_elem_type != NULL) && 
list_elem_type->is_base_type()) {
+    t_base_type* tbase = (t_base_type*)list_elem_type;
+    if(tbase->get_base() == t_base_type::TYPE_BYTE) {
+      pwarning(1,"Consider using the more efficient \"binary\" type instead of 
\"list<byte>\".");
+    }
+  }
+}
+
+
 /**
  * Prints the version number
  */

http://git-wip-us.apache.org/repos/asf/thrift/blob/6fe77e8e/compiler/cpp/src/main.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/main.h b/compiler/cpp/src/main.h
index 87af5f6..f737e3f 100644
--- a/compiler/cpp/src/main.h
+++ b/compiler/cpp/src/main.h
@@ -88,6 +88,10 @@ char* clean_up_doctext(char* doctext);
  */
 void declare_valid_program_doctext();
 
+/**
+ * Emits a warning on list<byte>, binary type is typically a much better 
choice.
+ */
+void check_for_list_of_bytes(t_type* list_elem_type);
 
 /**
  * Flex utilities

http://git-wip-us.apache.org/repos/asf/thrift/blob/6fe77e8e/compiler/cpp/src/thrifty.yy
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index fd72b70..7c4a90b 100755
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -1213,6 +1213,7 @@ ListType:
   tok_list '<' FieldType '>' CppType
     {
       pdebug("ListType -> tok_list<FieldType>");
+      check_for_list_of_bytes($3);
       $$ = new t_list($3);
       if ($5 != NULL) {
         ((t_container*)$$)->set_cpp_name(std::string($5));

Reply via email to