You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dc...@apache.org on 2019/10/08 21:51:29 UTC

[thrift] branch master updated: THRIFT-4920: Fix generation of binary string constants

This is an automated email from the ASF dual-hosted git repository.

dcelasun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new ec8c7c4  THRIFT-4920: Fix generation of binary string constants
ec8c7c4 is described below

commit ec8c7c419b1c0318e5b34a1c6e9e939b9a8681fd
Author: Elvis Pranskevichus <el...@magic.io>
AuthorDate: Tue Oct 8 17:51:19 2019 -0400

    THRIFT-4920: Fix generation of binary string constants
    
    Currently, the thrift compiler generates regular string literals for
    string constants marked as `binary`.  This makes the resulting type
    inconsistent under Python 3.
    
    Client: python
    
    This closes #1843.
---
 compiler/cpp/src/thrift/generate/t_py_generator.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index 83462f4..982bca1 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -538,6 +538,9 @@ string t_py_generator::render_const_value(t_type* type, t_const_value* value) {
     t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
     switch (tbase) {
     case t_base_type::TYPE_STRING:
+      if (((t_base_type*)type)->is_binary()) {
+        out << 'b';
+      }
       out << '"' << get_escaped_string(value) << '"';
       break;
     case t_base_type::TYPE_BOOL: