From 5121034bb803023b8164dfcfec0e82d05a6530f6 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 29 Dec 2015 15:24:13 +0200 Subject: [PATCH 01/31] CMake will no longer complain that the minimum CMake version is not specified for test/CMakeLists.txt. --- test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c698af4..4af75bd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,5 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + find_package(GTestSrc) IF(GTESTSRC_FOUND) From caa4d22d1680f22e26c07f3a2c47354f121479da Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Tue, 29 Dec 2015 18:15:52 +0200 Subject: [PATCH 02/31] Initial attempt at moving travis to containerized infrastructure. --- .travis.yml | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index be06f35..0f7cfc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ language: cpp - +sudo: false +cache: + - ccache compiler: - clang - gcc +addons: {apt: {packages: &default_packages [cmake, valgrind, doxygen]}} env: matrix: - CONF=debug ARCH=x86_64 @@ -11,31 +14,35 @@ env: - CONF=debug ARCH=x86 - CONF=release ARCH=x86 global: + - USE_CCACHE=1 + - CCACHE_SLOPPINESS=pch_defines,time_macros + - CCACHE_COMPRESS=1 + - CCACHE_MAXSIZE=100M - ARCH_FLAGS_x86='-m32' # #266: don't use SSE on 32-bit - ARCH_FLAGS_x86_64='-msse4.2' # use SSE4.2 on 64-bit - GITHUB_REPO='miloyip/rapidjson' - secure: "HrsaCb+N66EG1HR+LWH1u51SjaJyRwJEDzqJGYMB7LJ/bfqb9mWKF1fLvZGk46W5t7TVaXRDD5KHFx9DPWvKn4gRUVkwTHEy262ah5ORh8M6n/6VVVajeV/AYt2C0sswdkDBDO4Xq+xy5gdw3G8s1A4Inbm73pUh+6vx+7ltBbk=" -before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq cmake valgrind - - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi - -install: true +matrix: + include: + env: CONF=debug ARCH=x86 + addons: {apt: {packages: [*default_packages, g++-multilib, libc6-dbg:i386]}} + include: + env: CONF=release ARCH=x86 + addons: {apt: {packages: [*default_packages, g++-multilib, libc6-dbg:i386]}} before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), # exposed by merging PR#163 (using -march=native) + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then export GCOV_FLAGS='--coverage'; fi - sed -i "s/-march=native//" CMakeLists.txt - - mkdir build + - mkdir build - > eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; - (cd build && cmake + (cd build && cmake -DRAPIDJSON_HAS_STDSTRING=ON - -DCMAKE_VERBOSE_MAKEFILE=ON - -DCMAKE_BUILD_TYPE=$CONF + -DCMAKE_VERBOSE_MAKEFILE=ON + -DCMAKE_BUILD_TYPE=$CONF -DCMAKE_CXX_FLAGS="$ARCH_FLAGS $GCOV_FLAGS" -DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS ..) @@ -48,4 +55,5 @@ script: - make travis_doc after_success: - - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then pip install --user cpp-coveralls; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h; fi From feadfad2660cd5cc332f99b14bb3ec78bb3d02d3 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 12:18:39 +0200 Subject: [PATCH 03/31] Fix syntax errors. --- .travis.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f7cfc0..a0feeb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,13 @@ compiler: - clang - gcc -addons: {apt: {packages: &default_packages [cmake, valgrind, doxygen]}} +addons: + apt: + packages: &default_packages + - cmake + - valgrind + - doxygen + env: matrix: - CONF=debug ARCH=x86_64 @@ -26,10 +32,20 @@ env: matrix: include: env: CONF=debug ARCH=x86 - addons: {apt: {packages: [*default_packages, g++-multilib, libc6-dbg:i386]}} + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 include: env: CONF=release ARCH=x86 - addons: {apt: {packages: [*default_packages, g++-multilib, libc6-dbg:i386]}} + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), From 6d97d8bf7166afddbdb650bd0414d02b68432814 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 12:32:26 +0200 Subject: [PATCH 04/31] Fixed bash syntax error. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a0feeb7..3b3b91f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,4 +72,4 @@ script: after_success: - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then pip install --user cpp-coveralls; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h; fi From 4fadfa5c223a8ea7fadd53cce228319f55cb6aea Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 13:06:53 +0200 Subject: [PATCH 05/31] Corrected the build matrix and removed inline logic. --- .travis.yml | 66 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b3b91f..a52ac2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,26 +31,51 @@ env: matrix: include: - env: CONF=debug ARCH=x86 - addons: - apt: - packages: - - *default_packages - - g++-multilib - - libc6-dbg:i386 - include: - env: CONF=release ARCH=x86 - addons: - apt: - packages: - - *default_packages - - g++-multilib - - libc6-dbg:i386 + - env: CONF=debug ARCH=x86 + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + - env: CONF=release ARCH=x86 + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + - env: CONF=debug ARCH=x86 GCOV_FLAGS='--coverage' + compiler: gcc + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + after_success: + - ./travis-coveralls.sh + - env: CONF=debug ARCH=x86_64 GCOV_FLAGS='--coverage' + compiler: gcc + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + after_success: + - ./travis-coveralls.sh + # These jobs report code coverage so they need extra environment variables + # and commands + exclude: + - env: CONF=debug ARCH=x86_64 + compiler: gcc + - env: CONF=debug ARCH=x86 + compiler: gcc before_script: -# hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), -# exposed by merging PR#163 (using -march=native) - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then export GCOV_FLAGS='--coverage'; fi + # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), + # exposed by merging PR#163 (using -march=native) - sed -i "s/-march=native//" CMakeLists.txt - mkdir build - > @@ -69,7 +94,4 @@ script: - make examples - ctest -V `[ "$CONF" = "release" ] || echo "-E perftest"` - make travis_doc - -after_success: - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then pip install --user cpp-coveralls; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h; fi + From 6400ab8d18cf115f67698f7014c3d2bb9bad6979 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 13:10:39 +0200 Subject: [PATCH 06/31] Added the missing coveralls script. --- travis-coveralls.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 travis-coveralls.sh diff --git a/travis-coveralls.sh b/travis-coveralls.sh new file mode 100755 index 0000000..7825265 --- /dev/null +++ b/travis-coveralls.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +pip install --user cpp-coveralls +coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h From 2a7836c96119f0f6a248845753b440561389d2b2 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 13:11:39 +0200 Subject: [PATCH 07/31] Cached python packages as well for faster coverage reporting. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a52ac2d..7cabb6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: cpp sudo: false cache: - ccache + - pip compiler: - clang - gcc @@ -94,4 +95,3 @@ script: - make examples - ctest -V `[ "$CONF" = "release" ] || echo "-E perftest"` - make travis_doc - From 291bcf94b0245af34608e92eb2e32524da9f9e54 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:01:44 +0200 Subject: [PATCH 08/31] Fixed path to coverage script. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cabb6e..4aae68c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ matrix: - g++-multilib - libc6-dbg:i386 after_success: - - ./travis-coveralls.sh + - ../travis-coveralls.sh - env: CONF=debug ARCH=x86_64 GCOV_FLAGS='--coverage' compiler: gcc addons: @@ -65,7 +65,7 @@ matrix: - g++-multilib - libc6-dbg:i386 after_success: - - ./travis-coveralls.sh + - ../travis-coveralls.sh # These jobs report code coverage so they need extra environment variables # and commands exclude: From 1f43a6f0b2b743a8e031d1e88bc77204665e4300 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:07:32 +0200 Subject: [PATCH 09/31] Added comment. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4aae68c..179b4cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,7 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 + # coverage report - env: CONF=debug ARCH=x86 GCOV_FLAGS='--coverage' compiler: gcc addons: From 3a01a252425c1b80cac0b730060c5185a1a31ce5 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:09:36 +0200 Subject: [PATCH 10/31] Explictly specify compiler in the matrix. --- .travis.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.travis.yml b/.travis.yml index 179b4cb..fe7f617 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,15 @@ env: matrix: include: - env: CONF=debug ARCH=x86 + compiler: gcc + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + - env: CONF=debug ARCH=x86 + compiler: clang addons: apt: packages: @@ -40,6 +49,15 @@ matrix: - g++-multilib - libc6-dbg:i386 - env: CONF=release ARCH=x86 + compiler: gcc + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + - env: CONF=release ARCH=x86 + compiler: clang addons: apt: packages: From c3cd3edad2dd78eabc1d48ec7ab052614c468db2 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:52:11 +0200 Subject: [PATCH 11/31] Explictly specify the entire matrix. --- .travis.yml | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe7f617..bced68d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,6 @@ sudo: false cache: - ccache - pip -compiler: - - clang - - gcc addons: apt: @@ -15,11 +12,6 @@ addons: - doxygen env: - matrix: - - CONF=debug ARCH=x86_64 - - CONF=release ARCH=x86_64 - - CONF=debug ARCH=x86 - - CONF=release ARCH=x86 global: - USE_CCACHE=1 - CCACHE_SLOPPINESS=pch_defines,time_macros @@ -32,22 +24,6 @@ env: matrix: include: - - env: CONF=debug ARCH=x86 - compiler: gcc - addons: - apt: - packages: - - *default_packages - - g++-multilib - - libc6-dbg:i386 - - env: CONF=debug ARCH=x86 - compiler: clang - addons: - apt: - packages: - - *default_packages - - g++-multilib - - libc6-dbg:i386 - env: CONF=release ARCH=x86 compiler: gcc addons: @@ -56,6 +32,18 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 + - env: CONF=release ARCH=x86_64 + compiler: gcc + - env: CONF=debug ARCH=x86 + compiler: clang + addons: + apt: + packages: + - *default_packages + - g++-multilib + - libc6-dbg:i386 + - env: CONF=debug ARCH=x86_64 + compiler: clang - env: CONF=release ARCH=x86 compiler: clang addons: @@ -64,6 +52,8 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 + - env: CONF=release ARCH=x86_64 + compiler: clang # coverage report - env: CONF=debug ARCH=x86 GCOV_FLAGS='--coverage' compiler: gcc @@ -85,13 +75,6 @@ matrix: - libc6-dbg:i386 after_success: - ../travis-coveralls.sh - # These jobs report code coverage so they need extra environment variables - # and commands - exclude: - - env: CONF=debug ARCH=x86_64 - compiler: gcc - - env: CONF=debug ARCH=x86 - compiler: gcc before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), From db11011a5c12e4efa0e27a915737f5af4765454c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:55:24 +0200 Subject: [PATCH 12/31] Script seems to fail to report coverage. Explictly specifying the commands. --- .travis.yml | 6 ++++-- travis-coveralls.sh | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) delete mode 100755 travis-coveralls.sh diff --git a/.travis.yml b/.travis.yml index bced68d..640c24d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,8 @@ matrix: - g++-multilib - libc6-dbg:i386 after_success: - - ../travis-coveralls.sh + - pip install --user cpp-coveralls + - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h - env: CONF=debug ARCH=x86_64 GCOV_FLAGS='--coverage' compiler: gcc addons: @@ -74,7 +75,8 @@ matrix: - g++-multilib - libc6-dbg:i386 after_success: - - ../travis-coveralls.sh + - pip install --user cpp-coveralls + - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), diff --git a/travis-coveralls.sh b/travis-coveralls.sh deleted file mode 100755 index 7825265..0000000 --- a/travis-coveralls.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -pip install --user cpp-coveralls -coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h From 3186e31b579c2b2151a3a8d4c965969dd3d0b4e1 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Wed, 30 Dec 2015 15:57:44 +0200 Subject: [PATCH 13/31] Print cache statistics. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 640c24d..981ea37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -81,6 +81,7 @@ matrix: before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), # exposed by merging PR#163 (using -march=native) + - ccache -s - sed -i "s/-march=native//" CMakeLists.txt - mkdir build - > From 84c56130d2cdc4ea378e5d9e33d68cf983467fcc Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 11:56:39 +0200 Subject: [PATCH 14/31] Adjust CMakeLists.txt files to use ccache when it's available. --- CMakeLists.txt | 6 ++++++ test/perftest/CMakeLists.txt | 6 ++++++ test/unittest/CMakeLists.txt | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51ee620..89a7634 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,12 @@ if(RAPIDJSON_HAS_STDSTRING) add_definitions(-DRAPIDJSON_HAS_STDSTRING) endif() +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index 4121bf9..f698382 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -9,6 +9,12 @@ target_link_libraries(perftest ${TEST_LIBRARIES}) add_dependencies(tests perftest) +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) add_test(NAME perftest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index fd2eb4d..ee5ff0c 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -18,6 +18,12 @@ set(UNITTEST_SOURCES valuetest.cpp writertest.cpp) +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") From 96fbaef1ec17a338ec8673fab7a4d461fed8a134 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:04:47 +0200 Subject: [PATCH 15/31] Workaround clang and ccache bugs described in http://petereisentraut.blogspot.co.il/2011/05/ccache-and-clang.html --- CMakeLists.txt | 2 +- test/perftest/CMakeLists.txt | 2 ++ test/unittest/CMakeLists.txt | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89a7634..ca47d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ endif(CCACHE_FOUND) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers -Qunused-arguments -fcolor-diagnostics") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index f698382..4329231 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -13,6 +13,8 @@ find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") endif(CCACHE_FOUND) IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index ee5ff0c..8654753 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -22,6 +22,8 @@ find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") endif(CCACHE_FOUND) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") From 163c4b75832a25831f974a7d0a7958f08e7a08a7 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:07:28 +0200 Subject: [PATCH 16/31] Fixed cmake syntax errors. --- CMakeLists.txt | 5 ++++- test/perftest/CMakeLists.txt | 1 + test/unittest/CMakeLists.txt | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca47d81..3c6f4e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,12 +29,15 @@ find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") + endif() endif(CCACHE_FOUND) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers -Qunused-arguments -fcolor-diagnostics") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index 4329231..ba8dc31 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -15,6 +15,7 @@ if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") + endif() endif(CCACHE_FOUND) IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 8654753..c24ef84 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -24,6 +24,7 @@ if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") + endif() endif(CCACHE_FOUND) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") From 45ea872f2e23605cbcf01c49bce3dc7e3a527980 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:10:34 +0200 Subject: [PATCH 17/31] Set CCACHE_CPP2 environment variable to yes as described in http://petereisentraut.blogspot.co.il/2011/09/ccache-and-clang-part-2.html --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 981ea37..a0c3b07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,9 +42,9 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 - - env: CONF=debug ARCH=x86_64 + - env: CONF=debug ARCH=x86_64 CCACHE_CPP2=yes compiler: clang - - env: CONF=release ARCH=x86 + - env: CONF=release ARCH=x86 CCACHE_CPP2=yes compiler: clang addons: apt: @@ -52,7 +52,7 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 - - env: CONF=release ARCH=x86_64 + - env: CONF=release ARCH=x86_64 CCACHE_CPP2=yes compiler: clang # coverage report - env: CONF=debug ARCH=x86 GCOV_FLAGS='--coverage' From 0cc5974b111f2f16993d66b316df14533ea13b4c Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:19:09 +0200 Subject: [PATCH 18/31] Missed one CCACHE_CPP2=yes --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a0c3b07..d516feb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ matrix: - libc6-dbg:i386 - env: CONF=release ARCH=x86_64 compiler: gcc - - env: CONF=debug ARCH=x86 + - env: CONF=debug ARCH=x86 CCACHE_CPP2=yes compiler: clang addons: apt: From 52e287a8c9fe9af888cb0f1f9acc7a40ef1e8ccd Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:32:17 +0200 Subject: [PATCH 19/31] Fail the build early if cmake cannot generate the Makefiles. --- .travis.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index d516feb..5681a22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,17 +84,17 @@ before_script: - ccache -s - sed -i "s/-march=native//" CMakeLists.txt - mkdir build - - > - eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; - (cd build && cmake - -DRAPIDJSON_HAS_STDSTRING=ON - -DCMAKE_VERBOSE_MAKEFILE=ON - -DCMAKE_BUILD_TYPE=$CONF - -DCMAKE_CXX_FLAGS="$ARCH_FLAGS $GCOV_FLAGS" - -DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS - ..) script: + - > + eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; + (cd build && cmake + -DRAPIDJSON_HAS_STDSTRING=ON + -DCMAKE_VERBOSE_MAKEFILE=ON + -DCMAKE_BUILD_TYPE=$CONF + -DCMAKE_CXX_FLAGS="$ARCH_FLAGS $GCOV_FLAGS" + -DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS + ..) - cd build - make tests - make examples From 5fb5002e9a154b57490964877aff132eabc44548 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 12:35:25 +0200 Subject: [PATCH 20/31] Run everything in 2 parallel threads. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5681a22..4565ebb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -96,7 +96,7 @@ script: -DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS ..) - cd build - - make tests - - make examples - - ctest -V `[ "$CONF" = "release" ] || echo "-E perftest"` + - make tests -j 2 + - make examples -j 2 + - ctest -j 2 -V `[ "$CONF" = "release" ] || echo "-E perftest"` - make travis_doc From 89631a6190858698061cbec7cdb93b596a3b6a46 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 13:05:57 +0200 Subject: [PATCH 21/31] Make documentation only in one of the build jobs. --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4565ebb..9c6089f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ addons: packages: &default_packages - cmake - valgrind - - doxygen env: global: @@ -74,6 +73,10 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 + - doxygen + script: # Generate and push documentation + - *default_script + - make travis_doc after_success: - pip install --user cpp-coveralls - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h @@ -85,7 +88,7 @@ before_script: - sed -i "s/-march=native//" CMakeLists.txt - mkdir build -script: +script: &default_script - > eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; (cd build && cmake @@ -99,4 +102,4 @@ script: - make tests -j 2 - make examples -j 2 - ctest -j 2 -V `[ "$CONF" = "release" ] || echo "-E perftest"` - - make travis_doc + From 8e40b2062ed76ede53a6f26c8e31ac7736f3ef1e Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 13:29:39 +0200 Subject: [PATCH 22/31] Split the documentation task from the rest since references to script doesn't work. --- .travis.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c6089f..b84f7bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,13 +73,17 @@ matrix: - *default_packages - g++-multilib - libc6-dbg:i386 - - doxygen - script: # Generate and push documentation - - *default_script - - make travis_doc after_success: - pip install --user cpp-coveralls - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h + - script: + - cd build + - cmake -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON + - make travis_doc + addons: + apt: + packages: + - doxygen before_script: # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), @@ -88,7 +92,7 @@ before_script: - sed -i "s/-march=native//" CMakeLists.txt - mkdir build -script: &default_script +script: - > eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; (cd build && cmake @@ -102,4 +106,3 @@ script: &default_script - make tests -j 2 - make examples -j 2 - ctest -j 2 -V `[ "$CONF" = "release" ] || echo "-E perftest"` - From 5337e73f34017f6d2d626f1ea3c95dbdca36d027 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 13:41:51 +0200 Subject: [PATCH 23/31] Fix path. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b84f7bd..acc3a04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,7 +78,7 @@ matrix: - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h - script: - cd build - - cmake -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON + - cmake .. -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON - make travis_doc addons: apt: From 918fafc611401d7cf0198fc1ce6f4f5333bef2d8 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 13:56:35 +0200 Subject: [PATCH 24/31] Disable cache for doxygen. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index acc3a04..449fdc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,6 +80,7 @@ matrix: - cd build - cmake .. -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON - make travis_doc + cache: false addons: apt: packages: From 83a2e13efb25503c7e05efeb3c7f3d53634838f3 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 14:21:23 +0200 Subject: [PATCH 25/31] Add pip caching only when reporting coverage. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 449fdc3..865b9d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: cpp sudo: false cache: - ccache - - pip addons: apt: @@ -56,6 +55,9 @@ matrix: # coverage report - env: CONF=debug ARCH=x86 GCOV_FLAGS='--coverage' compiler: gcc + cache: + - ccache + - pip addons: apt: packages: @@ -67,6 +69,9 @@ matrix: - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h - env: CONF=debug ARCH=x86_64 GCOV_FLAGS='--coverage' compiler: gcc + cache: + - ccache + - pip addons: apt: packages: From 53557c898899f813759bf217da759eea4d077521 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 31 Dec 2015 16:17:14 +0200 Subject: [PATCH 26/31] Moved comment to the right place and added a TODO. Added another comment about the documentation task. --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 865b9d5..57b1b1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -81,7 +81,7 @@ matrix: after_success: - pip install --user cpp-coveralls - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h - - script: + - script: # Documentation task - cd build - cmake .. -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON - make travis_doc @@ -92,9 +92,10 @@ matrix: - doxygen before_script: - # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), - # exposed by merging PR#163 (using -march=native) - ccache -s + # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), + # exposed by merging PR#163 (using -march=native) + # TODO: Since this bug is already fixed. Remove this when valgrind can be upgraded. - sed -i "s/-march=native//" CMakeLists.txt - mkdir build From bd1be768f18342b032e4d3e0e205fd6c51d4bd7d Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 19 Jan 2016 09:59:38 +0800 Subject: [PATCH 27/31] Fix #508 tutorial documentation about move semantics. --- doc/tutorial.md | 4 ++-- doc/tutorial.zh-cn.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 1211023..379e6e3 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -280,7 +280,7 @@ A very special decision during design of RapidJSON is that, assignment of value ~~~~~~~~~~cpp Value a(123); Value b(456); -b = a; // a becomes a Null value, b becomes number 123. +a = b; // a becomes number 456, b becomes a Null value. ~~~~~~~~~~ ![Assignment with move semantics.](diagram/move1.png) @@ -305,7 +305,7 @@ Value o(kObjectType); ![Copy semantics makes a lots of copy operations.](diagram/move2.png) -The object `o` needs to allocate a buffer of same size as contacts, makes a deep clone of it, and then finally contacts is destructed. This will incur a lot of unnecessary allocations/deallocations and memory copying. +The object `o` needs to allocate a buffer of same size as `contacts`, makes a deep clone of it, and then finally `contacts` is destructed. This will incur a lot of unnecessary allocations/deallocations and memory copying. There are solutions to prevent actual copying these data, such as reference counting and garbage collection(GC). diff --git a/doc/tutorial.zh-cn.md b/doc/tutorial.zh-cn.md index 37808b0..156dab6 100644 --- a/doc/tutorial.zh-cn.md +++ b/doc/tutorial.zh-cn.md @@ -280,7 +280,7 @@ Value a(kArrayType); ~~~~~~~~~~cpp Value a(123); Value b(456); -b = a; // a变成Null,b变成数字123。 +a = b; // a变成数字456,b变成Null。 ~~~~~~~~~~ ![使用移动语意赋值。](diagram/move1.png) @@ -304,7 +304,7 @@ Value o(kObjectType); ![复制语意产生大量的复制操作。](diagram/move2.png) -那个`o` Object需要分配一个和contacts相同大小的缓冲区,对conacts做深度复制,并最终要析构contacts。这样会产生大量无必要的内存分配/释放,以及内存复制。 +那个`o` Object需要分配一个和contacts相同大小的缓冲区,对`contacts`做深度复制,并最终要析构`contacts`。这样会产生大量无必要的内存分配/释放,以及内存复制。 有一些方案可避免实质地复制这些数据,例如引用计数(reference counting)、垃圾回收(garbage collection, GC)。 From 44f81f09b4db3c39d2d485f04fb9eb1b07ff661a Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 19 Jan 2016 18:28:28 +0800 Subject: [PATCH 28/31] Remove travis doc job number checking. Travis doc is running on separated task now. --- travis-doxygen.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/travis-doxygen.sh b/travis-doxygen.sh index e9eb6b9..ca4e6e2 100755 --- a/travis-doxygen.sh +++ b/travis-doxygen.sh @@ -42,8 +42,8 @@ abort() { skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})." # check for job number -[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \ - skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})." +#[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \ +# skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})." # install doxygen binary distribution doxygen_install() From ad1d22eba5028a6fef26900f48ea3ae0494d3b75 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 20 Jan 2016 01:53:40 +0800 Subject: [PATCH 29/31] Fix #509 by checking Nan/Inf when writing a double --- include/rapidjson/internal/ieee754.h | 1 + include/rapidjson/writer.h | 8 +++++++- test/unittest/writertest.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/internal/ieee754.h b/include/rapidjson/internal/ieee754.h index 6890f89..82bb0b9 100644 --- a/include/rapidjson/internal/ieee754.h +++ b/include/rapidjson/internal/ieee754.h @@ -40,6 +40,7 @@ public: bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } + bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index a450456..fab6740 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -139,7 +139,7 @@ public: } bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); } - + bool EndObject(SizeType memberCount = 0) { (void)memberCount; RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); @@ -235,6 +235,9 @@ protected: } bool WriteDouble(double d) { + if (internal::Double(d).IsNanOrInf()) + return false; + char buffer[25]; char* end = internal::dtoa(d, buffer); for (char* p = buffer; p != end; ++p) @@ -381,6 +384,9 @@ inline bool Writer::WriteUint64(uint64_t u) { template<> inline bool Writer::WriteDouble(double d) { + if (internal::Double(d).IsNanOrInf()) + return false; + char *buffer = os_->Push(25); char* end = internal::dtoa(d, buffer); os_->Pop(static_cast(25 - (end - buffer))); diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 2adb551..24a2c6c 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -375,3 +375,27 @@ TEST(Writer, InvalidEventSequence) { EXPECT_FALSE(writer.IsComplete()); } } + +double zero = 0.0; // Use global variable to prevent compiler warning + +TEST(Writer, NaN) { + double nan = zero / zero; + EXPECT_TRUE(internal::Double(nan).IsNan()); + StringBuffer buffer; + Writer writer(buffer); + EXPECT_FALSE(writer.Double(nan)); +} + +TEST(Writer, Inf) { + double inf = 1.0 / zero; + EXPECT_TRUE(internal::Double(inf).IsInf()); + StringBuffer buffer; + { + Writer writer(buffer); + EXPECT_FALSE(writer.Double(inf)); + } + { + Writer writer(buffer); + EXPECT_FALSE(writer.Double(-inf)); + } +} From bab80e7ccae70e11d5782d86cbbba1f93a3e8363 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 20 Jan 2016 02:01:14 +0800 Subject: [PATCH 30/31] Fix clang warning --- test/unittest/writertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 24a2c6c..197411c 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -376,6 +376,7 @@ TEST(Writer, InvalidEventSequence) { } } +extern double zero; // clang -Wmissing-variable-declarations double zero = 0.0; // Use global variable to prevent compiler warning TEST(Writer, NaN) { From 78c7d54aba2ae0f6639b2539f30ef488d8b877f3 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 20 Jan 2016 22:29:50 +0800 Subject: [PATCH 31/31] Fix #498 VC2015 warnings --- include/rapidjson/reader.h | 6 +++--- test/unittest/readertest.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 8628b53..870ed94 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -886,7 +886,7 @@ private: while (s.Peek() >= '0' && s.Peek() <= '9') { if (i64 >= RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC)) // 2^63 = 9223372036854775808 if (i64 != RAPIDJSON_UINT64_C2(0x0CCCCCCC, 0xCCCCCCCC) || s.Peek() > '8') { - d = i64; + d = static_cast(i64); useDouble = true; break; } @@ -897,7 +897,7 @@ private: while (s.Peek() >= '0' && s.Peek() <= '9') { if (i64 >= RAPIDJSON_UINT64_C2(0x19999999, 0x99999999)) // 2^64 - 1 = 18446744073709551615 if (i64 != RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || s.Peek() > '5') { - d = i64; + d = static_cast(i64); useDouble = true; break; } @@ -968,7 +968,7 @@ private: int exp = 0; if (s.Peek() == 'e' || s.Peek() == 'E') { if (!useDouble) { - d = use64bit ? i64 : i; + d = static_cast(use64bit ? i64 : i); useDouble = true; } s.Take(); diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index f2a0be1..3b84ab7 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -409,7 +409,7 @@ TEST(Reader, ParseNumber_NormalPrecisionError) { a = h.actual_; uint64_t bias1 = e.ToBias(); uint64_t bias2 = a.ToBias(); - double ulp = bias1 >= bias2 ? bias1 - bias2 : bias2 - bias1; + double ulp = static_cast(bias1 >= bias2 ? bias1 - bias2 : bias2 - bias1); ulpMax = std::max(ulpMax, ulp); ulpSum += ulp; }