Skip to content

Commit c334ac0

Browse files
committed
Merge branch 'master' into 0.y.z
- fix for "C++ Builder" IDE - Travis CI/AppVeyor - **cmake** tweak - fix memory leak in unit-test See #268 and #252.
2 parents c66cc27 + 28d086e commit c334ac0

File tree

13 files changed

+84
-38
lines changed

13 files changed

+84
-38
lines changed

.travis.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
# http://about.travis-ci.org/docs/user/build-configuration/
33
# This file can be validated on:
44
# http://lint.travis-ci.org/
5-
before_install: sudo apt-get install cmake
5+
6+
#before_install: sudo apt-get install -y cmake
7+
# cmake is pre-installed in Travis for both linux and osx
8+
9+
before_install:
10+
- sudo apt-get update -qq
11+
- sudo apt-get install -qq valgrind
12+
os:
13+
- linux
614
language: cpp
715
compiler:
816
- gcc
917
- clang
10-
script: cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DJSONCPP_LIB_BUILD_SHARED=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE . && make && make jsoncpp_check
18+
script: ./travis.sh
1119
env:
1220
matrix:
1321
- SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post
99
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
1010
OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
1111
OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
12+
OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
13+
OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON)
1214

1315
# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
1416
IF(NOT WIN32)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Steps for generating solution/makefiles using `cmake-gui`:
5858
* Make "source code" point to the source directory.
5959
* Make "where to build the binary" point to the directory to use for the build.
6060
* Click on the "Grouped" check box.
61-
* Review JsonCpp build options (tick `JSONCPP_LIB_BUILD_SHARED` to build as a
61+
* Review JsonCpp build options (tick `BUILD_SHARED_LIBS` to build as a
6262
dynamic library).
6363
* Click the configure button at the bottom, then the generate button.
6464
* The generated solution/makefiles can be found in the binary directory.
@@ -67,7 +67,7 @@ Alternatively, from the command-line on Unix in the source directory:
6767

6868
mkdir -p build/debug
6969
cd build/debug
70-
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
70+
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -G "Unix Makefiles" ../..
7171
make
7272

7373
Running `cmake -`" will display the list of available generators (passed using

dev.makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dox:
1616
# Then 'git add -A' and 'git push' in jsoncpp-docs.
1717
build:
1818
mkdir -p build/debug
19-
cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_SHARED=ON -G "Unix Makefiles" ../..
19+
cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_SHARED_LIBS=ON -G "Unix Makefiles" ../..
2020
make -C build/debug
2121

2222
# Currently, this depends on include/json/version.h generated
@@ -26,6 +26,9 @@ test-amalgamate:
2626
python3.4 amalgamate.py
2727
cd dist; gcc -I. -c jsoncpp.cpp
2828

29+
valgrind:
30+
valgrind --error-exitcode=42 --leak-check=full ./build/debug/src/test_lib_json/jsoncpp_test
31+
2932
clean:
3033
\rm -rf *.gz *.asc dist/
3134

devtools/agent_vmw7.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
},
2020
{"name": "shared_dll",
2121
"variables": [
22-
["JSONCPP_LIB_BUILD_SHARED=true"],
23-
["JSONCPP_LIB_BUILD_SHARED=false"]
22+
["BUILD_SHARED_LIBS=true"],
23+
["BUILD_SHARED_LIBS=false"]
2424
]
2525
},
2626
{"name": "build_type",

devtools/agent_vmxp.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
},
1313
{"name": "shared_dll",
1414
"variables": [
15-
["JSONCPP_LIB_BUILD_SHARED=true"],
16-
["JSONCPP_LIB_BUILD_SHARED=false"]
15+
["BUILD_SHARED_LIBS=true"],
16+
["BUILD_SHARED_LIBS=false"]
1717
]
1818
},
1919
{"name": "build_type",

include/json/reader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,13 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
302302
/** Called by ctor, but you can use this to reset settings_.
303303
* \pre 'settings' != NULL (but Json::null is fine)
304304
* \remark Defaults:
305-
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
305+
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
306306
*/
307307
static void setDefaults(Json::Value* settings);
308308
/** Same as old Features::strictMode().
309309
* \pre 'settings' != NULL (but Json::null is fine)
310310
* \remark Defaults:
311-
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
311+
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
312312
*/
313313
static void strictMode(Json::Value* settings);
314314
};

include/json/value.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class JSON_API Value {
214214
void swap(CZString& other);
215215

216216
struct StringStorage {
217-
DuplicationPolicy policy_: 2;
217+
unsigned policy_: 2;
218218
unsigned length_: 30; // 1GB max
219219
};
220220

src/jsontestrunner/CMakeLists.txt

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
FIND_PACKAGE(PythonInterp 2.6)
22

3-
IF(JSONCPP_LIB_BUILD_SHARED)
4-
ADD_DEFINITIONS( -DJSON_DLL )
5-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
6-
73
ADD_EXECUTABLE(jsontestrunner_exe
84
main.cpp
95
)
106

11-
IF(JSONCPP_LIB_BUILD_SHARED)
7+
IF(BUILD_SHARED_LIBS)
8+
ADD_DEFINITIONS( -DJSON_DLL )
129
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib)
13-
ELSE(JSONCPP_LIB_BUILD_SHARED)
10+
ELSE(BUILD_SHARED_LIBS)
1411
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib_static)
15-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
12+
ENDIF(BUILD_SHARED_LIBS)
1613

1714
SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)
1815

src/lib_json/CMakeLists.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
OPTION(JSONCPP_LIB_BUILD_SHARED "Build jsoncpp_lib as a shared library." OFF)
2-
OPTION(JSONCPP_LIB_BUILD_STATIC "Build jsoncpp_lib static library." ON)
3-
4-
IF(BUILD_SHARED_LIBS)
5-
SET(JSONCPP_LIB_BUILD_SHARED ON)
6-
ENDIF(BUILD_SHARED_LIBS)
7-
81
if( CMAKE_COMPILER_IS_GNUCXX )
92
#Get compiler version.
103
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
@@ -46,7 +39,7 @@ ELSE(JSONCPP_WITH_CMAKE_PACKAGE)
4639
SET(INSTALL_EXPORT)
4740
ENDIF(JSONCPP_WITH_CMAKE_PACKAGE)
4841

49-
IF(JSONCPP_LIB_BUILD_SHARED)
42+
IF(BUILD_SHARED_LIBS)
5043
ADD_DEFINITIONS( -DJSON_DLL_BUILD )
5144
ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources})
5245
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
@@ -65,7 +58,7 @@ IF(JSONCPP_LIB_BUILD_SHARED)
6558

6659
ENDIF()
6760

68-
IF(JSONCPP_LIB_BUILD_STATIC)
61+
IF(BUILD_STATIC_LIBS)
6962
ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources})
7063
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
7164
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp )

src/test_lib_json/CMakeLists.txt

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
# vim: et ts=4 sts=4 sw=4 tw=0
22

3-
IF(JSONCPP_LIB_BUILD_SHARED)
4-
ADD_DEFINITIONS( -DJSON_DLL )
5-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
6-
73
ADD_EXECUTABLE( jsoncpp_test
84
jsontest.cpp
95
jsontest.h
106
main.cpp
117
)
128

139

14-
IF(JSONCPP_LIB_BUILD_SHARED)
10+
IF(BUILD_SHARED_LIBS)
11+
ADD_DEFINITIONS( -DJSON_DLL )
1512
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib)
16-
ELSE(JSONCPP_LIB_BUILD_SHARED)
13+
ELSE(BUILD_SHARED_LIBS)
1714
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static)
18-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
15+
ENDIF(BUILD_SHARED_LIBS)
1916

2017
# another way to solve issue #90
2118
#set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store)
2219

2320
# Run unit tests in post-build
2421
# (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
2522
IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
26-
IF(JSONCPP_LIB_BUILD_SHARED)
23+
IF(BUILD_SHARED_LIBS)
2724
# First, copy the shared lib, for Microsoft.
2825
# Then, run the test executable.
2926
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
3027
POST_BUILD
3128
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test>
3229
COMMAND $<TARGET_FILE:jsoncpp_test>)
33-
ELSE(JSONCPP_LIB_BUILD_SHARED)
30+
ELSE(BUILD_SHARED_LIBS)
3431
# Just run the test executable.
3532
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
3633
POST_BUILD
3734
COMMAND $<TARGET_FILE:jsoncpp_test>)
38-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
35+
ENDIF(BUILD_SHARED_LIBS)
3936
ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST)
4037

4138
SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)

src/test_lib_json/main.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ JSONTEST_FIXTURE(ValueTest, arrays) {
257257
JSONTEST_ASSERT_EQUAL(Json::Value(17), got);
258258
JSONTEST_ASSERT_EQUAL(false, array1_.removeIndex(2, &got)); // gone now
259259
}
260+
JSONTEST_FIXTURE(ValueTest, arrayIssue252)
261+
{
262+
int count = 5;
263+
Json::Value root;
264+
Json::Value item;
265+
root["array"] = Json::Value::nullRef;
266+
for (int i = 0; i < count; i++)
267+
{
268+
item["a"] = i;
269+
item["b"] = i;
270+
root["array"][i] = item;
271+
}
272+
//JSONTEST_ASSERT_EQUAL(5, root["array"].size());
273+
}
260274

261275
JSONTEST_FIXTURE(ValueTest, null) {
262276
JSONTEST_ASSERT_EQUAL(Json::nullValue, null_.type());
@@ -2139,6 +2153,7 @@ JSONTEST_FIXTURE(CharReaderAllowSingleQuotesTest, issue182) {
21392153
JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString());
21402154
JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString());
21412155
}
2156+
delete reader;
21422157
}
21432158

21442159
struct CharReaderAllowZeroesTest : JsonTest::TestCase {};
@@ -2171,6 +2186,7 @@ JSONTEST_FIXTURE(CharReaderAllowZeroesTest, issue176) {
21712186
JSONTEST_ASSERT_STRING_EQUAL("x", root["a"].asString());
21722187
JSONTEST_ASSERT_STRING_EQUAL("y", root["b"].asString());
21732188
}
2189+
delete reader;
21742190
}
21752191

21762192
struct BuilderTest : JsonTest::TestCase {};
@@ -2254,6 +2270,7 @@ int main(int argc, const char* argv[]) {
22542270
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);
22552271
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, objects);
22562272
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrays);
2273+
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrayIssue252);
22572274
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, null);
22582275
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, strings);
22592276
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, bools);

travis.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env sh
2+
# This is called by `.travis.yml` via Travis CI.
3+
# Travis supplies $TRAVIS_OS_NAME.
4+
# http://docs.travis-ci.com/user/multi-os/
5+
# Our .travis.yml also defines:
6+
# - SHARED_LIB=ON/OFF
7+
# - STATIC_LIB=ON/OFF
8+
# - CMAKE_PKG=ON/OFF
9+
# - BUILD_TYPE=release/debug
10+
# - VERBOSE_MAKE=false/true
11+
# - VERBOSE (set or not)
12+
13+
# -e: fail on error
14+
# -v: show commands
15+
# -x: show expanded commands
16+
set -vex
17+
18+
env | sort
19+
20+
cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DBUILD_SHARED_LIBS=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE .
21+
make
22+
23+
# Python is not available in Travis for osx.
24+
# https://github.com/travis-ci/travis-ci/issues/2320
25+
if [ "$TRAVIS_OS_NAME" != "osx" ]
26+
then
27+
make jsoncpp_check
28+
valgrind --error-exitcode=42 --leak-check=full ./src/test_lib_json/jsoncpp_test
29+
fi

0 commit comments

Comments
 (0)