Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug on solaris #717

Closed
1NF1N1TTY opened this issue Jun 9, 2022 · 6 comments · Fixed by #719
Closed

bug on solaris #717

1NF1N1TTY opened this issue Jun 9, 2022 · 6 comments · Fixed by #719

Comments

@1NF1N1TTY
Copy link

When parsing the int field information in JSON message on Solaris, the value obtained is incorrect. The order of the numbers is chaotic.
Here are some codes.
"recvMsg " is a JSON string that needs to be parsed.

boost::json::object recvJson = boost::json::parse(recvMsg.c_str()).as_object();
boost::json::array playSequence = recvJson["playSequence"].as_array();
for (boost::json::value info : playSequence)
{
    boost::json::object infoJson = info.as_object();
    long long cameraId = infoJson["cameraNumber"].as_int64();
    printf("cameraid : %lld\n",cameraId);
}

The correct value is 11739859, but the actual value is 37119589. The order of numbers has changed.
We tested normally on windows10 (with MSVC v143), but there was a problem on Solaris 11.4.42.111.0.(sparcv9 ,with GCC v11.2.0).
We tested 1_ 78_ 0 and 1_ 79_ 0, their performance is the same.
2022-06-08 104326

@mclow mclow transferred this issue from boostorg/boost Jun 9, 2022
@pdimov
Copy link
Member

pdimov commented Jun 9, 2022

Endianness issue?

@pdimov
Copy link
Member

pdimov commented Jun 9, 2022

11,739,859 = 0xB322D3
37,119,589 = 0x2366665

doesn't look like it.

Oh, the digits are swapped. 1173 -> 3711, 9859 -> 9589.

#ifdef BOOST_JSON_BIG_ENDIAN
r = (((r * 10 + w3) * 10 + w2) * 10 + w1) * 10 + w0;
#else
r = (((r * 10 + w0) * 10 + w1) * 10 + w2) * 10 + w3;
#endif
#endif

BOOST_JSON_BIG_ENDIAN isn't being set correctly (that is, at all).

#131

See here for the logic for detecting endianness: https://github.com/boostorg/endian/blob/develop/include/boost/endian/detail/order.hpp

@grisumbras
Copy link
Member

We'll just add a dependency on Endian

@pdimov
Copy link
Member

pdimov commented Jun 9, 2022

Why? Just define the macro in config.hpp properly.

#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define BOOST_JSON_BIG_ENDIAN
#elif defined(__BIG_ENDIAN__)
# define BOOST_JSON_BIG_ENDIAN
#endif

@vinniefalco
Copy link
Member

As a workaround for now the user can set the macro when building the lib

@1NF1N1TTY
Copy link
Author

After defining "BOOST_JSON_BIG_ENDIAN" in "config.hpp", the problem was solved. Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants