You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Simon Falsig (JIRA)" <ji...@apache.org> on 2015/02/19 14:23:11 UTC

[jira] [Comment Edited] (THRIFT-2870) C++ TJSONProtocol using locale dependent formatting

    [ https://issues.apache.org/jira/browse/THRIFT-2870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14327391#comment-14327391 ] 

Simon Falsig edited comment on THRIFT-2870 at 2/19/15 1:23 PM:
---------------------------------------------------------------

Konrad - I've finally had some more time to play around with this, based on the tests in lib/cpp/test (by running {{make check-TESTS}}):

All tests are on my own KUbuntu 12.04 with Thrift 0.9.2 and boost 1.57.

Initial (no changes to the code): All 15 tests passed

Failing (I added a {{setlocale(LC_ALL, "da_DK"));}} to the beginning of the JSONProtoTest.cpp): JSONProtoTest fails (doubles now use ',' for decimal separators)

Fixed (keeping the new locale, adding my previously posted patch): All 15 tests passed. Doing a diff on the JSON output from JSONProtoTest, it matches the output from the initial test exactly.


You were mentioning that it failed testing on your machine - what tests are you using?


was (Author: simonfalsig):
Konrad - I've finally had some more time to play around with this, based on the tests in lib/cpp/test (by running {{make check-TESTS}}):

All tests are on my own KUbuntu 12.04 with Thrift 0.9.2 and boost 1.57.

Initial (no changes to the code): All 15 tests passed

Failing (I added a {{setlocale(LC_ALL, "da_DK"));}} to the beginning of the JSONProtoTest.cpp): JSONProtoTest fails (doubles now use ',' for decimal separators)

Fixed (keeping the new locale, adding my previously posted patch): All 15 tests passed


You were mentioning that it failed testing on your machine - what tests are you using?

> C++ TJSONProtocol using locale dependent formatting
> ---------------------------------------------------
>
>                 Key: THRIFT-2870
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2870
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.9
>         Environment: Linux, Boost 1.51
>            Reporter: Simon Falsig
>         Attachments: use-classic-locale-for-cpp-json_4.patch
>
>
> I'm using Thrift for serializing objects (in C++) into JSON strings, which I then store as files. This usually works fine, but if the locale of my system is set to a locale where the decimal separator is ',' instead of '.' (for instance in Denmark), then the TJSONProtocol (specifically the writeJSONDouble function that does the double to string conversion through a boost::lexical_cast) will also use this separator when serializing doubles. 
> This kinda plays havoc with the JSON specification, which does not allow for localized formatting, and depends on always using '.' as a decimal separator. I could imagine that there may be other more subtle places where the local can have an effect, but this is currently the only place I've been having trouble with.
> I can see that the same problem has been fixed for C# (commit
> 3da317bda100130b2f615034c46b0944888f0f14 / THRIFT-1245 C# JSON Protocol uses culture-dependant decimal separator for double) but it doesn't seem as if there's a similarly easy way to fix boost::lexical_cast...
> Note that I'm using Thrift 0.9.0, but as far as I can see there hasn't been any relevant changes to TJSONProtocol.cpp since.
> Relevant thread on thrift-user mailing list can be found here: http://mail-archives.apache.org/mod_mbox/thrift-user/201412.mbox/%3c7c2463f510dbb7548b4718e202ac1e45@mail.gmail.com%3e
> I've also attached a quick patch that works on my setup (see the patch file comments for more information).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)