Skip to content

Commit 797c304

Browse files
authored
Merge branch 'master' into master
2 parents d57ddb6 + e799ca0 commit 797c304

13 files changed

Lines changed: 240 additions & 52 deletions

File tree

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Checks: 'google-readability-casting,modernize-deprecated-headers,modernize-loop-convert,modernize-use-auto,modernize-use-default-member-init,modernize-use-using,readability-else-after-return,readability-redundant-member-init,readability-redundant-string-cstr'
33
WarningsAsErrors: ''
44
HeaderFilterRegex: ''
5-
AnalyzeTemporaryDtors: false
65
FormatStyle: none
76
CheckOptions:
87
- key: modernize-use-using.IgnoreMacros

BUILD.bazel

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
licenses(["unencumbered"]) # Public Domain or MIT
22

3+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
4+
35
exports_files(["LICENSE"])
46

7+
bool_flag(
8+
name = "use_exception",
9+
build_setting_default = False,
10+
)
11+
12+
config_setting(
13+
name = "use_exception_cfg",
14+
flag_values = {":use_exception": "true"},
15+
)
16+
17+
bool_flag(
18+
name = "has_int64",
19+
build_setting_default = True,
20+
)
21+
22+
config_setting(
23+
name = "has_int64_cfg",
24+
flag_values = {":has_int64": "true"},
25+
)
26+
527
cc_library(
628
name = "jsoncpp",
729
srcs = [
@@ -22,10 +44,13 @@ cc_library(
2244
"include/json/version.h",
2345
"include/json/writer.h",
2446
],
25-
copts = [
26-
"-DJSON_USE_EXCEPTION=0",
27-
"-DJSON_HAS_INT64",
28-
],
47+
defines = select({
48+
":use_exception_cfg": ["JSON_USE_EXCEPTION=1"],
49+
"//conditions:default": ["JSON_USE_EXCEPTION=0"],
50+
}) + select({
51+
":has_int64_cfg": ["JSON_HAS_INT64"],
52+
"//conditions:default": [],
53+
}),
2954
includes = ["include"],
3055
visibility = ["//visibility:public"],
3156
deps = [":private"],

MODULE.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ module(
1212
version = "1.9.7",
1313
compatibility_level = 1,
1414
)
15+
16+
bazel_dep(
17+
name = "bazel_skylib",
18+
version = "1.7.1",
19+
)

README.md

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# JsonCpp
22

3-
[![badge](https://img.shields.io/badge/conan.io-jsoncpp%2F1.8.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC)](https://bintray.com/theirix/conan-repo/jsoncpp%3Atheirix)
3+
[![Conan Center](https://img.shields.io/conan/v/jsoncpp)](https://conan.io/center/recipes/jsoncpp)
44
[![badge](https://img.shields.io/badge/license-MIT-blue)](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE)
55
[![badge](https://img.shields.io/badge/document-doxygen-brightgreen)](http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html)
66
[![Coverage Status](https://coveralls.io/repos/github/open-source-parsers/jsoncpp/badge.svg?branch=master)](https://coveralls.io/github/open-source-parsers/jsoncpp?branch=master)
77

8-
98
[JSON][json-org] is a lightweight data-interchange format. It can represent
109
numbers, strings, ordered sequences of values, and collections of name/value
1110
pairs.
@@ -14,18 +13,16 @@ pairs.
1413

1514
JsonCpp is a C++ library that allows manipulating JSON values, including
1615
serialization and deserialization to and from strings. It can also preserve
17-
existing comment in unserialization/serialization steps, making it a convenient
16+
existing comment in deserialization/serialization steps, making it a convenient
1817
format to store user input files.
1918

20-
2119
## Documentation
2220

2321
[JsonCpp documentation][JsonCpp-documentation] is generated using [Doxygen][].
2422

2523
[JsonCpp-documentation]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
2624
[Doxygen]: http://www.doxygen.org
2725

28-
2926
## A note on backward-compatibility
3027

3128
* `1.y.z` is built with C++11.
@@ -34,34 +31,106 @@ format to store user input files.
3431
* Major versions maintain binary-compatibility.
3532

3633
### Special note
37-
The branch `00.11.z`is a new branch, its major version number `00` is to show that it is
38-
different from `0.y.z` and `1.y.z`, the main purpose of this branch is to make a balance
39-
between the other two branches. Thus, users can use some new features in this new branch
40-
that introduced in 1.y.z, but can hardly applied into 0.y.z.
34+
35+
The branch `00.11.z`is a new branch, its major version number `00` is to show
36+
that it is different from `0.y.z` and `1.y.z`, the main purpose of this branch
37+
is to make a balance between the other two branches. Thus, users can use some
38+
new features in this new branch that introduced in 1.y.z, but can hardly applied
39+
into 0.y.z.
4140

4241
## Using JsonCpp in your project
4342

4443
### The vcpkg dependency manager
45-
You can download and install JsonCpp using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
4644

45+
You can download and install JsonCpp using the [vcpkg](https://github.com/Microsoft/vcpkg/)
46+
dependency manager, which has installation instruction dependent on your
47+
build system. For example, if you are in a CMake project, the
48+
[CMake install tutorial](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-powershell)
49+
suggests the follow installation method.
50+
51+
First, clone and set up `vcpkg`.
52+
53+
```sh
4754
git clone https://github.com/Microsoft/vcpkg.git
4855
cd vcpkg
4956
./bootstrap-vcpkg.sh
50-
./vcpkg integrate install
51-
./vcpkg install jsoncpp
57+
```
58+
59+
Then, create a [vcpkg.json manifest](https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json),
60+
enabling manifest mode and adding JsonCpp to the manifest's dependencies list.
61+
62+
```sh
63+
vcpkg new --application
64+
vcpkg add port jsoncpp
65+
```
66+
67+
> [!NOTE]: you can use vcpkg in either classic mode or manifest mode (recommended).
68+
69+
#### Classic mode
70+
71+
If your project does not have a `vcpkg.json`,
72+
your project is in [Classic mode](https://learn.microsoft.com/en-us/vcpkg/concepts/classic-mode)
73+
you can install JsonCpp by directly invoking the `install` command:
74+
75+
```sh
76+
vcpkg install jsoncpp
77+
```
5278

53-
The JsonCpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
79+
### Manifest mode
80+
81+
If your project *does* have a vcpkg.json manifest, your project is in [Manifest mode](https://learn.microsoft.com/en-us/vcpkg/concepts/manifest-mode)
82+
and you need to add JsonCpp to your package manifest dependencies, then invoke
83+
install with no arguments.
84+
85+
```sh
86+
vcpkg add port jsoncpp
87+
vcpkg install
88+
```
89+
90+
Example manifest:
91+
92+
```sh
93+
{
94+
"name": "best-app-ever",
95+
"dependencies": [ "jsoncpp" ],
96+
}
97+
```
98+
99+
> [!NOTE] The JsonCpp port in vcpkg is kept up to date by Microsoft team members and community contributors.
100+
> If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg)
101+
> on the vcpkg repository.
102+
103+
### Conan package manager
104+
105+
You can download and install JsonCpp using the [Conan](https://conan.io/)
106+
package manager:
107+
108+
```sh
109+
conan install -r conancenter --requires="jsoncpp/[*]" --build=missing
110+
```
111+
112+
The JsonCpp package in Conan Center is kept up to date by [ConanCenterIndex](https://github.com/conan-io/conan-center-index)
113+
contributors. If the version is out of date, please create an issue or pull request on the
114+
Conan Center Index repository.
54115

55116
### Amalgamated source
56-
https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated)
117+
118+
See the [Wiki entry on Amalgamated Source](https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated)).
57119

58120
### The Meson Build System
59-
If you are using the [Meson Build System](http://mesonbuild.com), then you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/jsoncpp), or simply use `meson wrap install jsoncpp`.
121+
122+
If you are using the [Meson Build System](http://mesonbuild.com), then you can
123+
get a wrap file by downloading it from [Meson WrapDB](https://mesonbuild.com/Wrapdb-projects.html),
124+
or simply use `meson wrap install jsoncpp`.
60125

61126
### Other ways
62-
If you have trouble, see the [Wiki](https://github.com/open-source-parsers/jsoncpp/wiki), or post a question as an Issue.
127+
128+
If you have trouble, see the
129+
[Wiki](https://github.com/open-source-parsers/jsoncpp/wiki), or post a question
130+
as an Issue.
63131

64132
## License
65133

66-
See the `LICENSE` file for details. In summary, JsonCpp is licensed under the
67-
MIT license, or public domain if desired and recognized in your jurisdiction.
134+
See the [LICENSE](./LICENSE) file for details. In summary, JsonCpp is licensed
135+
under the MIT license, or public domain if desired and recognized in your
136+
jurisdiction.

gcovr.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Newer versions of gcovr have strict function merging by default, which
2+
# can cause issues with header-only functions or macros (like in jsontest.h).
3+
# 'separate' mode keeps them distinct, fixing the GcovrMergeAssertionError.
4+
merge-mode-functions = separate
5+
6+
# --- Filtering ---
7+
# Only include the library sources in the coverage report.
8+
# This ensures coverage stats reflect the library quality and ignores test code.
9+
filter = src/lib_json/
10+
filter = include/json/
11+
12+
# Exclude the build directory to avoid processing generated files
13+
exclude-directories = build
14+
15+
# --- Noise Reduction ---
16+
# Ignore branches that are generated by the compiler (e.g., exception handling)
17+
# This drastically reduces "false positives" for missing branch coverage.
18+
exclude-throw-branches = yes
19+
20+
# --- CI Visibility ---
21+
# Print a small summary table to the console logs.
22+
print-summary = yes

src/jsontestrunner/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cc_binary(
2+
name = "jsontestrunner",
3+
srcs = ["main.cpp"],
4+
deps = ["//:jsoncpp"],
5+
visibility = ["//test:__pkg__"],
6+
)

src/lib_json/json_reader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstring>
1717
#include <iostream>
1818
#include <istream>
19+
#include <iterator>
1920
#include <limits>
2021
#include <memory>
2122
#include <set>
@@ -143,7 +144,12 @@ bool Reader::readValue() {
143144
// after calling readValue(). parse() executes one nodes_.push(), so > instead
144145
// of >=.
145146
if (nodes_.size() > stackLimit_g)
147+
#if JSON_USE_EXCEPTION
146148
throwRuntimeError("Exceeded stackLimit in readValue().");
149+
#else
150+
// throwRuntimeError aborts. Don't abort here.
151+
return false;
152+
#endif
147153

148154
Token token;
149155
readTokenSkippingComments(token);

src/test_lib_json/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cc_test(
2+
name = "jsoncpp_test",
3+
srcs = [
4+
"jsontest.cpp",
5+
"jsontest.h",
6+
"main.cpp",
7+
"fuzz.h",
8+
"fuzz.cpp",
9+
],
10+
deps = ["//:jsoncpp"],
11+
)

src/test_lib_json/fuzz.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#include <memory>
1212
#include <string>
1313

14-
namespace Json {
15-
class Exception;
16-
}
17-
1814
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
1915
Json::CharReaderBuilder builder;
2016

@@ -45,10 +41,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
4541

4642
Json::Value root;
4743
const auto data_str = reinterpret_cast<const char*>(data);
44+
#if JSON_USE_EXCEPTION
4845
try {
46+
#endif // JSON_USE_EXCEPTION
4947
reader->parse(data_str, data_str + size, &root, nullptr);
48+
#if JSON_USE_EXCEPTION
5049
} catch (Json::Exception const&) {
5150
}
51+
#endif // JSON_USE_EXCEPTION
5252
// Whether it succeeded or not doesn't matter.
5353
return 0;
5454
}

src/test_lib_json/jsontest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
228228
JsonTest::ToJsonString(actual), __FILE__, \
229229
__LINE__, #expected " == " #actual)
230230

231+
#if JSON_USE_EXCEPTION
232+
231233
/// \brief Asserts that a given expression throws an exception
232234
#define JSONTEST_ASSERT_THROWS(expr) \
233235
do { \
@@ -242,6 +244,8 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
242244
"expected exception thrown: " #expr); \
243245
} while (0)
244246

247+
#endif // JSON_USE_EXCEPTION
248+
245249
/// \brief Begin a fixture test case.
246250
#define JSONTEST_FIXTURE(FixtureType, name) \
247251
class Test##FixtureType##name : public FixtureType { \

0 commit comments

Comments
 (0)