Skip to content

Commit

Permalink
Fixed msgpack#1087 for C++.
Browse files Browse the repository at this point in the history
Treat signaling NaN correctly.
Introduced f32 to preserve signaling/quiet NaN.
Updated zlib on CI.
  • Loading branch information
redboltz committed Aug 28, 2023
1 parent b2f056c commit 377be64
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/depends/zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ while getopts "b:t:p:" c; do
done

mkdir $prefix || exit 1
wget https://zlib.net/zlib-1.2.13.tar.gz || exit 1
tar -xf zlib-1.2.13.tar.gz || exit 1
cd zlib-1.2.13
wget https://zlib.net/zlib-1.3.tar.gz || exit 1
tar -xf zlib-1.3.tar.gz || exit 1
cd zlib-1.3

build()
{
Expand Down
14 changes: 7 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ environment:
boost_subdir: lib32-msvc-14.0
build_script:
- ps: |
appveyor DownloadFile http://zlib.net/zlib-1.2.13.tar.gz -FileName zlib-1.2.13.tar.gz
7z x zlib-1.2.13.tar.gz 2> $null
7z x zlib-1.2.13.tar 2> $null
cd zlib-1.2.13
appveyor DownloadFile http://zlib.net/zlib-1.3.tar.gz -FileName zlib-1.3.tar.gz
7z x zlib-1.3.tar.gz 2> $null
7z x zlib-1.3.tar 2> $null
cd zlib-1.3
md build
md prefix
cd build
cmake `
-G $env:msvc `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.2.13\prefix" `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.3\prefix" `
..
if ($LastExitCode -ne 0) { exit $LastExitCode }
Expand All @@ -52,7 +52,7 @@ build_script:
-D MSGPACK_BUILD_EXAMPLES=ON `
-D MSGPACK_BUILD_TESTS=ON `
-D CMAKE_EXE_LINKER_FLAGS=/LIBPATH:"$env:boost_prefix\$env:boost_subdir" `
-D CMAKE_PREFIX_PATH="$env:boost_prefix;$env:APPVEYOR_BUILD_FOLDER\zlib-1.2.13\prefix" `
-D CMAKE_PREFIX_PATH="$env:boost_prefix;$env:APPVEYOR_BUILD_FOLDER\zlib-1.3\prefix" `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\prefix" `
-D CMAKE_CXX_FLAGS="/D_VARIADIC_MAX=10 /EHsc /DBOOST_ALL_DYN_LINK" `
..
Expand All @@ -62,5 +62,5 @@ build_script:
if ($LastExitCode -ne 0) { exit $LastExitCode }
test_script:
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.13\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release;%boost_prefix%\%boost_subdir%
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\zlib-1.3\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release;%boost_prefix%\%boost_subdir%
- ctest -VV -C Release
12 changes: 9 additions & 3 deletions include/msgpack/v1/adaptor/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace adaptor {
template <>
struct convert<float> {
msgpack::object const& operator()(msgpack::object const& o, float& v) const {
if(o.type == msgpack::type::FLOAT32 || o.type == msgpack::type::FLOAT64) {
if(o.type == msgpack::type::FLOAT32) {
v = o.via.f32;
}
else if (o.type == msgpack::type::FLOAT64) {
v = static_cast<float>(o.via.f64);
}
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
Expand Down Expand Up @@ -56,7 +59,10 @@ struct pack<float> {
template <>
struct convert<double> {
msgpack::object const& operator()(msgpack::object const& o, double& v) const {
if(o.type == msgpack::type::FLOAT32 || o.type == msgpack::type::FLOAT64) {
if (o.type == msgpack::type::FLOAT32) {
v = static_cast<double>(o.via.f32);
}
else if (o.type == msgpack::type::FLOAT64) {
v = o.via.f64;
}
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
Expand Down Expand Up @@ -86,7 +92,7 @@ template <>
struct object<float> {
void operator()(msgpack::object& o, float v) const {
o.type = msgpack::type::FLOAT32;
o.via.f64 = static_cast<double>(v);
o.via.f32 = v;
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/msgpack/v1/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class object_parser {
if (!v.visit_negative_integer(m_current->via.i64)) return;
break;
case msgpack::type::FLOAT32:
if (!v.visit_float32(static_cast<float>(m_current->via.f64))) return;
if (!v.visit_float32(m_current->via.f32)) return;
break;
case msgpack::type::FLOAT64:
if (!v.visit_float64(m_current->via.f64)) return;
Expand Down Expand Up @@ -717,7 +717,7 @@ struct object_with_zone<msgpack::object> {
}
bool visit_float32(float v) {
m_ptr->type = msgpack::type::FLOAT32;
m_ptr->via.f64 = v;
m_ptr->via.f32 = v;
return true;
}
bool visit_float64(double v) {
Expand Down Expand Up @@ -910,7 +910,7 @@ struct object_equal_visitor {
return true;
}
bool visit_float32(float v) {
if (m_ptr->type != msgpack::type::FLOAT32 || m_ptr->via.f64 != v) {
if (m_ptr->type != msgpack::type::FLOAT32 || m_ptr->via.f32 != v) {
m_result = false;
return false;
}
Expand Down
1 change: 1 addition & 0 deletions include/msgpack/v1/object_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct object {
double dec; // obsolete
#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
double f64;
float f32;
msgpack::object_array array;
msgpack::object_map map;
msgpack::object_str str;
Expand Down
2 changes: 1 addition & 1 deletion include/msgpack/v1/unpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ inline void unpack_int64(int64_t d, msgpack::object& o)
else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } }

inline void unpack_float(float d, msgpack::object& o)
{ o.type = msgpack::type::FLOAT32; o.via.f64 = d; }
{ o.type = msgpack::type::FLOAT32; o.via.f32 = d; }

inline void unpack_double(double d, msgpack::object& o)
{ o.type = msgpack::type::FLOAT64; o.via.f64 = d; }
Expand Down
2 changes: 1 addition & 1 deletion include/msgpack/v2/create_object_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class create_object_visitor : public msgpack::v2::null_visitor {
bool visit_float32(float v) {
msgpack::object* obj = m_stack.back();
obj->type = msgpack::type::FLOAT32;
obj->via.f64 = v;
obj->via.f32 = v;
return true;
}
bool visit_float64(double v) {
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ LIST (APPEND check_PROGRAMS
msgpack_stream.cpp
msgpack_tuple.cpp
msgpack_vref.cpp
nan.cpp
object.cpp
object_with_zone.cpp
pack_unpack.cpp
Expand Down
Loading

0 comments on commit 377be64

Please sign in to comment.