mirror of
https://github.com/json-c/json-c.git
synced 2026-04-06 22:09:06 +08:00
Compare commits
732 Commits
json-c-0.1
...
json_objec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0710c835a1 | ||
|
|
9128ec49b1 | ||
|
|
5ebfeaedc5 | ||
|
|
4c10712114 | ||
|
|
85c244f048 | ||
|
|
02fe2e0ccd | ||
|
|
ecdfeb18cf | ||
|
|
66d91fdf86 | ||
|
|
c4cc673071 | ||
|
|
0a16b23adf | ||
|
|
eab1375123 | ||
|
|
b0466b626b | ||
|
|
0fc9d91277 | ||
|
|
9ecb1222bd | ||
|
|
0351bb55c8 | ||
|
|
d1f83bf5ea | ||
|
|
5d89fc8a9d | ||
|
|
02b687b9a6 | ||
|
|
853b4b5dee | ||
|
|
4a546e7b2f | ||
|
|
fbe1543644 | ||
|
|
1e94da779a | ||
|
|
61e2bae511 | ||
|
|
fa6a7dccb9 | ||
|
|
cc802039a8 | ||
|
|
12b2e1159d | ||
|
|
8f3592b3d5 | ||
|
|
3008401b2a | ||
|
|
a8a0590921 | ||
|
|
a85d2395ff | ||
|
|
76dd99abb2 | ||
|
|
78642dcb9b | ||
|
|
dd040ba446 | ||
|
|
5b15c7567d | ||
|
|
311c5e5b2b | ||
|
|
5385a566db | ||
|
|
0a3d22b9bb | ||
|
|
1526c84a13 | ||
|
|
add7b13a9a | ||
|
|
d414d3eabc | ||
|
|
2e71fe0963 | ||
|
|
199c52e2db | ||
|
|
3648c3ed2c | ||
|
|
003b58782b | ||
|
|
26f080997d | ||
|
|
06742d6277 | ||
|
|
a59d5acfab | ||
|
|
4f43a077a4 | ||
|
|
519dfe1591 | ||
|
|
45b6416652 | ||
|
|
abc9a0731b | ||
|
|
090ae4e4d4 | ||
|
|
22870ac2bd | ||
|
|
a100573eec | ||
|
|
558ef8609c | ||
|
|
929d74512a | ||
|
|
e97fc20bfd | ||
|
|
31243e4d12 | ||
|
|
d07b910149 | ||
|
|
952db0f397 | ||
|
|
77d935b7ae | ||
|
|
099016b7e8 | ||
|
|
8e3d3d5544 | ||
|
|
c66e7377f3 | ||
|
|
8086314026 | ||
|
|
a555d0e2f2 | ||
|
|
4d36b0287d | ||
|
|
9b64c3e347 | ||
|
|
ee90110f9b | ||
|
|
0e5bbcaa16 | ||
|
|
f9605e9072 | ||
|
|
1059007024 | ||
|
|
d9981f67dd | ||
|
|
00272292a7 | ||
|
|
55d053118e | ||
|
|
f6f76f9430 | ||
|
|
05623b3a2e | ||
|
|
fa6bc1e2d7 | ||
|
|
8b511c402b | ||
|
|
ba4527904a | ||
|
|
2babb5b780 | ||
|
|
31ab57ca8b | ||
|
|
9ed00a694b | ||
|
|
4badbe9c20 | ||
|
|
0a95f98b8d | ||
|
|
ecb9354bb1 | ||
|
|
23ddcbd4da | ||
|
|
5cc11289b4 | ||
|
|
4dc0f1718e | ||
|
|
4313465f25 | ||
|
|
8bdb420d0f | ||
|
|
6bf6a9e248 | ||
|
|
a9114392b4 | ||
|
|
04bb0fca73 | ||
|
|
b14363ae32 | ||
|
|
8c33d1c3c9 | ||
|
|
7fb8d56458 | ||
|
|
053eaa61d7 | ||
|
|
ab5425a6a6 | ||
|
|
511edb51a4 | ||
|
|
2876fcc137 | ||
|
|
8096125618 | ||
|
|
f56c5c1a60 | ||
|
|
74bbe349c4 | ||
|
|
110c60fcdd | ||
|
|
76e1472808 | ||
|
|
d0dc3489dc | ||
|
|
4742a2ab1d | ||
|
|
165e6f58fc | ||
|
|
8269f90956 | ||
|
|
5e699f7f73 | ||
|
|
c58d56ab7c | ||
|
|
d52f1ff2c1 | ||
|
|
d47fb12e85 | ||
|
|
73a2ed115a | ||
|
|
fd0ae5aba6 | ||
|
|
78cd37fb18 | ||
|
|
37355cf0e6 | ||
|
|
270dc2f999 | ||
|
|
0734c5303d | ||
|
|
69ceb38f2f | ||
|
|
0dac15c1ca | ||
|
|
e756777c92 | ||
|
|
58670ec64e | ||
|
|
a989651bd4 | ||
|
|
61392c867f | ||
|
|
0a070ef312 | ||
|
|
545464322b | ||
|
|
b64bdfe381 | ||
|
|
0c60125211 | ||
|
|
95737df9d4 | ||
|
|
96ab2f6596 | ||
|
|
96bb334650 | ||
|
|
f357081b57 | ||
|
|
2782a6b62c | ||
|
|
a86ae1df9a | ||
|
|
829e0829dd | ||
|
|
cf8421c36d | ||
|
|
fb0b653612 | ||
|
|
a3b82cbc77 | ||
|
|
677a8ccf44 | ||
|
|
19bbf2c069 | ||
|
|
5e19c26cae | ||
|
|
9acc4e9d71 | ||
|
|
9a494081cb | ||
|
|
31f1ab2be1 | ||
|
|
8b162c4b89 | ||
|
|
c117d8a8a8 | ||
|
|
a8cec740f0 | ||
|
|
df7833e9a3 | ||
|
|
ed54353d84 | ||
|
|
5d9b8e0fef | ||
|
|
56f81811c2 | ||
|
|
6afcf1606b | ||
|
|
3822177473 | ||
|
|
c2ba379b03 | ||
|
|
203bacb24d | ||
|
|
d1650a582e | ||
|
|
541a0b609a | ||
|
|
353ef26bda | ||
|
|
1204a1fded | ||
|
|
a06339215e | ||
|
|
b15e7ba470 | ||
|
|
e94eb90f9f | ||
|
|
c14c6caa32 | ||
|
|
a8c9284f06 | ||
|
|
0030e905b4 | ||
|
|
e56ab0146f | ||
|
|
b3296e778f | ||
|
|
737aee40c4 | ||
|
|
2d44f865c3 | ||
|
|
6359b79847 | ||
|
|
9532f94fa4 | ||
|
|
1160c8625c | ||
|
|
c816de212b | ||
|
|
30e00cf757 | ||
|
|
e3b6521baa | ||
|
|
5a2b9139f9 | ||
|
|
a0129c9761 | ||
|
|
77d7a99c75 | ||
|
|
0ccb296263 | ||
|
|
f69fbd897b | ||
|
|
3c3b5920f7 | ||
|
|
c684b1d40b | ||
|
|
518f337ce8 | ||
|
|
4bf7ffa984 | ||
|
|
ae13ca524a | ||
|
|
0ffdbb2395 | ||
|
|
1934eddf29 | ||
|
|
7ad72b81c5 | ||
|
|
010f33d460 | ||
|
|
787a8b3f1c | ||
|
|
360d28b961 | ||
|
|
bb5971ba2a | ||
|
|
eca74dcccf | ||
|
|
e651e96a5b | ||
|
|
a255510cca | ||
|
|
8c0cb0bd28 | ||
|
|
0421772bbc | ||
|
|
4bfed6eb2f | ||
|
|
5fe4448541 | ||
|
|
a5089f5a79 | ||
|
|
48ae9e8874 | ||
|
|
ee34939e74 | ||
|
|
424b315ce0 | ||
|
|
1446572997 | ||
|
|
d6b968dff7 | ||
|
|
78d8e5c3d5 | ||
|
|
6c55f65d07 | ||
|
|
0819a55ffb | ||
|
|
37b4da6b92 | ||
|
|
581b94b3bd | ||
|
|
11a638048d | ||
|
|
a92e6d2c28 | ||
|
|
41f434e89f | ||
|
|
b99be9cf4e | ||
|
|
7f30afc6e5 | ||
|
|
f19abcf981 | ||
|
|
bdaff94e9a | ||
|
|
25aedddcdf | ||
|
|
3d3b014971 | ||
|
|
b1ad748842 | ||
|
|
af8dd4a307 | ||
|
|
baed9983b3 | ||
|
|
ac26ea9c5b | ||
|
|
ddd049045d | ||
|
|
7ef51239a9 | ||
|
|
760c1e284c | ||
|
|
eae040a84a | ||
|
|
374ffe87c6 | ||
|
|
05b41b159e | ||
|
|
087534c030 | ||
|
|
d0b87ee87b | ||
|
|
8799623806 | ||
|
|
a91aa5e35d | ||
|
|
509600a7f7 | ||
|
|
4f69529a04 | ||
|
|
dd08b70e46 | ||
|
|
dd0eef6aab | ||
|
|
163db3f6d0 | ||
|
|
1da4b23235 | ||
|
|
a49f1dee8a | ||
|
|
897b49f475 | ||
|
|
b140c473d1 | ||
|
|
6288be340c | ||
|
|
57e79e1d0b | ||
|
|
50e7fff0f3 | ||
|
|
c8e1b59ae5 | ||
|
|
1c7e891e44 | ||
|
|
4a94ddbd8b | ||
|
|
e2f46b9f79 | ||
|
|
68abf12afa | ||
|
|
48984dbd42 | ||
|
|
8ab8df1170 | ||
|
|
a9c34d5531 | ||
|
|
3969487376 | ||
|
|
07ea04e651 | ||
|
|
634900d270 | ||
|
|
44605744dc | ||
|
|
21c886534f | ||
|
|
2b1903cc69 | ||
|
|
485f2a02c7 | ||
|
|
c2036ab9fc | ||
|
|
3e81b4abe3 | ||
|
|
c46a0636c6 | ||
|
|
f1713b3f62 | ||
|
|
259d5078c4 | ||
|
|
6b0745ea1f | ||
|
|
39c9fa0a2b | ||
|
|
3003161eff | ||
|
|
6460446aa6 | ||
|
|
ee4691c9fb | ||
|
|
9c4b07faec | ||
|
|
7a9075c16b | ||
|
|
240627f260 | ||
|
|
745cadc944 | ||
|
|
83cb93b7ae | ||
|
|
2942870325 | ||
|
|
3b108935d0 | ||
|
|
506a32d4ab | ||
|
|
7539ab2d2e | ||
|
|
753de5a5a9 | ||
|
|
80bf857b27 | ||
|
|
aa831c7960 | ||
|
|
fc1b113b29 | ||
|
|
71f5c2d50b | ||
|
|
c3e11d6812 | ||
|
|
dba65cbd30 | ||
|
|
5bb5e2e8fc | ||
|
|
b0bceaa8bf | ||
|
|
3943960874 | ||
|
|
e8cec5c9e4 | ||
|
|
ebe520e96e | ||
|
|
ba5a02e8a9 | ||
|
|
994e6c1f60 | ||
|
|
705e2fd010 | ||
|
|
31d4d3dee7 | ||
|
|
0a8ac2ed92 | ||
|
|
08c8231cc8 | ||
|
|
bf29aa0f8c | ||
|
|
91f9884591 | ||
|
|
d189d7b5ff | ||
|
|
f2e991a341 | ||
|
|
2327b23d8e | ||
|
|
901d59b29f | ||
|
|
3df1f98b4a | ||
|
|
a056893263 | ||
|
|
e3752b5894 | ||
|
|
c1c71097a1 | ||
|
|
fb042f449b | ||
|
|
37a2edf468 | ||
|
|
4bbc72f633 | ||
|
|
7a4759f165 | ||
|
|
4414d068b3 | ||
|
|
7038bb8061 | ||
|
|
dfc0fddf22 | ||
|
|
0b3616d580 | ||
|
|
c75ebe8973 | ||
|
|
8bd62177e7 | ||
|
|
f8c632f579 | ||
|
|
da4b34355d | ||
|
|
104aef0a6e | ||
|
|
2fd95844c3 | ||
|
|
1e301d94be | ||
|
|
1e08150838 | ||
|
|
f8eb1dec64 | ||
|
|
cdc4e9f64b | ||
|
|
250de31f17 | ||
|
|
c652b6ad29 | ||
|
|
d5da847f51 | ||
|
|
0992aac61f | ||
|
|
cfd09c87f0 | ||
|
|
c233f5c05e | ||
|
|
5ea6a05bfa | ||
|
|
9aca3b6a08 | ||
|
|
8c214902d9 | ||
|
|
e411b1a36e | ||
|
|
84dcc01da1 | ||
|
|
87556afe2a | ||
|
|
5b6d62259a | ||
|
|
94fd101601 | ||
|
|
25afa92ed5 | ||
|
|
c123a1c21b | ||
|
|
89747ac758 | ||
|
|
a19031411d | ||
|
|
f83cf244cd | ||
|
|
963e707ca4 | ||
|
|
0631c37c7f | ||
|
|
8c4a941475 | ||
|
|
d447fbca77 | ||
|
|
d582d3ae5a | ||
|
|
8c82f0e5c3 | ||
|
|
219025727d | ||
|
|
f2f103b986 | ||
|
|
d6d81e6ece | ||
|
|
c01635e03e | ||
|
|
ae242720b6 | ||
|
|
11ab365324 | ||
|
|
a47eafe868 | ||
|
|
0e7ec2ffcd | ||
|
|
aedd36ac8b | ||
|
|
95015d474e | ||
|
|
2643658b6f | ||
|
|
7709cb1355 | ||
|
|
b34d26ff25 | ||
|
|
e00a07b885 | ||
|
|
5dae561d33 | ||
|
|
96efeadd6e | ||
|
|
437716c5b4 | ||
|
|
d99edade72 | ||
|
|
4dd92180c6 | ||
|
|
3628f16dd6 | ||
|
|
1eab22f0da | ||
|
|
bf80d5ad0e | ||
|
|
91662a5b69 | ||
|
|
9c9529f798 | ||
|
|
f81da5e57a | ||
|
|
31a6c2fac8 | ||
|
|
ba11d334db | ||
|
|
48f7e389fb | ||
|
|
4d1e0b4409 | ||
|
|
2a22858fe7 | ||
|
|
b8738dd623 | ||
|
|
05c85ddc21 | ||
|
|
04788421fe | ||
|
|
49003242d1 | ||
|
|
185f43afef | ||
|
|
6727b46454 | ||
|
|
03f3b95248 | ||
|
|
5641227c9b | ||
|
|
fabb84a785 | ||
|
|
e424af32b7 | ||
|
|
ac09581cc2 | ||
|
|
c9c84ca7ee | ||
|
|
cf913621f1 | ||
|
|
579f0746f0 | ||
|
|
cfbdf7757b | ||
|
|
139eb64b43 | ||
|
|
66a77d129a | ||
|
|
8899f3fbfb | ||
|
|
1110e84cce | ||
|
|
dc79d94c38 | ||
|
|
d9879c2533 | ||
|
|
5454c4eaa3 | ||
|
|
4ac47a0219 | ||
|
|
edde8eff9f | ||
|
|
e3fabe9a44 | ||
|
|
5355d387e9 | ||
|
|
e1561ed1df | ||
|
|
7e608c5728 | ||
|
|
32f503f738 | ||
|
|
d58693b0f0 | ||
|
|
837a249f01 | ||
|
|
e9f9f14f22 | ||
|
|
b301f4ea01 | ||
|
|
86a3a6475f | ||
|
|
548d000891 | ||
|
|
b2afca4560 | ||
|
|
2d1da5ab13 | ||
|
|
8777c9477a | ||
|
|
5b11e9adff | ||
|
|
ab0d4dbc69 | ||
|
|
95dff31951 | ||
|
|
447d67d5f3 | ||
|
|
95e174e2fb | ||
|
|
81f6edbfd5 | ||
|
|
3141c3976b | ||
|
|
256ebcd827 | ||
|
|
474376f30a | ||
|
|
2f1fe55f66 | ||
|
|
ef7b08ce7f | ||
|
|
e0e34f0a13 | ||
|
|
db8dbbf371 | ||
|
|
0a99e7a5c1 | ||
|
|
65884f4d9e | ||
|
|
af87944585 | ||
|
|
36dbe2d74e | ||
|
|
8d8a785bd2 | ||
|
|
d8fbfc7aa1 | ||
|
|
ddce7c28e4 | ||
|
|
fcad0ec015 | ||
|
|
730ab7b019 | ||
|
|
40317f079e | ||
|
|
c0b7d762b2 | ||
|
|
bc2e30453b | ||
|
|
fb72160caf | ||
|
|
85f57859fd | ||
|
|
7b9432d564 | ||
|
|
effab3f91a | ||
|
|
9d47ae824c | ||
|
|
ba8625a701 | ||
|
|
dd8dcb8228 | ||
|
|
061afc7993 | ||
|
|
b64402ede2 | ||
|
|
a14ada5730 | ||
|
|
33db761551 | ||
|
|
1d3e97f2ab | ||
|
|
f7a44ad101 | ||
|
|
7b7a76e161 | ||
|
|
55ecae3e58 | ||
|
|
5a99e527ff | ||
|
|
5e33dabda1 | ||
|
|
fd9b3b2260 | ||
|
|
7fd74fc7a3 | ||
|
|
4deed587e7 | ||
|
|
a3f97eeeeb | ||
|
|
db3115cee9 | ||
|
|
cc201fdcaa | ||
|
|
cec97ebc6f | ||
|
|
73636c2ed0 | ||
|
|
8f6ecbf37b | ||
|
|
4fb2eefac2 | ||
|
|
a36396992d | ||
|
|
e8e574fbe4 | ||
|
|
23e064ad29 | ||
|
|
1a94c70336 | ||
|
|
8581806558 | ||
|
|
e76ea37772 | ||
|
|
2c2deb87f8 | ||
|
|
f10a5ae4d7 | ||
|
|
4b5e39c89c | ||
|
|
cfbbb23141 | ||
|
|
a9f265d166 | ||
|
|
d3f813a14e | ||
|
|
2cda677d06 | ||
|
|
6bd86d1044 | ||
|
|
0f81ecf5f4 | ||
|
|
4e673656a1 | ||
|
|
014924ba89 | ||
|
|
82f5a4ab29 | ||
|
|
175d934cff | ||
|
|
8c86207258 | ||
|
|
d74b7eb144 | ||
|
|
482e771af1 | ||
|
|
3948fcad2d | ||
|
|
bad6c9a427 | ||
|
|
9a64fd7d55 | ||
|
|
91977159ee | ||
|
|
3fab117e4e | ||
|
|
f6f852fd93 | ||
|
|
75825a9f01 | ||
|
|
9ff0f4987f | ||
|
|
8157784483 | ||
|
|
177c401e02 | ||
|
|
0a010a59eb | ||
|
|
779b77a164 | ||
|
|
a443b9f7e7 | ||
|
|
1e4824a841 | ||
|
|
61db4cfac5 | ||
|
|
ca7a1973e2 | ||
|
|
d050f1e622 | ||
|
|
47f32a76ef | ||
|
|
8cb86a583a | ||
|
|
c0da680f13 | ||
|
|
742e059da1 | ||
|
|
97dd7d5103 | ||
|
|
8e12f4a21c | ||
|
|
7601f20d70 | ||
|
|
e8ce1db471 | ||
|
|
ee7fc26de1 | ||
|
|
2fbdee19da | ||
|
|
0e91183300 | ||
|
|
aaba8c1080 | ||
|
|
d4899bd4d5 | ||
|
|
f8132f932d | ||
|
|
33339ae595 | ||
|
|
ecdc14f535 | ||
|
|
7e12b9f47c | ||
|
|
80150a18d3 | ||
|
|
818156f6f7 | ||
|
|
be63ba99ca | ||
|
|
a26305d428 | ||
|
|
e518b22b72 | ||
|
|
9a313f767f | ||
|
|
6a0667567d | ||
|
|
36a28fcb0c | ||
|
|
05f025c075 | ||
|
|
5fd99e62ed | ||
|
|
5653bc61a4 | ||
|
|
0df34b4c96 | ||
|
|
b2fbf93df0 | ||
|
|
c5c93724fe | ||
|
|
0c749d96ea | ||
|
|
928858457b | ||
|
|
bdead39f63 | ||
|
|
702b42eaf3 | ||
|
|
43afcc0d99 | ||
|
|
fe941a26a3 | ||
|
|
ab7c09dc8e | ||
|
|
34b4a490b1 | ||
|
|
989e39d995 | ||
|
|
e2ee223dc2 | ||
|
|
69f018c49e | ||
|
|
fae09456ae | ||
|
|
9f9c3326fe | ||
|
|
21e5ffbcf8 | ||
|
|
ea1499a372 | ||
|
|
c5b5a984cd | ||
|
|
0fcf1d1ae7 | ||
|
|
5fccfed4f4 | ||
|
|
c4d060bf80 | ||
|
|
e40505e489 | ||
|
|
61cd433131 | ||
|
|
e076ae756d | ||
|
|
8215c0ac0e | ||
|
|
b222d4386e | ||
|
|
4d62de3898 | ||
|
|
0ad87649d4 | ||
|
|
9f9a9ac426 | ||
|
|
71d0615e98 | ||
|
|
f3db59d990 | ||
|
|
bc3e691a1e | ||
|
|
51b011ce24 | ||
|
|
d758f4a8a7 | ||
|
|
33ae9f5d44 | ||
|
|
ab1d761865 | ||
|
|
f2e7dda910 | ||
|
|
36b4003118 | ||
|
|
f40b08d8f0 | ||
|
|
250a3987cf | ||
|
|
9688f343a5 | ||
|
|
1fceb2207a | ||
|
|
fa76e4a8c9 | ||
|
|
4091b9c87e | ||
|
|
7d637362b7 | ||
|
|
deb9fa482d | ||
|
|
344009bf26 | ||
|
|
54ae254537 | ||
|
|
b366750e11 | ||
|
|
868b20ce4e | ||
|
|
2b255d0ebf | ||
|
|
b1d65b62db | ||
|
|
1071385896 | ||
|
|
29005ef7b1 | ||
|
|
29ef73f21d | ||
|
|
78cf6e63ff | ||
|
|
5fb63a09f9 | ||
|
|
595891729e | ||
|
|
f285c0a2e5 | ||
|
|
ae66b24369 | ||
|
|
40de3c67cd | ||
|
|
d13cfe10f6 | ||
|
|
a42caac805 | ||
|
|
0539191d18 | ||
|
|
1eb5a700f9 | ||
|
|
e61eb409fd | ||
|
|
ce7ad480f4 | ||
|
|
0e1a057449 | ||
|
|
f87e378d48 | ||
|
|
c2b004ba0e | ||
|
|
22fdcfc71a | ||
|
|
28c1ca1240 | ||
|
|
7ae5c3f7a6 | ||
|
|
5e4e5f7d9d | ||
|
|
f4ca1325ae | ||
|
|
996be85843 | ||
|
|
9a2915ce66 | ||
|
|
b2c5969aff | ||
|
|
21dc5dc92b | ||
|
|
2200ffa8b0 | ||
|
|
3345b25962 | ||
|
|
9edf2418e0 | ||
|
|
1fb87cd196 | ||
|
|
e3fb74942a | ||
|
|
c6a97eb9ce | ||
|
|
82bdbdba24 | ||
|
|
4e0c8b55fb | ||
|
|
afa9f824e7 | ||
|
|
02a2151b2b | ||
|
|
138c2a6b97 | ||
|
|
dffdee966f | ||
|
|
dec5fcd50b | ||
|
|
00e475c434 | ||
|
|
77a4276a8c | ||
|
|
7150b7f28d | ||
|
|
79c99aeb2b | ||
|
|
537f8bcbdb | ||
|
|
882b7d95cc | ||
|
|
980cdd61be | ||
|
|
65be8275da | ||
|
|
316da85818 | ||
|
|
5a6a378725 | ||
|
|
7e98ed93f4 | ||
|
|
9d85367679 | ||
|
|
827f0fd8ef | ||
|
|
23ee243113 | ||
|
|
92e9a5032b | ||
|
|
45c56b80c4 | ||
|
|
36610fb697 | ||
|
|
c97bbd3797 | ||
|
|
b82a51a5cd | ||
|
|
239c146a4b | ||
|
|
fd43c2b99a | ||
|
|
80c1f69b9e | ||
|
|
10d50aadf2 | ||
|
|
82030cd0af | ||
|
|
88dedb8824 | ||
|
|
f786feac0a | ||
|
|
17e11e2c92 | ||
|
|
f6f8436e97 | ||
|
|
3f012eb0f8 | ||
|
|
467102fa78 | ||
|
|
f37b0a10a5 | ||
|
|
12916e229c | ||
|
|
c4f8cc34df | ||
|
|
1ae4b50bde | ||
|
|
8f8d03df46 | ||
|
|
2d549662be | ||
|
|
d8e44dc685 | ||
|
|
1757a31750 | ||
|
|
d4f8f92eb0 | ||
|
|
93b1fe63e5 | ||
|
|
a8bbefbbb4 | ||
|
|
55530bfc0f | ||
|
|
e8a302017f | ||
|
|
b594c34f57 | ||
|
|
92d4cf15f0 | ||
|
|
cd8bd7f617 | ||
|
|
75d7409c4e | ||
|
|
cbedf2f7ca | ||
|
|
e4fce5d6ae | ||
|
|
e1eb298de1 | ||
|
|
82a1316f76 | ||
|
|
93582ad85e | ||
|
|
36b0169ed6 | ||
|
|
cdca9d3c8e | ||
|
|
736f4b3581 | ||
|
|
9d3d8d6fc0 | ||
|
|
e1a3f33a26 | ||
|
|
d5baa0381f | ||
|
|
18b3c49296 | ||
|
|
bf32650c83 | ||
|
|
720d566d03 | ||
|
|
9be71700eb | ||
|
|
72310c87a5 | ||
|
|
0137103f4b | ||
|
|
a74f6b2867 | ||
|
|
68d856f618 | ||
|
|
7e3a6c6b9d | ||
|
|
da62fca305 | ||
|
|
484ca368f0 | ||
|
|
a500c1f0b5 | ||
|
|
9db3099572 | ||
|
|
99d8fc975e | ||
|
|
4d18d39d99 | ||
|
|
0609a5729c | ||
|
|
ec4879ac5b | ||
|
|
6ec6fdaf8c | ||
|
|
2c722277ee | ||
|
|
f88db708ac | ||
|
|
fcf5ad1bd6 | ||
|
|
2f5789bdef | ||
|
|
37f5d8696d | ||
|
|
048dcf288a | ||
|
|
ca0ebe0f71 | ||
|
|
db833f2411 | ||
|
|
a7534dbb7e | ||
|
|
4841c48f81 | ||
|
|
d4e81f9ec8 | ||
|
|
1da0599e0e | ||
|
|
2149a04ca8 | ||
|
|
92a7740e90 | ||
|
|
795e9151a1 | ||
|
|
4569e3e430 | ||
|
|
40aab4c502 | ||
|
|
332a594fd4 | ||
|
|
7870978c2e | ||
|
|
23620b827c | ||
|
|
fa54bd542e | ||
|
|
259c5c0b5f | ||
|
|
515ba0dfb7 | ||
|
|
2be921d883 |
53
.clang-format
Normal file
53
.clang-format
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
# If true, clang-format will attempt to re-flow comments
|
||||||
|
ReflowComments: false
|
||||||
|
# The column limit.
|
||||||
|
ColumnLimit: 100
|
||||||
|
# Indent width for line continuations.
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
# The number of columns to use for indentation.
|
||||||
|
IndentWidth: 8
|
||||||
|
# The number of columns used for tab stops.
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: ForIndentation
|
||||||
|
|
||||||
|
# Options for aligning backslashes in escaped newlines.
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
# Short Block Style
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
# If true, short case labels will be contracted to a single line.
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
# Dependent on the value, int f() { return 0; } can be put on a single line.
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
# The brace breaking style to use.
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
# Control of individual brace wrapping cases.
|
||||||
|
BraceWrapping:
|
||||||
|
# Wrap class definition.
|
||||||
|
AfterClass: true
|
||||||
|
# Wrap control statements
|
||||||
|
AfterControlStatement: true
|
||||||
|
# Wrap enum definitions.
|
||||||
|
AfterEnum: true
|
||||||
|
# Wrap function definitions.
|
||||||
|
AfterFunction: true
|
||||||
|
# Wrap namespace definitions.
|
||||||
|
AfterNamespace: true
|
||||||
|
# Wrap struct definitions.
|
||||||
|
AfterStruct: true
|
||||||
|
# Wrap union definitions.
|
||||||
|
AfterUnion: true
|
||||||
|
# Wrap extern blocks.
|
||||||
|
AfterExternBlock: false
|
||||||
|
# Wrap before catch.
|
||||||
|
BeforeCatch: true
|
||||||
|
# Wrap before else.
|
||||||
|
BeforeElse: true
|
||||||
|
# Indent the wrapped braces themselves.
|
||||||
|
IndentBraces: false
|
||||||
|
# If false, empty function body can be put on a single line.
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
# If false, empty record (e.g. class, struct or union) body can be put on a single line.
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
# If false, empty namespace body can be put on a single line.
|
||||||
|
SplitEmptyNamespace: false
|
||||||
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# EditorConfig
|
||||||
|
# http://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# LF end-of-line, insert an empty new line and UTF-8
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
# Tab indentation
|
||||||
|
[makefile,Makefile]
|
||||||
|
indent_style = tab
|
||||||
23
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
23
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Note: for general questions and comments, please use the forums at:
|
||||||
|
https://groups.google.com/forum/#!forum/json-c
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is, and any information about where you're running into the bug that you feel might be relevant.
|
||||||
|
|
||||||
|
**Steps To Reproduce**
|
||||||
|
List the steps to reproduce the behavior.
|
||||||
|
If possible, please attach a sample json file and/or a minimal code example.
|
||||||
|
|
||||||
|
**Version and Platform**
|
||||||
|
- json-c version: [e.g. json-c-0.14, or a specific commit hash]
|
||||||
|
- OS: [e.g. Ubuntu 20.04, Debian Buster, NetBSD 9, etc...]
|
||||||
|
- Custom cmake/build flags, if any
|
||||||
106
.gitignore
vendored
106
.gitignore
vendored
@@ -1,34 +1,18 @@
|
|||||||
|
# Temp files
|
||||||
*~
|
*~
|
||||||
*.swp
|
*.swp
|
||||||
/INSTALL
|
*.bak
|
||||||
.deps/
|
*.backup
|
||||||
.libs/
|
\#*
|
||||||
/aclocal.m4
|
.\#*
|
||||||
/autom4te.cache
|
*\#
|
||||||
/config.guess
|
*.sav
|
||||||
/json_config.h
|
*.save
|
||||||
/compile
|
*.autosav
|
||||||
/config.h
|
*.autosave
|
||||||
/config.log
|
|
||||||
/config.status
|
# Tests
|
||||||
/config.sub
|
|
||||||
/configure
|
|
||||||
/depcomp
|
|
||||||
/doc
|
|
||||||
/install-sh
|
|
||||||
/json.pc
|
|
||||||
/json-c.pc
|
|
||||||
/json-c-uninstalled.pc
|
|
||||||
/libtool
|
|
||||||
/ltmain.sh
|
|
||||||
/Makefile
|
|
||||||
/Makefile.in
|
|
||||||
/missing
|
|
||||||
/stamp-h1
|
|
||||||
/stamp-h2
|
|
||||||
/test-driver
|
|
||||||
/tests/Makefile
|
/tests/Makefile
|
||||||
/tests/Makefile.in
|
|
||||||
/tests/test1
|
/tests/test1
|
||||||
/tests/test1Formatted
|
/tests/test1Formatted
|
||||||
/tests/test2
|
/tests/test2
|
||||||
@@ -36,20 +20,74 @@
|
|||||||
/tests/test4
|
/tests/test4
|
||||||
/tests/testReplaceExisting
|
/tests/testReplaceExisting
|
||||||
/tests/testSubDir
|
/tests/testSubDir
|
||||||
/tests/test_parse_int64
|
|
||||||
/tests/test_parse
|
|
||||||
/tests/test_cast
|
/tests/test_cast
|
||||||
/tests/test_charcase
|
/tests/test_charcase
|
||||||
|
/tests/test_compare
|
||||||
|
/tests/test_deep_copy
|
||||||
|
/tests/test_double_serializer
|
||||||
|
/tests/test_float
|
||||||
|
/tests/test_int_add
|
||||||
|
/tests/test_json_pointer
|
||||||
/tests/test_locale
|
/tests/test_locale
|
||||||
/tests/test_null
|
/tests/test_null
|
||||||
|
/tests/test_parse
|
||||||
|
/tests/test_parse_int64
|
||||||
/tests/test_printbuf
|
/tests/test_printbuf
|
||||||
/tests/test_set_serializer
|
/tests/test_set_serializer
|
||||||
|
/tests/test_set_value
|
||||||
|
/tests/test_util_file
|
||||||
|
/tests/test_visit
|
||||||
/tests/*.vg.out
|
/tests/*.vg.out
|
||||||
/tests/*.log
|
/tests/*.log
|
||||||
/tests/*.trs
|
/tests/*.trs
|
||||||
|
|
||||||
|
# Generated folders
|
||||||
|
/build
|
||||||
/Debug
|
/Debug
|
||||||
/Release
|
/Release
|
||||||
*.lo
|
/*/Debug
|
||||||
*.o
|
/*/Release
|
||||||
/libjson-c.la
|
|
||||||
/libjson.la
|
# Archives
|
||||||
|
*.zip
|
||||||
|
*.tar.*
|
||||||
|
*.tgz
|
||||||
|
*.gz
|
||||||
|
*.bz2
|
||||||
|
*.xz
|
||||||
|
*.lz
|
||||||
|
*.lzma
|
||||||
|
*.7z
|
||||||
|
*.dll
|
||||||
|
*.deb
|
||||||
|
*.rpm
|
||||||
|
*.apk
|
||||||
|
*.exe
|
||||||
|
*.msi
|
||||||
|
*.dmg
|
||||||
|
*.ipa
|
||||||
|
|
||||||
|
# It's not good practice to build directly in the source tree
|
||||||
|
# but ignore cmake auto-generated files anyway:
|
||||||
|
/json_config.h
|
||||||
|
/config.h
|
||||||
|
/json-c.pc
|
||||||
|
/Makefile
|
||||||
|
/CMakeCache.txt
|
||||||
|
/CMakeFiles
|
||||||
|
/CMakeDoxyfile.in
|
||||||
|
/*.cmake
|
||||||
|
/DartConfiguration.tcl
|
||||||
|
/tests/CMakeFiles/
|
||||||
|
/tests/*.cmake
|
||||||
|
/Testing/
|
||||||
|
|
||||||
|
# ...and build artifacts.
|
||||||
|
/doc/html
|
||||||
|
/libjson-c.a
|
||||||
|
/libjson-c.so
|
||||||
|
/libjson-c.so.*
|
||||||
|
|
||||||
|
# Benchmarking input and output
|
||||||
|
/bench/data
|
||||||
|
/bench/work
|
||||||
|
|||||||
153
.travis.yml
Normal file
153
.travis.yml
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
language: cpp
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
# gcc
|
||||||
|
# xenial
|
||||||
|
# gcc 5 is the default on xenial
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- valgrind
|
||||||
|
- cppcheck
|
||||||
|
- doxygen
|
||||||
|
- cmake
|
||||||
|
env: CHECK="true"
|
||||||
|
# bionic
|
||||||
|
- os: linux
|
||||||
|
dist: bionic
|
||||||
|
compiler: gcc
|
||||||
|
env: MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
|
||||||
|
|
||||||
|
# gcc 7 is the default on bionic
|
||||||
|
- os: linux
|
||||||
|
dist: bionic
|
||||||
|
compiler: gcc
|
||||||
|
env: CHECK="true"
|
||||||
|
- os: linux
|
||||||
|
dist: bionic
|
||||||
|
compiler: gcc
|
||||||
|
env: MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
|
||||||
|
|
||||||
|
# clang
|
||||||
|
# xenial
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-xenial-5.0
|
||||||
|
packages:
|
||||||
|
- clang-5.0
|
||||||
|
- cmake
|
||||||
|
env: MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-xenial-6.0
|
||||||
|
packages:
|
||||||
|
- clang-6.0
|
||||||
|
- cmake
|
||||||
|
env: MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0"
|
||||||
|
|
||||||
|
# clang-7 is the default on xenial and bionic
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- valgrind
|
||||||
|
- cppcheck
|
||||||
|
- doxygen
|
||||||
|
- cmake
|
||||||
|
env: CHECK="true"
|
||||||
|
|
||||||
|
# bionic
|
||||||
|
- os: linux
|
||||||
|
dist: bionic
|
||||||
|
compiler: clang
|
||||||
|
env: CHECK="true"
|
||||||
|
# osx
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode9.4
|
||||||
|
env: XCODE="true"
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode10.1
|
||||||
|
env: XCODE="true" CHECK="true"
|
||||||
|
|
||||||
|
# run coveralls
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- lcov
|
||||||
|
env: CHECK="true"
|
||||||
|
before_install:
|
||||||
|
- sudo gem install coveralls-lcov
|
||||||
|
- echo $CC
|
||||||
|
- echo $LANG
|
||||||
|
- echo $LC_ALL
|
||||||
|
- set -e
|
||||||
|
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||||
|
eval "${MATRIX_EVAL}";
|
||||||
|
if [ -n "$MATRIX_EVAL" ] && [ "$TRAVIS_COMPILER" != "clang" ]; then
|
||||||
|
sudo apt-get install -y $CC;
|
||||||
|
fi;
|
||||||
|
fi
|
||||||
|
before_script:
|
||||||
|
- export CFLAGS="-fprofile-arcs -ftest-coverage"
|
||||||
|
- mkdir build && cd build && cmake ..
|
||||||
|
script:
|
||||||
|
- make
|
||||||
|
- make test
|
||||||
|
after_success:
|
||||||
|
- cd ..
|
||||||
|
- lcov -d build/ -b . -c -o build/all_coverage.info
|
||||||
|
- lcov -r build/all_coverage.info '/usr/*' '*CMakeFiles*' '*fuzz*' '*test*' -o build/coverage.info
|
||||||
|
- coveralls-lcov --verbose build/coverage.info
|
||||||
|
|
||||||
|
# allow_failures:
|
||||||
|
# - os: osx
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- echo $CC
|
||||||
|
- echo $LANG
|
||||||
|
- echo $LC_ALL
|
||||||
|
- set -e
|
||||||
|
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||||
|
eval "${MATRIX_EVAL}";
|
||||||
|
if [ -n "$MATRIX_EVAL" ] && [ "$TRAVIS_COMPILER" != "clang" ]; then
|
||||||
|
sudo apt-get install -y $CC;
|
||||||
|
fi;
|
||||||
|
fi
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# XXX osx on travis doesn't work w/ set -e, so turn it off :(
|
||||||
|
- set +e
|
||||||
|
- mkdir -p build || echo "Failed to mkdir build"
|
||||||
|
- cd build || echo "Failed to cd build"
|
||||||
|
- cmake .. || echo "Failed to run cmake"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make
|
||||||
|
# when using bionic, Travis seems to ignore the "addons" section, so installing the packages with apt-get...
|
||||||
|
- if [ -n "$CHECK" ]; then
|
||||||
|
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
|
||||||
|
brew install doxygen;
|
||||||
|
else
|
||||||
|
if [ "$TRAVIS_DIST" = "bionic" ]; then
|
||||||
|
sudo apt-get install -y valgrind cppcheck doxygen;
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
make distcheck;
|
||||||
|
if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi;
|
||||||
|
fi
|
||||||
33
AUTHORS
33
AUTHORS
@@ -1,5 +1,30 @@
|
|||||||
Michael Clark <michael@metaparadigm.com>
|
Alexander Dahl <post@lespocky.de>
|
||||||
Jehiah Czebotar <jehiah@gmail.com>
|
andy5995 <andy400-dev@yahoo.com>
|
||||||
Eric Haszlakiewicz <hawicz+json-c@gmail.com>
|
Björn Esser <besser82@fedoraproject.org>
|
||||||
|
changyong guo <guo1487@163.com>
|
||||||
|
chenguoping <chenguopingdota@163.com>
|
||||||
|
Christopher Head <chead@chead.ca>
|
||||||
|
Chris Wolfe <chriswwolfe@gmail.com>
|
||||||
C. Watford (christopher.watford@gmail.com)
|
C. Watford (christopher.watford@gmail.com)
|
||||||
|
Darjan Krijan <darjan_krijan@gmx.de>
|
||||||
|
Eric Hawicz <erh+git@nimenees.com>
|
||||||
|
grdowns <grdowns@microsoft.com>
|
||||||
|
Ivan Romanov <drizt@land.ru>
|
||||||
|
Jaap Keuter <jaap.keuter@xs4all.nl>
|
||||||
|
janczer <menshikov.ivn@gmail.com>
|
||||||
|
Jehan <jehan@girinstud.io>
|
||||||
|
Jehiah Czebotar <jehiah@gmail.com>
|
||||||
|
Jonathan Wiens <j.wiens@teles.com>
|
||||||
|
Jose Bollo <jose.bollo@iot.bzh>
|
||||||
|
Keith Holman <keith.holman@windriver.com>
|
||||||
|
Liang, Gao <liang.gao@intel.com>
|
||||||
|
max <mpano91@gmail.com>
|
||||||
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
myd7349 <myd7349@gmail.com>
|
||||||
|
Pierce Lopez <pierce.lopez@gmail.com>
|
||||||
|
Po-Chuan Hsieh <sunpoet@sunpoet.net>
|
||||||
|
Ramiro Polla <ramiro.polla@gmail.com>
|
||||||
|
Rikard Falkeborn <rikard.falkeborn@gmail.com>
|
||||||
|
Robert <roby_p97@yahoo.com>
|
||||||
|
Rubasri Kalidas <rubasri.kalidas@intel.com>
|
||||||
|
Unmanned Player <36690541+unmanned-player@users.noreply.github.com>
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
# This file is the top android makefile for all sub-modules.
|
# This file is the top android makefile for all sub-modules.
|
||||||
|
#
|
||||||
|
# Suggested settings to build for Android:
|
||||||
|
#
|
||||||
|
# export PATH=$PATH:/opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/
|
||||||
|
# export SYSROOT=/opt/android-ndk/platforms/android-9/arch-arm/usr/
|
||||||
|
# export LD=arm-linux-androideabi-ld
|
||||||
|
# export CC="arm-linux-androideabi-gcc --sysroot=/opt/android-ndk/platforms/android-9/arch-arm"
|
||||||
|
#
|
||||||
|
# Then run autogen.sh, configure and make.
|
||||||
|
#
|
||||||
|
|
||||||
LOCAL_PATH := $(call my-dir)
|
LOCAL_PATH := $(call my-dir)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|||||||
463
CMakeLists.txt
Normal file
463
CMakeLists.txt
Normal file
@@ -0,0 +1,463 @@
|
|||||||
|
# Many projects still are stuck using CMake 2.8 is several places so it's good to provide backward support too. This is
|
||||||
|
# specially true in old embedded systems (OpenWRT and friends) where CMake isn't necessarily upgraded.
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
if(POLICY CMP0048)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# JSON-C library is C only project.
|
||||||
|
project(json-c LANGUAGES C VERSION 0.14.99)
|
||||||
|
|
||||||
|
# If we've got 3.0 then it's good, let's provide support. Otherwise, leave it be.
|
||||||
|
if(POLICY CMP0038)
|
||||||
|
# Policy CMP0038 introduced was in CMake 3.0
|
||||||
|
cmake_policy(SET CMP0038 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(POLICY CMP0054)
|
||||||
|
cmake_policy(SET CMP0054 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# set default build type if not specified by user
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE debug)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
|
||||||
|
|
||||||
|
# Include file check macros honor CMAKE_REQUIRED_LIBRARIES
|
||||||
|
# i.e. the check_include_file() calls will include -lm when checking.
|
||||||
|
if(POLICY CMP0075)
|
||||||
|
cmake_policy(SET CMP0075 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING AND
|
||||||
|
(NOT MSVC OR NOT (MSVC_VERSION LESS 1800)) # Tests need at least VS2013
|
||||||
|
)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT MSVC) # cmd line apps don't built on Windows currently.
|
||||||
|
add_subdirectory(apps)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set some packaging variables.
|
||||||
|
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
|
||||||
|
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
|
||||||
|
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
|
||||||
|
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
|
||||||
|
set(JSON_C_BUGREPORT "json-c@googlegroups.com")
|
||||||
|
set(CPACK_SOURCE_IGNORE_FILES
|
||||||
|
${PROJECT_SOURCE_DIR}/build
|
||||||
|
${PROJECT_SOURCE_DIR}/cmake-build-debug
|
||||||
|
${PROJECT_SOURCE_DIR}/pack
|
||||||
|
${PROJECT_SOURCE_DIR}/.idea
|
||||||
|
${PROJECT_SOURCE_DIR}/.DS_Store
|
||||||
|
${PROJECT_SOURCE_DIR}/.git
|
||||||
|
${PROJECT_SOURCE_DIR}/.vscode)
|
||||||
|
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
include(CheckIncludeFile)
|
||||||
|
include(CheckIncludeFiles)
|
||||||
|
include(CheckCSourceCompiles)
|
||||||
|
include(CheckTypeSize)
|
||||||
|
include(CPack)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
option(BUILD_SHARED_LIBS "Default to building shared libraries" ON)
|
||||||
|
option(BUILD_STATIC_LIBS "Default to building static libraries" ON)
|
||||||
|
|
||||||
|
# Generate a release merge and test it to verify the correctness of republishing the package.
|
||||||
|
ADD_CUSTOM_TARGET(distcheck
|
||||||
|
COMMAND make package_source
|
||||||
|
COMMAND tar -xvf "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source.tar.gz"
|
||||||
|
COMMAND mkdir "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build"
|
||||||
|
COMMAND cmake "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/" -B"./${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build/"
|
||||||
|
COMMAND make -C "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build"
|
||||||
|
COMMAND make test -C "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source/build"
|
||||||
|
COMMAND rm -rf "${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-Source"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Enable or disable features. By default, all features are turned off.
|
||||||
|
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function." OFF)
|
||||||
|
option(DISABLE_THREAD_LOCAL_STORAGE "Disable using Thread-Local Storage (HAVE___THREAD)." OFF)
|
||||||
|
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF)
|
||||||
|
option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF)
|
||||||
|
option(ENABLE_THREADING "Enable partial threading support." OFF)
|
||||||
|
|
||||||
|
if (UNIX OR MINGW OR CYGWIN)
|
||||||
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (UNIX)
|
||||||
|
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS /D_CRT_SECURE_NO_DEPRECATE)
|
||||||
|
list(APPEND CMAKE_REQUIRED_FLAGS /wd4996)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_include_file("fcntl.h" HAVE_FCNTL_H)
|
||||||
|
check_include_file("inttypes.h" HAVE_INTTYPES_H)
|
||||||
|
check_include_file(stdarg.h HAVE_STDARG_H)
|
||||||
|
check_include_file(strings.h HAVE_STRINGS_H)
|
||||||
|
check_include_file(string.h HAVE_STRING_H)
|
||||||
|
check_include_file(syslog.h HAVE_SYSLOG_H)
|
||||||
|
|
||||||
|
|
||||||
|
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
|
||||||
|
|
||||||
|
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||||
|
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||||
|
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage
|
||||||
|
|
||||||
|
check_include_file("dlfcn.h" HAVE_DLFCN_H)
|
||||||
|
check_include_file("endian.h" HAVE_ENDIAN_H)
|
||||||
|
check_include_file("limits.h" HAVE_LIMITS_H)
|
||||||
|
check_include_file("locale.h" HAVE_LOCALE_H)
|
||||||
|
check_include_file("memory.h" HAVE_MEMORY_H)
|
||||||
|
|
||||||
|
check_include_file(stdint.h HAVE_STDINT_H)
|
||||||
|
check_include_file(stdlib.h HAVE_STDLIB_H)
|
||||||
|
check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H)
|
||||||
|
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
|
||||||
|
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
|
||||||
|
check_include_file(xlocale.h HAVE_XLOCALE_H)
|
||||||
|
|
||||||
|
if (HAVE_INTTYPES_H AND NOT MSVC)
|
||||||
|
set(JSON_C_HAVE_INTTYPES_H 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN)
|
||||||
|
check_symbol_exists(_finite "float.h" HAVE_DECL__FINITE)
|
||||||
|
|
||||||
|
if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX)
|
||||||
|
check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY)
|
||||||
|
check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF)
|
||||||
|
check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN)
|
||||||
|
check_symbol_exists(nan "math.h" HAVE_DECL_NAN)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_symbol_exists(_doprnt "stdio.h" HAVE_DOPRNT)
|
||||||
|
if (UNIX OR MINGW OR CYGWIN)
|
||||||
|
check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
|
||||||
|
endif()
|
||||||
|
check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF)
|
||||||
|
check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
|
||||||
|
check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF)
|
||||||
|
|
||||||
|
if (HAVE_FCNTL_H)
|
||||||
|
check_symbol_exists(open "fcntl.h" HAVE_OPEN)
|
||||||
|
endif()
|
||||||
|
if (HAVE_STDLIB_H)
|
||||||
|
check_symbol_exists(realloc "stdlib.h" HAVE_REALLOC)
|
||||||
|
endif()
|
||||||
|
if (HAVE_LOCALE_H)
|
||||||
|
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE)
|
||||||
|
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
|
||||||
|
endif()
|
||||||
|
if (HAVE_STRINGS_H)
|
||||||
|
check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP)
|
||||||
|
check_symbol_exists(strncasecmp "strings.h" HAVE_STRNCASECMP)
|
||||||
|
endif()
|
||||||
|
if (HAVE_STRING_H)
|
||||||
|
check_symbol_exists(strdup "string.h" HAVE_STRDUP)
|
||||||
|
check_symbol_exists(strerror "string.h" HAVE_STRERROR)
|
||||||
|
endif()
|
||||||
|
if (HAVE_SYSLOG_H)
|
||||||
|
check_symbol_exists(vsyslog "syslog.h" HAVE_VSYSLOG)
|
||||||
|
endif()
|
||||||
|
if (HAVE_SYS_RESOURCE_H)
|
||||||
|
check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL)
|
||||||
|
check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL)
|
||||||
|
|
||||||
|
set(json_c_strtoll "strtoll")
|
||||||
|
if (NOT HAVE_STRTOLL)
|
||||||
|
# Use _strtoi64 if strtoll is not available.
|
||||||
|
check_symbol_exists(_strtoi64 "stdlib.h" __have_strtoi64)
|
||||||
|
if (__have_strtoi64)
|
||||||
|
#set(HAVE_STRTOLL 1)
|
||||||
|
set(json_c_strtoll "_strtoi64")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(json_c_strtoull "strtoull")
|
||||||
|
if (NOT HAVE_STRTOULL)
|
||||||
|
# Use _strtoui64 if strtoull is not available.
|
||||||
|
check_symbol_exists(_strtoui64 "stdlib.h" __have_strtoui64)
|
||||||
|
if (__have_strtoui64)
|
||||||
|
#set(HAVE_STRTOULL 1)
|
||||||
|
set(json_c_strtoull "_strtoui64")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
check_type_size(int SIZEOF_INT)
|
||||||
|
check_type_size(int64_t SIZEOF_INT64_T)
|
||||||
|
check_type_size(long SIZEOF_LONG)
|
||||||
|
check_type_size("long long" SIZEOF_LONG_LONG)
|
||||||
|
check_type_size("size_t" SIZEOF_SIZE_T)
|
||||||
|
if (MSVC)
|
||||||
|
list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h)
|
||||||
|
check_type_size("SSIZE_T" SIZEOF_SSIZE_T)
|
||||||
|
else()
|
||||||
|
check_type_size("ssize_t" SIZEOF_SSIZE_T)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_c_source_compiles(
|
||||||
|
[=[
|
||||||
|
extern void json_object_get();
|
||||||
|
__asm__(".section .gnu.json_object_get\\n\\t.ascii \\"Please link against libjson-c instead of libjson\\"\\n\\t.text");
|
||||||
|
int main(int c, char *v) { return 0;}
|
||||||
|
]=]
|
||||||
|
HAS_GNU_WARNING_LONG)
|
||||||
|
|
||||||
|
check_c_source_compiles(
|
||||||
|
"int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }"
|
||||||
|
HAVE_ATOMIC_BUILTINS)
|
||||||
|
|
||||||
|
if (NOT DISABLE_THREAD_LOCAL_STORAGE)
|
||||||
|
check_c_source_compiles(
|
||||||
|
"__thread int x = 0; int main() { return 0; }"
|
||||||
|
HAVE___THREAD)
|
||||||
|
|
||||||
|
if (HAVE___THREAD)
|
||||||
|
set(SPEC___THREAD __thread)
|
||||||
|
elseif (MSVC)
|
||||||
|
set(SPEC___THREAD __declspec(thread))
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility.
|
||||||
|
if (WIN32)
|
||||||
|
set(ENABLE_RDRAND 0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Once we've done basic symbol/header searches let's add them in.
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.in ${PROJECT_BINARY_DIR}/config.h)
|
||||||
|
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/config.h")
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h)
|
||||||
|
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/json_config.h")
|
||||||
|
|
||||||
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
|
||||||
|
if ("${DISABLE_WERROR}" STREQUAL "OFF")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
||||||
|
endif()
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
|
||||||
|
if (NOT WIN32)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-D_GNU_SOURCE)
|
||||||
|
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4702")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
|
||||||
|
check_c_source_compiles(
|
||||||
|
[=[
|
||||||
|
/* uClibc toolchains without threading barf when _REENTRANT is defined */
|
||||||
|
#define _REENTRANT 1
|
||||||
|
#include <sys/types.h>
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
]=]
|
||||||
|
REENTRANT_WORKS
|
||||||
|
)
|
||||||
|
if (REENTRANT_WORKS)
|
||||||
|
add_compile_options("-D_REENTRANT")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# OSX Mach-O doesn't support linking with '-Bsymbolic-functions'.
|
||||||
|
# Others may not support it, too.
|
||||||
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions")
|
||||||
|
check_c_source_compiles(
|
||||||
|
[=[
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
]=]
|
||||||
|
BSYMBOLIC_WORKS
|
||||||
|
)
|
||||||
|
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions")
|
||||||
|
if (DISABLE_BSYMBOLIC STREQUAL "OFF" AND BSYMBOLIC_WORKS)
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
|
||||||
|
# XXX need cmake>=3.13 for this:
|
||||||
|
#add_link_options("-Wl,-Bsymbolic-functions")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if ($ENV{VALGRIND})
|
||||||
|
# Build so that valgrind doesn't complain about linkhash.c
|
||||||
|
add_definitions(-DVALGRIND=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(JSON_C_PUBLIC_HEADERS
|
||||||
|
# Note: config.h is _not_ included here
|
||||||
|
${PROJECT_BINARY_DIR}/json_config.h
|
||||||
|
|
||||||
|
${PROJECT_SOURCE_DIR}/json.h
|
||||||
|
${PROJECT_SOURCE_DIR}/arraylist.h
|
||||||
|
${PROJECT_SOURCE_DIR}/debug.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_c_version.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_inttypes.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_object.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_object_iterator.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_pointer.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_tokener.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_types.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_util.h
|
||||||
|
${PROJECT_SOURCE_DIR}/json_visit.h
|
||||||
|
${PROJECT_SOURCE_DIR}/linkhash.h
|
||||||
|
${PROJECT_SOURCE_DIR}/printbuf.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(JSON_C_HEADERS
|
||||||
|
${JSON_C_PUBLIC_HEADERS}
|
||||||
|
${PROJECT_SOURCE_DIR}/json_object_private.h
|
||||||
|
${PROJECT_SOURCE_DIR}/random_seed.h
|
||||||
|
${PROJECT_SOURCE_DIR}/strerror_override.h
|
||||||
|
${PROJECT_SOURCE_DIR}/strerror_override_private.h
|
||||||
|
${PROJECT_SOURCE_DIR}/math_compat.h
|
||||||
|
${PROJECT_SOURCE_DIR}/snprintf_compat.h
|
||||||
|
${PROJECT_SOURCE_DIR}/strdup_compat.h
|
||||||
|
${PROJECT_SOURCE_DIR}/vasprintf_compat.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(JSON_C_SOURCES
|
||||||
|
${PROJECT_SOURCE_DIR}/arraylist.c
|
||||||
|
${PROJECT_SOURCE_DIR}/debug.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_c_version.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_object.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_object_iterator.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_pointer.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_tokener.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_util.c
|
||||||
|
${PROJECT_SOURCE_DIR}/json_visit.c
|
||||||
|
${PROJECT_SOURCE_DIR}/linkhash.c
|
||||||
|
${PROJECT_SOURCE_DIR}/printbuf.c
|
||||||
|
${PROJECT_SOURCE_DIR}/random_seed.c
|
||||||
|
${PROJECT_SOURCE_DIR}/strerror_override.c
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR})
|
||||||
|
include_directories(${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
|
add_subdirectory(doc)
|
||||||
|
|
||||||
|
# uninstall
|
||||||
|
add_custom_target(uninstall
|
||||||
|
COMMAND cat ${PROJECT_BINARY_DIR}/install_manifest.txt | xargs rm
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# XXX for a normal full distribution we'll need to figure out
|
||||||
|
# XXX how to build both shared and static libraries.
|
||||||
|
# Probably leverage that to build a local VALGRIND=1 library for testing too.
|
||||||
|
add_library(${PROJECT_NAME}
|
||||||
|
${JSON_C_SOURCES}
|
||||||
|
${JSON_C_HEADERS}
|
||||||
|
)
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
VERSION 5.0.0
|
||||||
|
SOVERSION 5)
|
||||||
|
list(APPEND CMAKE_TARGETS ${PROJECT_NAME})
|
||||||
|
# If json-c is used as subroject it set to target correct interface -I flags and allow
|
||||||
|
# to build external target without extra include_directories(...)
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
# Allow to build static and shared libraries at the same time
|
||||||
|
if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
|
||||||
|
set(STATIC_LIB ${PROJECT_NAME}-static)
|
||||||
|
add_library(${STATIC_LIB} STATIC
|
||||||
|
${JSON_C_SOURCES}
|
||||||
|
${JSON_C_HEADERS}
|
||||||
|
)
|
||||||
|
|
||||||
|
# rename the static library
|
||||||
|
if (NOT MSVC)
|
||||||
|
set_target_properties(${STATIC_LIB} PROPERTIES
|
||||||
|
OUTPUT_NAME ${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
list(APPEND CMAKE_TARGETS ${STATIC_LIB})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# Always create new install dirs with 0755 permissions, regardless of umask
|
||||||
|
set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
|
||||||
|
OWNER_READ
|
||||||
|
OWNER_WRITE
|
||||||
|
OWNER_EXECUTE
|
||||||
|
GROUP_READ
|
||||||
|
GROUP_EXECUTE
|
||||||
|
WORLD_READ
|
||||||
|
WORLD_EXECUTE
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS ${CMAKE_TARGETS}
|
||||||
|
EXPORT ${PROJECT_NAME}-targets
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(EXPORT ${PROJECT_NAME}-targets
|
||||||
|
FILE ${PROJECT_NAME}-targets.cmake
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
"cmake/Config.cmake.in"
|
||||||
|
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
|
||||||
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (UNIX OR MINGW OR CYGWIN)
|
||||||
|
SET(prefix ${CMAKE_INSTALL_PREFIX})
|
||||||
|
# exec_prefix is prefix by default and CMake does not have the
|
||||||
|
# concept.
|
||||||
|
SET(exec_prefix ${CMAKE_INSTALL_PREFIX})
|
||||||
|
SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
|
SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
||||||
|
SET(VERSION ${PROJECT_VERSION})
|
||||||
|
configure_file(json-c.pc.in json-c.pc @ONLY)
|
||||||
|
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||||
|
install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/json-c)
|
||||||
275
ChangeLog
275
ChangeLog
@@ -1,5 +1,265 @@
|
|||||||
|
|
||||||
|
Next Release 0.15
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Deprecated and removed features:
|
||||||
|
--------------------------------
|
||||||
|
...none yet...
|
||||||
|
|
||||||
|
Other changes
|
||||||
|
--------------
|
||||||
|
* Add a json_parse binary, for use in testing changes (not installed).
|
||||||
|
* Issue #471: always create directories with mode 0755, regardless of umask.
|
||||||
|
* Added a JSON_TOKENER_ALLOW_TRAILING_CHARS flag to allow multiple objects
|
||||||
|
to be parsed even when JSON_TOKENER_STRICT is set.
|
||||||
|
* Split the internal json_object structure into several sub-types, one for
|
||||||
|
each json_type (json_object_object, json_object_string, etc...).
|
||||||
|
This improves memory usage and speed, with the benchmark under
|
||||||
|
bench/ report 5.8% faster test time and 6%(max RSS)-12%(peak heap)
|
||||||
|
less memory usage.
|
||||||
|
Memory used just for json_object structures decreased 27%, so use cases
|
||||||
|
with fewer arrays and/or strings would benefit more.
|
||||||
|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
0.14 (up to commit 9ed00a6, 2020/04/14)
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
Deprecated and removed features:
|
||||||
|
--------------------------------
|
||||||
|
* bits.h has been removed
|
||||||
|
* lh_abort() has been removed
|
||||||
|
* lh_table_lookup() has been removed, use lh_table_lookup_ex() instead.
|
||||||
|
* Remove TRUE and FALSE defines, use 1 and 0 instead.
|
||||||
|
|
||||||
|
Build changes:
|
||||||
|
--------------
|
||||||
|
## Deprecated and removed features:
|
||||||
|
* bits.h has been removed
|
||||||
|
* lh_abort() has been removed
|
||||||
|
* lh_table_lookup() has been removed, use lh_table_lookup_ex() instead.
|
||||||
|
* Remove TRUE and FALSE defines, use 1 and 0 instead.
|
||||||
|
* autoconf support, including autogen.sh, has been removed. See details about cmake, below.
|
||||||
|
* With the addition of json_tokener_get_parse_end(), access to internal fields of json_tokener, as well as use of many other symbols and types in json_tokener.h, is deprecated now.
|
||||||
|
* The use of Android.configure.mk to build for Android no longer works, and it is unknown how (or if) the new cmake-based build machinery can be used.
|
||||||
|
* Reports of success, or pull requests to correct issues are welcome.
|
||||||
|
|
||||||
|
## Notable improvements and new features
|
||||||
|
|
||||||
|
### Builds and documentation
|
||||||
|
* Build machinery has been switched to CMake. See README.md for details about how to build.
|
||||||
|
* TL;DR: `mkdir build ; cd build ; cmake -DCMAKE_INSTALL_PREFIX=/some/path ../json-c ; make all test install`
|
||||||
|
* To ease the transition, there is a `cmake-configure` wrapper that emulates the old autoconf-based configure script.
|
||||||
|
* This has enabled improvements to the build on Windows system; also all public functions have been fixed to be properly exported. For best results, use Visual Studio 2015 or newer.
|
||||||
|
* The json-c style guide has been updated to specify the use of clang-format, and all code has been reformatted.
|
||||||
|
* Since many lines of code have trivial changes now, when using git blame, be sure to specify -w
|
||||||
|
* Numerous improvements have been made to the documentation including function effects on refcounts, when passing a NULL is safe, and so on.
|
||||||
|
|
||||||
|
### json_tokener changes
|
||||||
|
* Added a json_tokener_get_parse_end() function to replace direct access of tok->char_offset.
|
||||||
|
* The char_offset field, and the rest of the json_tokener structure remain exposed for now, but expect a future release to hide it like is done with json_object_private.h
|
||||||
|
* json_tokener_parse_ex() now accepts a new JSON_TOKENER_VALIDATE_UTF8 flag to validate that input is UTF8.
|
||||||
|
* If validation fails, json_tokener_get_error(tok) will return json_tokener_error_parse_utf8_string (see enum json_tokener_error).
|
||||||
|
|
||||||
|
### Other changes and additions
|
||||||
|
* Add support for unsigned 64-bit integers, uint64_t, to gain one extra bit of magnitude for positive ints.
|
||||||
|
* json_tokener will now parse values up to UINT64_MAX (18446744073709551615)
|
||||||
|
* Existing methods returning int32_t or int64_t will cap out-of-range values at INT32_MAX or INT64_MAX, preserving existing behavior.
|
||||||
|
* The implementation includes the possibility of easily extending this to larger sizes in the future.
|
||||||
|
* A total of 7 new functions were added:
|
||||||
|
* json_object_get_uint64 ( struct json_object const* jso )
|
||||||
|
* json_object_new_uint64 ( uint64_t i )
|
||||||
|
* json_object_set_uint64 ( struct json_object* jso, uint64_t new_value )
|
||||||
|
* json_parse_uint64 ( char const* buf, uint64_t* retval )
|
||||||
|
* See description of uint64 support, above.
|
||||||
|
* json_tokener_get_parse_end ( struct json_tokener* tok )
|
||||||
|
* See details under "json_tokener changes", above.
|
||||||
|
* json_object_from_fd_ex ( int fd, int in_depth )
|
||||||
|
* Allows the max nesting depth to be specified.
|
||||||
|
* json_object_new_null ( )
|
||||||
|
* Simply returns NULL. Its use is not recommended.
|
||||||
|
* The size of struct json_object has decreased from 96 bytes to 88 bytes.
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
* Many updates were made to test cases, increasing code coverage.
|
||||||
|
* There is now a quick way (JSONC_TEST_TRACE=1) to turn on shell tracing in tests.
|
||||||
|
* To run tests, use `make test`; the old "check" target no longer exists.
|
||||||
|
|
||||||
|
## Significant bug fixes
|
||||||
|
For the full list of issues and pull requests since the previous release, please see issues_closed_for_0.14.md
|
||||||
|
|
||||||
|
* [Issue #389](https://github.com/json-c/json-c/issues/389): Add an assert to explicitly crash when _ref_count is corrupted, instead of a later "double free" error.
|
||||||
|
* [Issue #407](https://github.com/json-c/json-c/issues/407): fix incorrect casts in calls to ctype functions (isdigit and isspace) so we don't crash when asserts are enabled on certain platforms and characters > 128 are parsed.
|
||||||
|
* [Issue #418](https://github.com/json-c/json-c/issues/418): Fix docs for json_util_from_fd and json_util_from_file to say that they return NULL on failures.
|
||||||
|
* [Issue #422](https://github.com/json-c/json-c/issues/422): json_object.c:set errno in json_object_get_double() when called on a json_type_string object with bad content.
|
||||||
|
* [Issue #453](https://github.com/json-c/json-c/issues/453): Fixed misalignment in JSON serialization when JSON_C_TO_STRING_SPACED and JSON_C_TO_STRING_PRETTY are used together.
|
||||||
|
* [Issue #463](https://github.com/json-c/json-c/issues/463): fix newlocale() call to use LC_NUMERIC_MASK instead of LC_NUMERIC, and remove incorrect comment.
|
||||||
|
* [Issue #486](https://github.com/json-c/json-c/issues/486): append a missing ".0" to negative double values to ensure they are serialized as floating point numbers.
|
||||||
|
* [Issue #488](https://github.com/json-c/json-c/issues/488): use JSON_EXPORT on functions so they are properly exported on Windows.
|
||||||
|
* [Issue #539](https://github.com/json-c/json-c/issues/539): use an internal-only serializer function in json_object_new_double_s() to avoid potential conflicts with user code that uses the json_object_userdata_to_json_string serializer.
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
0.13.1 (up to commit 0f814e5, 2018/03/04)
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
* Bump the major version of the .so library generated up to 4.0 to avoid
|
||||||
|
conflicts because some downstream packagers of json-c had already done
|
||||||
|
their own bump to ".so.3" for a much older 0.12 release.
|
||||||
|
* Add const size_t json_c_object_sizeof()
|
||||||
|
* Avoid invalid free (and thus a segfault) when ref_count gets < 0
|
||||||
|
* PR#394: fix handling of custom double formats that include a ".0"
|
||||||
|
* Avoid uninitialized variable warnings in json_object_object_foreach
|
||||||
|
* Issue #396: fix build for certain uClibc based systems.
|
||||||
|
* Add a top level fuzz directory for fuzzers run by OSS-Fuzz
|
||||||
|
|
||||||
|
|
||||||
|
0.13 (up to commit 5dae561, 2017/11/29)
|
||||||
|
=================================
|
||||||
|
|
||||||
|
This release, being three and a half years after the 0.12 branch (f84d9c),
|
||||||
|
has quite a number of changes included. The following is a sampling of
|
||||||
|
the most significant ones.
|
||||||
|
|
||||||
|
Since the 0.12 release, 250 issues and pull requests have been closed.
|
||||||
|
See issues_closed_for_0.13.md for a complete list.
|
||||||
|
|
||||||
|
|
||||||
|
Deprecated and removed features:
|
||||||
|
--------------------------------
|
||||||
|
* All internal use of bits.h has been eliminated. The file will be removed.
|
||||||
|
Do not use: hexdigit(), error_ptr(), error_descrition() and it_error()
|
||||||
|
* lh_abort() is deprecated. It will be removed.
|
||||||
|
|
||||||
|
Behavior changes:
|
||||||
|
-----------------
|
||||||
|
* Tighten the number parsing algorithm to raise errors instead of truncating
|
||||||
|
the results. For example 12.3.4 or 2015-01-15, which now return null.
|
||||||
|
See commit 99d8fc
|
||||||
|
|
||||||
|
* Use size_t for array length and size. Platforms where sizeof(size_t) != sizeof(int) may not be backwards compatible
|
||||||
|
See commits 45c56b, 92e9a5 and others.
|
||||||
|
|
||||||
|
* Check for failue when allocating memory, returning NULL and errno=ENOMEM.
|
||||||
|
See commit 2149a04.
|
||||||
|
|
||||||
|
* Change json_object_object_add() return type from void to int, and will return -1 on failures, instead of exiting. (Note: this is not an ABI change)
|
||||||
|
|
||||||
|
New features:
|
||||||
|
-------------
|
||||||
|
* We're aiming to follow RFC 7159 now.
|
||||||
|
|
||||||
|
* Add a couple of additional option to json_object_to_json_string_ext:
|
||||||
|
JSON_C_TO_STRING_PRETTY_TAB
|
||||||
|
JSON_C_TO_STRING_NOSLASHESCAPE
|
||||||
|
|
||||||
|
* Add a json_object_object_add_ex() function to allow for performance
|
||||||
|
improvements when certain constraints are known to be true.
|
||||||
|
|
||||||
|
* Make serialization format of doubles configurable, in two different ways:
|
||||||
|
Call json_object_set_serializer with json_object_double_to_json_string and a custom
|
||||||
|
format on each double object, or
|
||||||
|
Call json_c_set_serialization_double_format() to set a global or thread-wide format.
|
||||||
|
|
||||||
|
* Add utility function for comparing json_objects - json_object_equal()
|
||||||
|
|
||||||
|
* Add a way to copy entire object trees: json_object_deep_copy()
|
||||||
|
* Add json_object_set_<type> function to modify the value of existing json_object's
|
||||||
|
without the need to recreate them. Also add a json_object_int_inc function to
|
||||||
|
adjust an int's value.
|
||||||
|
* Add support for JSON pointer, RFC 6901. See json_pointer.h
|
||||||
|
* Add a json_util_get_last_err() function to retrieve the string describing the
|
||||||
|
cause of errors, instead of printing to stderr.
|
||||||
|
* Add perllike hash function for strings, and json_global_set_string_hash() 8f8d03d
|
||||||
|
* Add a json_c_visit() function to provide a way to iterate over a tree of json-c objects.
|
||||||
|
|
||||||
|
Notable bug fixes and other improvements:
|
||||||
|
-----------------------------------------
|
||||||
|
* Make reference increment and decrement atomic to allow passing json objects between threads.
|
||||||
|
* Fix json_object_object_foreach to avoid uninitialized variable warnings.
|
||||||
|
* Improve performance by removing unneeded data items from hashtable code and reducing duplicate hash computation.
|
||||||
|
* Improve performance by storing small strings inside json_object
|
||||||
|
* Improve performance of json_object_to_json_string by removing variadic printf. commit 9ff0f49
|
||||||
|
* Issue #371: fix parsing of "-Infinity", and avoid needlessly copying the input when doing so.
|
||||||
|
* Fix stack buffer overflow in json_object_double_to_json_string_format() - commit 2c2deb87
|
||||||
|
* Fix various potential null ptr deref and int32 overflows
|
||||||
|
* Issue #332: fix a long-standing bug in array_list_put_idx() where it would attempt to free previously free'd entries due to not checking the current array length.
|
||||||
|
* Issue #195: use uselocale() instead of setlocale() in json_tokener to behave better in threaded environments.
|
||||||
|
* Issue #275: fix out of bounds read when handling unicode surrogate pairs.
|
||||||
|
* Ensure doubles that happen to be a whole number are emitted with ".0" - commit ca7a19
|
||||||
|
* PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensures the string is terminated.
|
||||||
|
* Fix double to int cast overflow in json_object_get_int64.
|
||||||
|
* Clamp double to int32 when narrowing in json_object_get_int.
|
||||||
|
* Use strtoll() to parse ints - instead of sscanf
|
||||||
|
* Miscellaneous smaller changes, including removing unused variables, fixing warning
|
||||||
|
about uninitialized variables adding const qualifiers, reformatting code, etc...
|
||||||
|
|
||||||
|
Build changes:
|
||||||
|
--------------
|
||||||
|
* Add Appveyor and Travis build support
|
||||||
|
* Switch to using CMake when building on Windows with Visual Studio.
|
||||||
|
A dynamic .dll is generated instead of a .lib
|
||||||
|
config.h is now generated, config.h.win32 should no longer be manually copied
|
||||||
|
* Add support for MacOS through CMake too.
|
||||||
|
* Enable silent build by default
|
||||||
|
* Link against libm when needed
|
||||||
|
* Add support for building with AddressSanitizer
|
||||||
|
* Add support for building with Clang
|
||||||
|
* Add a --enable-threading configure option, and only use the (slower) __sync_add_and_fetch()/__sync_sub_and_fetch() function when it is specified.
|
||||||
|
|
||||||
|
List of new functions added:
|
||||||
|
----------------------------
|
||||||
|
### json_object.h
|
||||||
|
* array_list_bsearch()
|
||||||
|
* array_list_del_idx()
|
||||||
|
* json_object_to_json_string_length()
|
||||||
|
* json_object_get_userdata()
|
||||||
|
* json_object_set_userdata()
|
||||||
|
* json_object_object_add_ex()
|
||||||
|
* json_object_array_bsearch()
|
||||||
|
* json_object_array_del_idx()
|
||||||
|
* json_object_set_boolean()
|
||||||
|
* json_object_set_int()
|
||||||
|
* json_object_int_inc()
|
||||||
|
* json_object_set_int64()
|
||||||
|
* json_c_set_serialization_double_format()
|
||||||
|
* json_object_double_to_json_string()
|
||||||
|
* json_object_set_double()
|
||||||
|
* json_object_set_string()
|
||||||
|
* json_object_set_string_len()
|
||||||
|
* json_object_equal()
|
||||||
|
* json_object_deep_copy()
|
||||||
|
|
||||||
|
### json_pointer.h
|
||||||
|
* json_pointer_get()
|
||||||
|
* json_pointer_getf()
|
||||||
|
* json_pointer_set()
|
||||||
|
* json_pointer_setf()
|
||||||
|
|
||||||
|
### json_util.h
|
||||||
|
* json_object_from_fd()
|
||||||
|
* json_object_to_fd()
|
||||||
|
* json_util_get_last_err()
|
||||||
|
|
||||||
|
### json_visit.h
|
||||||
|
* json_c_visit()
|
||||||
|
|
||||||
|
### linkhash.h
|
||||||
|
* json_global_set_string_hash()
|
||||||
|
* lh_table_resize()
|
||||||
|
|
||||||
|
### printbuf.h
|
||||||
|
* printbuf_strappend()
|
||||||
|
|
||||||
|
|
||||||
|
0.12.1
|
||||||
|
======
|
||||||
|
|
||||||
|
* Minimal changes to address compile issues.
|
||||||
|
|
||||||
0.12
|
0.12
|
||||||
|
====
|
||||||
|
|
||||||
* Address security issues:
|
* Address security issues:
|
||||||
* CVE-2013-6371: hash collision denial of service
|
* CVE-2013-6371: hash collision denial of service
|
||||||
@@ -39,6 +299,7 @@
|
|||||||
|
|
||||||
|
|
||||||
0.11
|
0.11
|
||||||
|
====
|
||||||
|
|
||||||
* IMPORTANT: the name of the library has changed to libjson-c.so and
|
* IMPORTANT: the name of the library has changed to libjson-c.so and
|
||||||
the header files are now in include/json-c.
|
the header files are now in include/json-c.
|
||||||
@@ -62,6 +323,7 @@
|
|||||||
* Fix a bug (buffer overrun) when expanding arrays to more than 64 entries.
|
* Fix a bug (buffer overrun) when expanding arrays to more than 64 entries.
|
||||||
|
|
||||||
0.10
|
0.10
|
||||||
|
====
|
||||||
|
|
||||||
* Add a json_object_to_json_string_ext() function to allow output to be
|
* Add a json_object_to_json_string_ext() function to allow output to be
|
||||||
formatted in a more human readable form.
|
formatted in a more human readable form.
|
||||||
@@ -110,6 +372,7 @@
|
|||||||
Brent Miller, bdmiller at yahoo dash inc dot com
|
Brent Miller, bdmiller at yahoo dash inc dot com
|
||||||
|
|
||||||
0.9
|
0.9
|
||||||
|
===
|
||||||
* Add README.html README-WIN32.html config.h.win32 to Makefile.am
|
* Add README.html README-WIN32.html config.h.win32 to Makefile.am
|
||||||
Michael Clark, <michael@metaparadigm.com>
|
Michael Clark, <michael@metaparadigm.com>
|
||||||
* Add const qualifier to the json_tokener_parse functions
|
* Add const qualifier to the json_tokener_parse functions
|
||||||
@@ -140,6 +403,7 @@
|
|||||||
Gerard Krol, g dot c dot krol at student dot tudelft dot nl
|
Gerard Krol, g dot c dot krol at student dot tudelft dot nl
|
||||||
|
|
||||||
0.8
|
0.8
|
||||||
|
===
|
||||||
* Add va_end for every va_start
|
* Add va_end for every va_start
|
||||||
Dotan Barak, dotanba at gmail dot com
|
Dotan Barak, dotanba at gmail dot com
|
||||||
* Add macros to enable compiling out debug code
|
* Add macros to enable compiling out debug code
|
||||||
@@ -152,19 +416,22 @@
|
|||||||
Geoffrey Young, geoff at modperlcookbook dot org
|
Geoffrey Young, geoff at modperlcookbook dot org
|
||||||
|
|
||||||
0.7
|
0.7
|
||||||
|
===
|
||||||
* Add escaping of backslash to json output
|
* Add escaping of backslash to json output
|
||||||
* Add escaping of foward slash on tokenizing and output
|
* Add escaping of foward slash on tokenizing and output
|
||||||
* Changes to internal tokenizer from using recursion to
|
* Changes to internal tokenizer from using recursion to
|
||||||
using a depth state structure to allow incremental parsing
|
using a depth state structure to allow incremental parsing
|
||||||
|
|
||||||
0.6
|
0.6
|
||||||
|
===
|
||||||
* Fix bug in escaping of control characters
|
* Fix bug in escaping of control characters
|
||||||
Johan Bj<EFBFBD>rklund, johbjo09 at kth dot se
|
Johan Björklund, johbjo09 at kth dot se
|
||||||
* Remove include "config.h" from headers (should only
|
* Remove include "config.h" from headers (should only
|
||||||
be included from .c files)
|
be included from .c files)
|
||||||
Michael Clark <michael@metaparadigm.com>
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
|
||||||
0.5
|
0.5
|
||||||
|
===
|
||||||
* Make headers C++ compatible by change *this to *obj
|
* Make headers C++ compatible by change *this to *obj
|
||||||
* Add ifdef C++ extern "C" to headers
|
* Add ifdef C++ extern "C" to headers
|
||||||
* Use simpler definition of min and max in bits.h
|
* Use simpler definition of min and max in bits.h
|
||||||
@@ -177,18 +444,21 @@
|
|||||||
Michael Clark <michael@metaparadigm.com>
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
|
||||||
0.4
|
0.4
|
||||||
|
===
|
||||||
* Fix additional error case in object parsing
|
* Fix additional error case in object parsing
|
||||||
* Add back sign reversal in nested object parse as error pointer
|
* Add back sign reversal in nested object parse as error pointer
|
||||||
value is negative, while error value is positive.
|
value is negative, while error value is positive.
|
||||||
Michael Clark <michael@metaparadigm.com>
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
|
||||||
0.3
|
0.3
|
||||||
|
===
|
||||||
* fix pointer arithmetic bug for error pointer check in is_error() macro
|
* fix pointer arithmetic bug for error pointer check in is_error() macro
|
||||||
* fix type passed to printbuf_memappend in json_tokener
|
* fix type passed to printbuf_memappend in json_tokener
|
||||||
* update autotools bootstrap instructions in README
|
* update autotools bootstrap instructions in README
|
||||||
Michael Clark <michael@metaparadigm.com>
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
|
||||||
0.2
|
0.2
|
||||||
|
===
|
||||||
* printbuf.c - C. Watford (christopher.watford@gmail.com)
|
* printbuf.c - C. Watford (christopher.watford@gmail.com)
|
||||||
Added a Win32/Win64 compliant implementation of vasprintf
|
Added a Win32/Win64 compliant implementation of vasprintf
|
||||||
* debug.c - C. Watford (christopher.watford@gmail.com)
|
* debug.c - C. Watford (christopher.watford@gmail.com)
|
||||||
@@ -205,10 +475,11 @@
|
|||||||
Added cast and mask to suffice size_t v. unsigned int conversion
|
Added cast and mask to suffice size_t v. unsigned int conversion
|
||||||
correctness
|
correctness
|
||||||
* json_tokener.c - sign reversal issue on error info for nested object parse
|
* json_tokener.c - sign reversal issue on error info for nested object parse
|
||||||
spotted by Johan Bj<EFBFBD>rklund (johbjo09 at kth.se)
|
spotted by Johan Björklund (johbjo09 at kth.se)
|
||||||
* json_object.c - escape " in json_escape_str
|
* json_object.c - escape " in json_escape_str
|
||||||
* Change to automake and libtool to build shared and static library
|
* Change to automake and libtool to build shared and static library
|
||||||
Michael Clark <michael@metaparadigm.com>
|
Michael Clark <michael@metaparadigm.com>
|
||||||
|
|
||||||
0.1
|
0.1
|
||||||
|
===
|
||||||
* initial release
|
* initial release
|
||||||
|
|||||||
74
Makefile.am
74
Makefile.am
@@ -1,74 +0,0 @@
|
|||||||
include Makefile.am.inc
|
|
||||||
|
|
||||||
EXTRA_DIST = README.html README-WIN32.html config.h.win32 doc json-c.vcproj
|
|
||||||
SUBDIRS = . tests
|
|
||||||
|
|
||||||
lib_LTLIBRARIES = libjson-c.la
|
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
|
||||||
pkgconfig_DATA = json-c.pc
|
|
||||||
|
|
||||||
libjson_cincludedir = $(includedir)/json-c
|
|
||||||
libjson_cinclude_HEADERS = \
|
|
||||||
arraylist.h \
|
|
||||||
bits.h \
|
|
||||||
debug.h \
|
|
||||||
json.h \
|
|
||||||
json_config.h \
|
|
||||||
json_c_version.h \
|
|
||||||
json_inttypes.h \
|
|
||||||
json_object.h \
|
|
||||||
json_object_iterator.h \
|
|
||||||
json_object_private.h \
|
|
||||||
json_tokener.h \
|
|
||||||
json_util.h \
|
|
||||||
linkhash.h \
|
|
||||||
printbuf.h \
|
|
||||||
random_seed.h
|
|
||||||
|
|
||||||
#libjsonx_includedir = $(libdir)/json-c-@VERSION@
|
|
||||||
#
|
|
||||||
#libjsonx_include_HEADERS = \
|
|
||||||
# json_config.h
|
|
||||||
|
|
||||||
libjson_c_la_LDFLAGS = -version-info 2:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@
|
|
||||||
|
|
||||||
libjson_c_la_SOURCES = \
|
|
||||||
arraylist.c \
|
|
||||||
debug.c \
|
|
||||||
json_c_version.c \
|
|
||||||
json_object.c \
|
|
||||||
json_object_iterator.c \
|
|
||||||
json_tokener.c \
|
|
||||||
json_util.c \
|
|
||||||
linkhash.c \
|
|
||||||
printbuf.c \
|
|
||||||
random_seed.c
|
|
||||||
|
|
||||||
|
|
||||||
distclean-local:
|
|
||||||
-rm -rf $(testsubdir)
|
|
||||||
-rm -rf config.h.in~ Makefile.in aclocal.m4 autom4te.cache/ config.guess config.sub depcomp install-sh ltmain.sh missing
|
|
||||||
-rm -f INSTALL test-driver tests/Makefile.in compile
|
|
||||||
|
|
||||||
maintainer-clean-local:
|
|
||||||
-rm -rf configure
|
|
||||||
|
|
||||||
uninstall-local:
|
|
||||||
rm -rf "$(DESTDIR)@includedir@/json-c"
|
|
||||||
rm -f "$(DESTDIR)@includedir@/json"
|
|
||||||
|
|
||||||
ANDROID_CFLAGS = -I$(top_srcdir) -DHAVE_CONFIG_H
|
|
||||||
|
|
||||||
Android.mk: Makefile.am
|
|
||||||
androgenizer -:PROJECT json-c \
|
|
||||||
-:SHARED libjson-c \
|
|
||||||
-:TAGS eng debug \
|
|
||||||
-:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \
|
|
||||||
-:SOURCES $(libjson_c_la_SOURCES) $(nodist_libjson_c_la_SOURCES) \
|
|
||||||
-:CFLAGS $(DEFS) $(ANDROID_CFLAGS) $(libjson_c_la_CFLAGS) \
|
|
||||||
-:LDFLAGS $(libjson_c_la_LDFLAGS) $(libjson_c_la_LIBADD) \
|
|
||||||
-:HEADER_TARGET json-c \
|
|
||||||
-:HEADERS $(libjson_cinclude_HEADERS) \
|
|
||||||
-:PASSTHROUGH LOCAL_ARM_MODE:=arm \
|
|
||||||
> $@
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
AM_CFLAGS = -Wall -Werror -Wno-error=deprecated-declarations -Wextra -Wwrite-strings -Wno-unused-parameter -std=gnu99 -D_GNU_SOURCE -D_REENTRANT
|
|
||||||
|
|
||||||
46
README
46
README
@@ -1,45 +1 @@
|
|||||||
Building on Unix with git, gcc and autotools
|
See README.md or README.html
|
||||||
|
|
||||||
Home page for json-c:
|
|
||||||
https://github.com/json-c/json-c/wiki
|
|
||||||
|
|
||||||
Caution: do NOT use sources from svn.metaparadigm.com, they are old.
|
|
||||||
|
|
||||||
Prerequisites:
|
|
||||||
gcc (or another C compiler)
|
|
||||||
libtool
|
|
||||||
|
|
||||||
If you're not using a release tarball, you'll also need:
|
|
||||||
autoconf (autoreconf)
|
|
||||||
automake
|
|
||||||
Make sure you have a complete libtool install, including libtoolize
|
|
||||||
|
|
||||||
Github repo for json-c:
|
|
||||||
https://github.com/json-c/json-c
|
|
||||||
|
|
||||||
$ git clone https://github.com/json-c/json-c.git
|
|
||||||
$ cd json-c
|
|
||||||
$ sh autogen.sh
|
|
||||||
|
|
||||||
Then
|
|
||||||
|
|
||||||
$ ./configure
|
|
||||||
$ make
|
|
||||||
$ make install
|
|
||||||
|
|
||||||
To build and run the test programs run
|
|
||||||
|
|
||||||
$ make check
|
|
||||||
|
|
||||||
Linking to libjson-c
|
|
||||||
|
|
||||||
If your system has pkgconfig then you can just add this to your makefile
|
|
||||||
|
|
||||||
CFLAGS += $(shell pkg-config --cflags json-c)
|
|
||||||
LDFLAGS += $(shell pkg-config --libs json-c)
|
|
||||||
|
|
||||||
Without pkgconfig, you would do something like this:
|
|
||||||
|
|
||||||
JSON_C_DIR=/path/to/json_c/install
|
|
||||||
CFLAGS += -I$(JSON_C_DIR)/include/json-c
|
|
||||||
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>JSON-C - A JSON implementation in C - Win32 specific notes</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h2>Windows specific notes for JSON-C</h2>
|
|
||||||
<p>Please send Win32 bug reports to <a href="mailto:christopher.watford@gmail.com">christopher.watford@gmail.com</a></p>
|
|
||||||
<p><b>Win32 Specific Changes:</b></p>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
Various functions have been redefined to their Win32 version (i.e. <tt>open</tt>
|
|
||||||
on win32 is <tt>_open</tt>)</li>
|
|
||||||
<li>
|
|
||||||
Implemented missing functions from MS's libc (i.e. <tt>vasprintf</tt>)</li>
|
|
||||||
<li>
|
|
||||||
Added code to allow Win64 support without integer resizing issues, this
|
|
||||||
probably makes it much nicer on 64bit machines everywhere (i.e. using <tt>ptrdiff_t</tt>
|
|
||||||
for pointer math)</li>
|
|
||||||
</ul>
|
|
||||||
<p><b>Porting Changelog:</b></p>
|
|
||||||
<dl>
|
|
||||||
<dt><tt>printbuf.c</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Added a Win32/Win64 compliant implementation of <tt>vasprintf</tt></dd>
|
|
||||||
<dt><tt>debug.c</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Removed usage of <tt>vsyslog</tt> on Win32/Win64 systems, needs to be handled
|
|
||||||
by a configure script</dd>
|
|
||||||
<dt><tt>json_object.c</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Added scope operator to wrap usage of <tt>json_object_object_foreach</tt>, this needs to be
|
|
||||||
rethought to be more ANSI C friendly</dd>
|
|
||||||
<dt><tt>json_object.h</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Added Microsoft C friendly version of <tt>json_object_object_foreach</tt></dd>
|
|
||||||
<dt><tt>json_tokener.c</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Added a Win32/Win64 compliant implementation of <tt>strndup</tt></dd>
|
|
||||||
<dt><tt>json_util.c</tt> - C. Watford (christopher.watford@gmail.com)</dt>
|
|
||||||
<dd>
|
|
||||||
Added cast and mask to suffice <tt>size_t</tt> v. <tt>unsigned int</tt>
|
|
||||||
conversion correctness</dd>
|
|
||||||
</dl>
|
|
||||||
<p>This program is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the MIT License. See COPYING for details.</p>
|
|
||||||
<hr />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
19
README.html
19
README.html
@@ -10,16 +10,23 @@
|
|||||||
<h3>Overview</h3>
|
<h3>Overview</h3>
|
||||||
<p>JSON-C implements a reference counting object model that allows you to easily
|
<p>JSON-C implements a reference counting object model that allows you to easily
|
||||||
construct JSON objects in C, output them as JSON formatted strings and parse
|
construct JSON objects in C, output them as JSON formatted strings and parse
|
||||||
JSON formatted strings back into the C representation of JSON objects.</p>
|
JSON formatted strings back into the C representation of JSON objects.
|
||||||
|
It aims to conform to <a href="https://tools.ietf.org/html/rfc7159">RFC 7159</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h3>Building</h3>
|
<h3>Building</h3>
|
||||||
<p>To setup JSON-C to build on your system please run <tt>configure</tt> and <tt>make</tt>.</p>
|
<p>To setup JSON-C to build on your system please run <tt>configure</tt> and <tt>make</tt>.</p>
|
||||||
<p>If you are on Win32 and are not using the VS project file, be sure
|
<p>If you are on Win32 cmake is required, generally:</p>
|
||||||
to rename <tt>config.h.win32</tt> to <tt>config.h</tt> before building.</p>
|
<ul>
|
||||||
|
<li>mkdir build</li>
|
||||||
|
<li>cd build</li>
|
||||||
|
<li>cmake ..</li>
|
||||||
|
<li>msbuild "json-c.vcxproj" /m /verbosity:normal /p:OutDir=lib\</li>
|
||||||
|
<li>Or, open the project in Visual Studio</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h3>Documentation</h3>
|
<h3>Documentation</h3>
|
||||||
<P>Doxygen generated documentation exists <a href="doc/html/json__object_8h.html">here</a>
|
<P>Doxygen generated documentation exists <a href="http://json-c.github.io/json-c/">here</a>.</P>
|
||||||
and Win32 specific notes can be found <a href="README-WIN32.html">here</a>.</P>
|
|
||||||
|
|
||||||
<h3><a href="https://github.com/json-c/json-c">GIT Reposository</a></h3>
|
<h3><a href="https://github.com/json-c/json-c">GIT Reposository</a></h3>
|
||||||
<p><strong><code>git clone https://github.com/json-c/json-c.git</code></strong></p>
|
<p><strong><code>git clone https://github.com/json-c/json-c.git</code></strong></p>
|
||||||
@@ -28,7 +35,7 @@
|
|||||||
<pi>Send email to <strong><code>json-c <i><at></i> googlegroups <i><dot></i> com</code></strong></p>
|
<pi>Send email to <strong><code>json-c <i><at></i> googlegroups <i><dot></i> com</code></strong></p>
|
||||||
|
|
||||||
<h3><a href="COPYING">License</a></h3>
|
<h3><a href="COPYING">License</a></h3>
|
||||||
<p>This program is free software; you can redistribute it and/or modify it under the terms of the MIT License..</p>
|
<p>This program is free software; you can redistribute it and/or modify it under the terms of the MIT License.</p>
|
||||||
<hr/>
|
<hr/>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
15
README.json_object-split.md
Normal file
15
README.json_object-split.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
This branch implements the changes briefly described at:
|
||||||
|
|
||||||
|
https://github.com/json-c/json-c/wiki/Proposal:-struct-json_object-split
|
||||||
|
|
||||||
|
These were originally mentioned in:
|
||||||
|
Issue #535 - short string optimization: excessive array length
|
||||||
|
|
||||||
|
The changes are expected to impact and possibly invalidate:
|
||||||
|
Issue #552 - Some anlysis about memory allocator in json-c
|
||||||
|
|
||||||
|
and will likely cause notable conflicts in any other significant un-merged
|
||||||
|
changes, such as PR#620 - Introduce json_object_new_string_{ext,noalloc}()
|
||||||
|
|
||||||
|
|
||||||
242
README.md
Normal file
242
README.md
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
`json-c`
|
||||||
|
========
|
||||||
|
|
||||||
|
1. [Overview and Build Status](#overview)
|
||||||
|
2. [Building on Unix](#buildunix)
|
||||||
|
* [Prerequisites](#installprereq)
|
||||||
|
* [Build commands](#buildcmds)
|
||||||
|
3. [CMake options](#CMake)
|
||||||
|
4. [Testing](#testing)
|
||||||
|
5. [Building with `vcpkg`](#buildvcpkg)
|
||||||
|
6. [Linking to libjson-c](#linking)
|
||||||
|
7. [Using json-c](#using)
|
||||||
|
|
||||||
|
JSON-C - A JSON implementation in C <a name="overview"></a>
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
Build Status
|
||||||
|
* [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) 
|
||||||
|
* [Travis Build](https://travis-ci.org/json-c/json-c) 
|
||||||
|
|
||||||
|
Test Status
|
||||||
|
* [Coveralls](https://coveralls.io/github/json-c/json-c?branch=master) [](https://coveralls.io/github/json-c/json-c?branch=master)
|
||||||
|
|
||||||
|
JSON-C implements a reference counting object model that allows you to easily
|
||||||
|
construct JSON objects in C, output them as JSON formatted strings and parse
|
||||||
|
JSON formatted strings back into the C representation of JSON objects.
|
||||||
|
It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
|
||||||
|
|
||||||
|
Building on Unix with `git`, `gcc` and `cmake` <a name="buildunix"></a>
|
||||||
|
--------------------------------------------------
|
||||||
|
|
||||||
|
Home page for json-c: https://github.com/json-c/json-c/wiki
|
||||||
|
|
||||||
|
### Prerequisites: <a name="installprereq"></a>
|
||||||
|
|
||||||
|
- `gcc`, `clang`, or another C compiler
|
||||||
|
|
||||||
|
- cmake>=2.8, >=3.16 recommended
|
||||||
|
|
||||||
|
To generate docs you'll also need:
|
||||||
|
- `doxygen>=1.8.13`
|
||||||
|
|
||||||
|
If you are on a relatively modern system, you'll likely be able to install
|
||||||
|
the prerequisites using your OS's packaging system.
|
||||||
|
|
||||||
|
### Install using apt (e.g. Ubuntu 16.04.2 LTS)
|
||||||
|
```sh
|
||||||
|
sudo apt install git
|
||||||
|
sudo apt install cmake
|
||||||
|
sudo apt install doxygen # optional
|
||||||
|
sudo apt install valgrind # optional
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build instructions: <a name="buildcmds"></a>
|
||||||
|
|
||||||
|
`json-c` GitHub repo: https://github.com/json-c/json-c
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ git clone https://github.com/json-c/json-c.git
|
||||||
|
$ mkdir json-c-build
|
||||||
|
$ cd json-c-build
|
||||||
|
$ cmake ../json-c # See CMake section below for custom arguments
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: it's also possible to put your build directory inside the json-c
|
||||||
|
source directory, or even not use a separate build directory at all, but
|
||||||
|
certain things might not work quite right (notably, `make distcheck`)
|
||||||
|
|
||||||
|
Then:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ make
|
||||||
|
$ make test
|
||||||
|
$ make USE_VALGRIND=0 test # optionally skip using valgrind
|
||||||
|
$ make install
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Generating documentation with Doxygen:
|
||||||
|
|
||||||
|
The libray documentation can be generated directly from the source codes using Doxygen tool:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# in build directory
|
||||||
|
make doc
|
||||||
|
google-chrome doc/html/index.html
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
CMake Options <a name="CMake"></a>
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
The json-c library is built with [CMake](https://cmake.org/cmake-tutorial/),
|
||||||
|
which can take a few options.
|
||||||
|
|
||||||
|
Variable | Type | Description
|
||||||
|
-----------------------------|--------|--------------
|
||||||
|
CMAKE_INSTALL_PREFIX | String | The install location.
|
||||||
|
CMAKE_BUILD_TYPE | String | Defaults to "debug".
|
||||||
|
BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only.
|
||||||
|
BUILD_STATIC_LIBS | Bool | The default build generates a static (lib/a) library. Set this to OFF to create a shared library only.
|
||||||
|
DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions.
|
||||||
|
DISABLE_THREAD_LOCAL_STORAGE | Bool | Disable use of Thread-Local Storage (HAVE___THREAD).
|
||||||
|
DISABLE_WERROR | Bool | Disable use of -Werror.
|
||||||
|
ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed.
|
||||||
|
ENABLE_THREADING | Bool | Enable partial threading support.
|
||||||
|
|
||||||
|
Pass these options as `-D` on CMake's command-line.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# build a static library only
|
||||||
|
cmake -DBUILD_SHARED_LIBS=OFF ..
|
||||||
|
```
|
||||||
|
|
||||||
|
### Building with partial threading support
|
||||||
|
|
||||||
|
Although json-c does not support fully multi-threaded access to
|
||||||
|
object trees, it has some code to help make its use in threaded programs
|
||||||
|
a bit safer. Currently, this is limited to using atomic operations for
|
||||||
|
json_object_get() and json_object_put().
|
||||||
|
|
||||||
|
Since this may have a performance impact, of at least 3x slower
|
||||||
|
according to https://stackoverflow.com/a/11609063, it is disabled by
|
||||||
|
default. You may turn it on by adjusting your cmake command with:
|
||||||
|
-DENABLE_THREADING=ON
|
||||||
|
|
||||||
|
Separately, the default hash function used for object field keys,
|
||||||
|
lh_char_hash, uses a compare-and-swap operation to ensure the random
|
||||||
|
seed is only generated once. Because this is a one-time operation, it
|
||||||
|
is always compiled in when the compare-and-swap operation is available.
|
||||||
|
|
||||||
|
|
||||||
|
### cmake-configure wrapper script
|
||||||
|
|
||||||
|
For those familiar with the old autoconf/autogen.sh/configure method,
|
||||||
|
there is a `cmake-configure` wrapper script to ease the transition to cmake.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
../cmake-configure --prefix=/some/install/path
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
cmake-configure can take a few options.
|
||||||
|
|
||||||
|
| options | Description|
|
||||||
|
| ---- | ---- |
|
||||||
|
| prefix=PREFIX | install architecture-independent files in PREFIX |
|
||||||
|
| enable-threading | Enable code to support partly multi-threaded use |
|
||||||
|
| enable-rdrand | Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. |
|
||||||
|
| enable-shared | build shared libraries [default=yes] |
|
||||||
|
| enable-static | build static libraries [default=yes] |
|
||||||
|
| disable-Bsymbolic | Avoid linking with -Bsymbolic-function |
|
||||||
|
| disable-werror | Avoid treating compiler warnings as fatal errors |
|
||||||
|
|
||||||
|
|
||||||
|
Testing: <a name="testing"></a>
|
||||||
|
----------
|
||||||
|
|
||||||
|
By default, if valgrind is available running tests uses it.
|
||||||
|
That can slow the tests down considerably, so to disable it use:
|
||||||
|
```sh
|
||||||
|
export USE_VALGRIND=0
|
||||||
|
```
|
||||||
|
|
||||||
|
To run tests a separate build directory is recommended:
|
||||||
|
```sh
|
||||||
|
mkdir build-test
|
||||||
|
cd build-test
|
||||||
|
# VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code
|
||||||
|
# which uses slightly slower, but valgrind-safe code.
|
||||||
|
VALGRIND=1 cmake ..
|
||||||
|
make
|
||||||
|
|
||||||
|
make test
|
||||||
|
# By default, if valgrind is available running tests uses it.
|
||||||
|
make USE_VALGRIND=0 test # optionally skip using valgrind
|
||||||
|
```
|
||||||
|
|
||||||
|
If a test fails, check `Testing/Temporary/LastTest.log`,
|
||||||
|
`tests/testSubDir/${testname}/${testname}.vg.out`, and other similar files.
|
||||||
|
If there is insufficient output try:
|
||||||
|
```sh
|
||||||
|
VERBOSE=1 make test
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```sh
|
||||||
|
JSONC_TEST_TRACE=1 make test
|
||||||
|
```
|
||||||
|
and check the log files again.
|
||||||
|
|
||||||
|
|
||||||
|
Building on Unix and Windows with `vcpkg` <a name="buildvcpkg"></a>
|
||||||
|
--------------------------------------------------
|
||||||
|
|
||||||
|
You can download and install JSON-C using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||||
|
|
||||||
|
git clone https://github.com/Microsoft/vcpkg.git
|
||||||
|
cd vcpkg
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
./vcpkg integrate install
|
||||||
|
vcpkg install json-c
|
||||||
|
|
||||||
|
The JSON-C 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.
|
||||||
|
|
||||||
|
|
||||||
|
Linking to `libjson-c` <a name="linking">
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
If your system has `pkgconfig`,
|
||||||
|
then you can just add this to your `makefile`:
|
||||||
|
|
||||||
|
```make
|
||||||
|
CFLAGS += $(shell pkg-config --cflags json-c)
|
||||||
|
LDFLAGS += $(shell pkg-config --libs json-c)
|
||||||
|
```
|
||||||
|
|
||||||
|
Without `pkgconfig`, you would do something like this:
|
||||||
|
|
||||||
|
```make
|
||||||
|
JSON_C_DIR=/path/to/json_c/install
|
||||||
|
CFLAGS += -I$(JSON_C_DIR)/include/json-c
|
||||||
|
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Using json-c <a name="using">
|
||||||
|
------------
|
||||||
|
|
||||||
|
To use json-c you can either include json.h, or preferrably, one of the
|
||||||
|
following more specific header files:
|
||||||
|
|
||||||
|
* json_object.h - Core types and methods.
|
||||||
|
* json_tokener.h - Methods for parsing and serializing json-c object trees.
|
||||||
|
* json_pointer.h - JSON Pointer (RFC 6901) implementation for retrieving
|
||||||
|
objects from a json-c object tree.
|
||||||
|
* json_object_iterator.h - Methods for iterating over single json_object instances.
|
||||||
|
* json_visit.h - Methods for walking a tree of json-c objects.
|
||||||
|
* json_util.h - Miscelleanous utility functions.
|
||||||
|
|
||||||
|
For a full list of headers see [files.html](http://json-c.github.io/json-c/json-c-0.13.1/doc/html/files.html)
|
||||||
@@ -1,57 +1,82 @@
|
|||||||
|
|
||||||
Release checklist:
|
# Release checklist:
|
||||||
|
|
||||||
release=0.12
|
## Pre-release tasks
|
||||||
|
|
||||||
|
* Figure out whether a release is worthwhile to do.
|
||||||
|
* Analyze the previous release branch to see if anything should have been
|
||||||
|
applied to master.
|
||||||
|
* Collect changes and assemble tentative release notes.
|
||||||
|
* Identify previous release branch point
|
||||||
|
* Check commit logs between previous branch point and now for
|
||||||
|
notable changes worth mentioning
|
||||||
|
* Create a new issues_closed_for_X.Y.md file
|
||||||
|
* Include notable entries from here in the release notes.
|
||||||
|
* Analyze APIs between previous release branch and master to produce list of
|
||||||
|
changes (added/removed/updated funcs, etc...), and detect backwards compat
|
||||||
|
issues.
|
||||||
|
* https://github.com/lvc/abi-compliance-checker
|
||||||
|
* If the new release is not backwards compatible, then this is a MAJOR release.
|
||||||
|
* Mention removed features in ChangeLog
|
||||||
|
* Update the AUTHORS file
|
||||||
|
* Exclude mentioning changes that have already been included in a point
|
||||||
|
release of the previous release branch.
|
||||||
|
|
||||||
|
* Update ChangeLog with relevant notes before branching.
|
||||||
|
|
||||||
|
* Check that the compile works on Linux - automatic through Travis
|
||||||
|
* Check that the compile works on NetBSD
|
||||||
|
* Check that the compile works on Windows - automatic through AppVeyor
|
||||||
|
|
||||||
|
## Release creation
|
||||||
|
|
||||||
|
Start creating the new release:
|
||||||
|
release=0.15
|
||||||
git clone https://github.com/json-c/json-c json-c-${release}
|
git clone https://github.com/json-c/json-c json-c-${release}
|
||||||
cd json-c-${release}
|
|
||||||
|
|
||||||
Check that the compile works on Linux
|
mkdir distcheck
|
||||||
Check that the compile works on NetBSD
|
cd distcheck
|
||||||
Check that the compile works on Windows
|
# Note, the build directory *must* be entirely separate from
|
||||||
Check ChangeLog to see if anything should be added.
|
# the source tree for distcheck to work properly.
|
||||||
|
cmake ../json-c-${release}
|
||||||
|
make distcheck
|
||||||
|
cd ..
|
||||||
|
|
||||||
Make any fixes/changes *before* branching.
|
Make any fixes/changes *before* branching.
|
||||||
|
|
||||||
|
cd json-c-${release}
|
||||||
git branch json-c-${release}
|
git branch json-c-${release}
|
||||||
git checkout json-c-${release}
|
git checkout json-c-${release}
|
||||||
|
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
Using ${release}:
|
||||||
Update the version in json_c_version.h
|
Update the version in json_c_version.h
|
||||||
Update the version in Doxyfile
|
Update the version in CMakeLists.txt (VERSION in the project(...) line)
|
||||||
Update the version in configure.in
|
Update the version in config.h.win32 (several places)
|
||||||
Use ${release}.
|
|
||||||
|
|
||||||
Update the libjson_la_LDFLAGS line in Makefile.am to the new version.
|
Update the set_target_properties() line in CmakeLists.txt to set the shared
|
||||||
Generally, unless we're doing a major release, change:
|
library version. Generally, unless we're doing a major release, change:
|
||||||
-version-info x:y:z
|
VERSION x.y.z
|
||||||
to
|
to
|
||||||
-version-info x:y+1:z
|
VERSION x.y+1.z
|
||||||
|
|
||||||
------------
|
git commit -a -m "Bump version to ${release}"
|
||||||
|
|
||||||
Generate the configure script and other files:
|
|
||||||
sh autogen.sh
|
|
||||||
git add -f Makefile.in aclocal.m4 config.guess \
|
|
||||||
config.sub configure depcomp install-sh \
|
|
||||||
ltmain.sh missing tests/Makefile.in \
|
|
||||||
INSTALL
|
|
||||||
|
|
||||||
# check for anything else to be added:
|
|
||||||
git status --ignored
|
|
||||||
git commit
|
|
||||||
|
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Generate the doxygen documentation:
|
Generate the doxygen documentation:
|
||||||
|
|
||||||
doxygen
|
doxygen
|
||||||
git add -f doc
|
git add -f doc
|
||||||
git commit doc
|
git commit doc
|
||||||
|
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
Create the release tarballs:
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
echo .git > excludes
|
echo .git > excludes
|
||||||
echo autom4te.cache >> excludes
|
|
||||||
tar -czf json-c-${release}.tar.gz -X excludes json-c-${release}
|
tar -czf json-c-${release}.tar.gz -X excludes json-c-${release}
|
||||||
|
|
||||||
echo doc >> excludes
|
echo doc >> excludes
|
||||||
@@ -60,6 +85,7 @@ tar -czf json-c-${release}-nodoc.tar.gz -X excludes json-c-${release}
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
Tag the branch:
|
Tag the branch:
|
||||||
|
|
||||||
cd json-c-${release}
|
cd json-c-${release}
|
||||||
git tag -a json-c-${release}-$(date +%Y%m%d) -m "Release json-c-${release}"
|
git tag -a json-c-${release}-$(date +%Y%m%d) -m "Release json-c-${release}"
|
||||||
|
|
||||||
@@ -72,7 +98,7 @@ Go to Amazon S3 service at:
|
|||||||
https://console.aws.amazon.com/s3/
|
https://console.aws.amazon.com/s3/
|
||||||
|
|
||||||
Upload the two tarballs in the json-c_releases folder.
|
Upload the two tarballs in the json-c_releases folder.
|
||||||
When uploading, use "Reduced Redundancy", and make the uploaded files publicly accessible.
|
When uploading, use "Standard" storage class, and make the uploaded files publicly accessible.
|
||||||
|
|
||||||
Logout of Amazon S3, and verify that the files are visible.
|
Logout of Amazon S3, and verify that the files are visible.
|
||||||
https://s3.amazonaws.com/json-c_releases/releases/index.html
|
https://s3.amazonaws.com/json-c_releases/releases/index.html
|
||||||
@@ -82,15 +108,20 @@ Logout of Amazon S3, and verify that the files are visible.
|
|||||||
Post-release checklist:
|
Post-release checklist:
|
||||||
|
|
||||||
git checkout master
|
git checkout master
|
||||||
Add new section to ChangeLog
|
|
||||||
Update the version in json_c_version.h
|
|
||||||
Update the version in Doxyfile
|
|
||||||
Update the version in configure.in
|
|
||||||
Use ${release}.99 to indicate a version "newer" than anything on the branch.
|
|
||||||
|
|
||||||
Leave the libjson_la_LDFLAGS line in Makefile.am alone.
|
Add new section to ChangeLog for ${release}+1
|
||||||
For more details see:
|
|
||||||
http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
Use ${release}.99 to indicate a version "newer" than anything on the branch:
|
||||||
|
Update the version in json_c_version.h
|
||||||
|
Update the version in CMakeLists.txt
|
||||||
|
Update the version in config.h.win32
|
||||||
|
|
||||||
|
Update RELEASE_CHECKLIST.txt, set release=${release}+1
|
||||||
|
|
||||||
|
Update the set_target_properties() line in CmakeLists.txt to match the release branch.
|
||||||
|
|
||||||
|
git commit -a -m "Update the master branch to version 0.${release}.99"
|
||||||
|
git push
|
||||||
|
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@@ -104,14 +135,27 @@ git clone -b gh-pages https://github.com/json-c/json-c json-c-pages
|
|||||||
cd json-c-pages
|
cd json-c-pages
|
||||||
mkdir json-c-${release}
|
mkdir json-c-${release}
|
||||||
cp -R ../json-c-${release}/doc json-c-${release}/.
|
cp -R ../json-c-${release}/doc json-c-${release}/.
|
||||||
cp ../json-c-${release}/README-WIN32.html json-c-${release}/.
|
|
||||||
git add json-c-${release}
|
git add json-c-${release}
|
||||||
git commit
|
git commit -a -m "Add the ${release} docs."
|
||||||
|
|
||||||
vi index.html
|
vi index.html
|
||||||
Add/change links to current release.
|
# Add/change links to current release.
|
||||||
|
|
||||||
|
git commit -a -m "Update the doc links to point at ${release}"
|
||||||
|
|
||||||
|
git push
|
||||||
|
|
||||||
|
------------
|
||||||
|
|
||||||
|
Update checksums on wiki page.
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
openssl sha -sha256 json-c*gz
|
||||||
|
openssl md5 json-c*gz
|
||||||
|
|
||||||
|
Copy and paste this output into the wiki page at:
|
||||||
|
https://github.com/json-c/json-c/wiki
|
||||||
|
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Send an email to the mailing list.
|
Send an email to the mailing list.
|
||||||
|
|
||||||
|
|||||||
31
STYLE.txt
Normal file
31
STYLE.txt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
In general:
|
||||||
|
For minor changes to a function, copy the existing formatting.
|
||||||
|
When changing the style, commit that separately from other changes.
|
||||||
|
For new code and major changes to a function, switch to the official json-c style.
|
||||||
|
|
||||||
|
Official json-c style:
|
||||||
|
|
||||||
|
Aim for readability, not strict conformance to fixed style rules.
|
||||||
|
Formatting is tab based; previous attempts at proper alignment with
|
||||||
|
spaces for continuation lines have been abandoned in favor of the
|
||||||
|
convenience of using clang-format.
|
||||||
|
Refer to the .clang-format file for details, and run the tool before commit:
|
||||||
|
|
||||||
|
clang-format -i somefile.c foo.h
|
||||||
|
|
||||||
|
For sections of code that would be significantly negatively impacted, surround
|
||||||
|
them with magic comments to disable formatting:
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
...code...
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
|
||||||
|
Naming:
|
||||||
|
Words within function and variable names are separated with underscores. Avoid camel case.
|
||||||
|
Prefer longer, more descriptive names, but not excessively so. No single letter variable names.
|
||||||
|
|
||||||
|
Other:
|
||||||
|
Variables should be defined for the smallest scope needed.
|
||||||
|
Functions should be defined static when possible.
|
||||||
|
When possible, avoid exposing internals in the public API.
|
||||||
122
apps/CMakeLists.txt
Normal file
122
apps/CMakeLists.txt
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.8) # see ../CMakeLists.txt for why 2.8
|
||||||
|
|
||||||
|
if(POLICY CMP0075)
|
||||||
|
cmake_policy(SET CMP0075 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
include(CheckIncludeFile)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
# First, sort out whether we're running inside a json-c build,
|
||||||
|
# or standalone, such as part of a benchmark build.
|
||||||
|
|
||||||
|
if ("${PROJECT_NAME}" STREQUAL "json-c")
|
||||||
|
# Part of an overall json-c build
|
||||||
|
set(APPS_LINK_LIBS "${PROJECT_NAME}")
|
||||||
|
|
||||||
|
# We know we have this in our current sources:
|
||||||
|
set(HAVE_JSON_TOKENER_GET_PARSE_END)
|
||||||
|
|
||||||
|
else()
|
||||||
|
|
||||||
|
# Standalone mode, using an already installed json-c library, somewhere.
|
||||||
|
# The path to the json-c install must be specified with -DCMAKE_PREFIX_PATH=...
|
||||||
|
|
||||||
|
project(apps)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
|
||||||
|
# PkgConfig is supposed to include CMAKE_PREFIX_PATH in the PKG_CONFIG_PATH
|
||||||
|
# that's used when running pkg-config, but it just doesn't work :(
|
||||||
|
# https://gitlab.kitware.com/cmake/cmake/issues/18150
|
||||||
|
#set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH True)
|
||||||
|
|
||||||
|
# Instead, we handle it explicitly here and update PKG_CONFIG_PATH ourselves.
|
||||||
|
if (NOT CMAKE_PREFIX_PATH)
|
||||||
|
message(FATAL_ERROR "Please specify -DCMAKE_PREFIX_PATH=... when running cmake.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Note: find_file isn't recursive :(
|
||||||
|
find_file(PC_FILE_PATH "json-c.pc"
|
||||||
|
PATHS "${CMAKE_PREFIX_PATH}/lib64" "${CMAKE_PREFIX_PATH}/lib"
|
||||||
|
PATH_SUFFIXES "pkgconfig"
|
||||||
|
NO_DEFAULT_PATH)
|
||||||
|
get_filename_component(PC_DIR_PATH "${PC_FILE_PATH}" DIRECTORY)
|
||||||
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${PC_DIR_PATH}")
|
||||||
|
message(STATUS "PC_FILE_PATH=${PC_FILE_PATH}")
|
||||||
|
message(STATUS "PC_DIR_PATH=${PC_DIR_PATH}")
|
||||||
|
|
||||||
|
pkg_check_modules(PC_JSONC json-c)
|
||||||
|
if (PC_JSONC_FOUND)
|
||||||
|
message(STATUS "Found json-c using pkg-config: ${PC_JSONC_PREFIX}")
|
||||||
|
message(STATUS " PC_JSONC_INCLUDE_DIRS=${PC_JSONC_INCLUDE_DIRS}")
|
||||||
|
message(STATUS " PC_JSONC_LIBRARIES=${PC_JSONC_LIBRARIES}")
|
||||||
|
message(STATUS " PC_JSONC_LIBRARY_DIRS=${PC_JSONC_LIBRARY_DIRS}")
|
||||||
|
link_directories(${PC_JSONC_LIBRARY_DIRS})
|
||||||
|
include_directories(${PC_JSONC_INCLUDE_DIRS})
|
||||||
|
# for target_link_libraries(...)
|
||||||
|
set(APPS_INCLUDE_DIRS ${PC_JSONC_INCLUDE_DIRS})
|
||||||
|
set(APPS_LINK_DIRS ${PC_JSONC_LIBRARY_DIRS})
|
||||||
|
set(APPS_LINK_LIBS ${PC_JSONC_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(STATUS "Using find_package to locate json-c")
|
||||||
|
|
||||||
|
# Note: find_package needs CMAKE_PREFIX_PATH set appropriately.
|
||||||
|
# XXX json-c's installed cmake files don't actually set up what's
|
||||||
|
# needed to use find_package() by itself, so we're just using it
|
||||||
|
# to confirm the top of the install location.
|
||||||
|
find_package(json-c CONFIG) # sets json-c_DIR
|
||||||
|
|
||||||
|
# Assume json-c-config.cmake is in lib64/cmake/json-c/
|
||||||
|
get_filename_component(json-c_TOP "${json-c_DIR}/../../.." ABSOLUTE)
|
||||||
|
get_filename_component(json-c_LIBDIR "${json-c_DIR}/../.." ABSOLUTE)
|
||||||
|
|
||||||
|
message(STATUS " json-c_TOP=${json-c_TOP}")
|
||||||
|
message(STATUS " json-c_DIR=${json-c_DIR}")
|
||||||
|
message(STATUS " json-c_LIBDIR=${json-c_LIBDIR}")
|
||||||
|
|
||||||
|
link_directories(${json-c_LIBDIR})
|
||||||
|
include_directories(${json-c_TOP}/include)
|
||||||
|
include_directories(${json-c_TOP}/include/json-c)
|
||||||
|
set(APPS_LINK_DIRS "${json-c_LIBDIR}")
|
||||||
|
set(APPS_INCLUDE_DIRS "${json-c_TOP}/include;${json-c_TOP}/include/json-c")
|
||||||
|
|
||||||
|
set(APPS_LINK_LIBS json-c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_REQUIRED_LINK_OPTIONS "-L${APPS_LINK_DIRS}")
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${APPS_LINK_LIBS})
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES ${APPS_INCLUDE_DIRS})
|
||||||
|
check_symbol_exists(json_tokener_get_parse_end "json_tokener.h" HAVE_JSON_TOKENER_GET_PARSE_END)
|
||||||
|
|
||||||
|
endif() # end "standalone mode" block
|
||||||
|
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage
|
||||||
|
if (HAVE_SYS_RESOURCE_H)
|
||||||
|
check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/apps_config.h.in
|
||||||
|
${PROJECT_BINARY_DIR}/apps_config.h)
|
||||||
|
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/apps_config.h")
|
||||||
|
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
include_directories(PUBLIC ${CMAKE_SOURCE_DIR})
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR})
|
||||||
|
include_directories(${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
# Now, finally, the actual executables we're building:
|
||||||
|
|
||||||
|
add_executable(json_parse json_parse.c)
|
||||||
|
target_link_libraries(json_parse PRIVATE ${APPS_LINK_LIBS})
|
||||||
|
|
||||||
|
# Note: it is intentional that there are no install instructions here yet.
|
||||||
|
# When/if the interface of the app(s) listed here settles down enough to
|
||||||
|
# publish as part of a regular build that will be added.
|
||||||
|
|
||||||
8
apps/cmake/apps_config.h.in
Normal file
8
apps/cmake/apps_config.h.in
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_RESOURCE_H
|
||||||
|
|
||||||
|
/* Define if you have the `getrusage' function. */
|
||||||
|
#cmakedefine HAVE_GETRUSAGE
|
||||||
|
|
||||||
|
#cmakedefine HAVE_JSON_TOKENER_GET_PARSE_END
|
||||||
187
apps/json_parse.c
Normal file
187
apps/json_parse.c
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "apps_config.h"
|
||||||
|
|
||||||
|
/* XXX for a regular program, these should be <json-c/foo.h>
|
||||||
|
* but that's inconvenient when building in the json-c source tree.
|
||||||
|
*/
|
||||||
|
#include "json_object.h"
|
||||||
|
#include "json_tokener.h"
|
||||||
|
#include "json_util.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int formatted_output = 0;
|
||||||
|
static int show_output = 1;
|
||||||
|
static int strict_mode = 0;
|
||||||
|
static const char *fname = NULL;
|
||||||
|
|
||||||
|
#ifndef HAVE_JSON_TOKENER_GET_PARSE_END
|
||||||
|
#define json_tokener_get_parse_end(tok) ((tok)->char_offset)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void usage(const char *argv0, int exitval, const char *errmsg);
|
||||||
|
static void showmem(void);
|
||||||
|
static int parseit(int fd, int (*callback)(struct json_object *));
|
||||||
|
static int showobj(struct json_object *new_obj);
|
||||||
|
|
||||||
|
static void showmem(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GETRUSAGE
|
||||||
|
struct rusage rusage;
|
||||||
|
memset(&rusage, 0, sizeof(rusage));
|
||||||
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
|
printf("maxrss: %ld KB\n", rusage.ru_maxrss);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parseit(int fd, int (*callback)(struct json_object *))
|
||||||
|
{
|
||||||
|
struct json_object *obj;
|
||||||
|
char buf[32768];
|
||||||
|
int ret;
|
||||||
|
int depth = JSON_TOKENER_DEFAULT_DEPTH;
|
||||||
|
json_tokener *tok;
|
||||||
|
|
||||||
|
tok = json_tokener_new_ex(depth);
|
||||||
|
if (!tok)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "unable to allocate json_tokener: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
json_tokener_set_flags(tok, JSON_TOKENER_STRICT
|
||||||
|
#ifdef JSON_TOKENER_ALLOW_TRAILING_CHARS
|
||||||
|
| JSON_TOKENER_ALLOW_TRAILING_CHARS
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
// XXX push this into some kind of json_tokener_parse_fd API?
|
||||||
|
// json_object_from_fd isn't flexible enough, and mirroring
|
||||||
|
// everything you can do with a tokener into json_util.c seems
|
||||||
|
// like the wrong approach.
|
||||||
|
size_t total_read = 0;
|
||||||
|
while ((ret = read(fd, buf, sizeof(buf))) > 0)
|
||||||
|
{
|
||||||
|
total_read += ret;
|
||||||
|
int start_pos = 0;
|
||||||
|
while (start_pos != ret)
|
||||||
|
{
|
||||||
|
obj = json_tokener_parse_ex(tok, &buf[start_pos], ret - start_pos);
|
||||||
|
enum json_tokener_error jerr = json_tokener_get_error(tok);
|
||||||
|
int parse_end = json_tokener_get_parse_end(tok);
|
||||||
|
if (obj == NULL && jerr != json_tokener_continue)
|
||||||
|
{
|
||||||
|
char *aterr = &buf[start_pos + parse_end];
|
||||||
|
fflush(stdout);
|
||||||
|
int fail_offset = total_read - ret + start_pos + parse_end;
|
||||||
|
fprintf(stderr, "Failed at offset %d: %s %c\n", fail_offset,
|
||||||
|
json_tokener_error_desc(jerr), aterr[0]);
|
||||||
|
json_tokener_free(tok);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (obj != NULL)
|
||||||
|
{
|
||||||
|
int cb_ret = callback(obj);
|
||||||
|
json_object_put(obj);
|
||||||
|
if (cb_ret != 0)
|
||||||
|
{
|
||||||
|
json_tokener_free(tok);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start_pos += json_tokener_get_parse_end(tok);
|
||||||
|
assert(start_pos <= ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error reading fd %d: %s\n", fd, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
json_tokener_free(tok);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int showobj(struct json_object *new_obj)
|
||||||
|
{
|
||||||
|
if (new_obj == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Failed to parse\n", fname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Successfully parsed object from %s\n", fname);
|
||||||
|
|
||||||
|
if (show_output)
|
||||||
|
{
|
||||||
|
const char *output;
|
||||||
|
if (formatted_output)
|
||||||
|
output = json_object_to_json_string(new_obj);
|
||||||
|
else
|
||||||
|
output = json_object_to_json_string_ext(new_obj, JSON_C_TO_STRING_PRETTY);
|
||||||
|
printf("%s\n", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
showmem();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usage(const char *argv0, int exitval, const char *errmsg)
|
||||||
|
{
|
||||||
|
FILE *fp = stdout;
|
||||||
|
if (exitval != 0)
|
||||||
|
fp = stderr;
|
||||||
|
if (errmsg != NULL)
|
||||||
|
fprintf(fp, "ERROR: %s\n\n", errmsg);
|
||||||
|
fprintf(fp, "Usage: %s [-f] [-n] [-s]\n", argv0);
|
||||||
|
fprintf(fp, " -f - Format the output with JSON_C_TO_STRING_PRETTY\n");
|
||||||
|
fprintf(fp, " -n - No output\n");
|
||||||
|
fprintf(fp, " -s - Parse in strict mode, flags:\n");
|
||||||
|
fprintf(fp, " JSON_TOKENER_STRICT|JSON_TOKENER_ALLOW_TRAILING_CHARS\n");
|
||||||
|
|
||||||
|
fprintf(fp, "\nWARNING WARNING WARNING\n");
|
||||||
|
fprintf(fp, "This is a prototype, it may change or be removed at any time!\n");
|
||||||
|
exit(exitval);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
json_object *new_obj;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "fhns")) != -1)
|
||||||
|
{
|
||||||
|
switch (opt)
|
||||||
|
{
|
||||||
|
case 'f': formatted_output = 1; break;
|
||||||
|
case 'n': show_output = 0; break;
|
||||||
|
case 's': strict_mode = 1; break;
|
||||||
|
case 'h': usage(argv[0], 0, NULL);
|
||||||
|
default: /* '?' */ usage(argv[0], EXIT_FAILURE, "Unknown arguments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind >= argc)
|
||||||
|
{
|
||||||
|
usage(argv[0], EXIT_FAILURE, "Expected argument after options");
|
||||||
|
}
|
||||||
|
fname = argv[optind];
|
||||||
|
|
||||||
|
int fd = open(argv[optind], O_RDONLY, 0);
|
||||||
|
showmem();
|
||||||
|
if (parseit(fd, showobj) != 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
showmem();
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
37
appveyor.yml
Normal file
37
appveyor.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
version: '{branch}.{build}'
|
||||||
|
os: Windows Server 2012 R2
|
||||||
|
|
||||||
|
platform: x64
|
||||||
|
|
||||||
|
# There should be a better way to set-up a build matrix.
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- b_toolset: Windows7.1SDK
|
||||||
|
b_config: Debug
|
||||||
|
|
||||||
|
- b_toolset: Windows7.1SDK
|
||||||
|
b_config: Release
|
||||||
|
|
||||||
|
- b_toolset: v120
|
||||||
|
b_config: Debug
|
||||||
|
|
||||||
|
- b_toolset: v120
|
||||||
|
b_config: Release
|
||||||
|
|
||||||
|
- b_toolset: v140
|
||||||
|
b_config: Debug
|
||||||
|
|
||||||
|
- b_toolset: v140
|
||||||
|
b_config: Release
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- cmake -T %b_toolset% -DCMAKE_BUILD_TYPE=%b_config% -DCMAKE_INSTALL_PREFIX=t_install .
|
||||||
|
- cmake --build . --target install
|
||||||
|
|
||||||
|
after_build:
|
||||||
|
- cd t_install
|
||||||
|
- 7z a ../json-c.win32.%b_toolset%.%b_config%.zip *
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
- path: json-c.win32.%b_toolset%.%b_config%.zip
|
||||||
|
name: json-c.win32.%b_toolset%.%b_config%.zip
|
||||||
139
arraylist.c
139
arraylist.c
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef STDC_HEADERS
|
#ifdef STDC_HEADERS
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -20,82 +22,153 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#endif /* HAVE_STRINGS_H */
|
#endif /* HAVE_STRINGS_H */
|
||||||
|
|
||||||
#include "bits.h"
|
#ifndef SIZE_T_MAX
|
||||||
|
#if SIZEOF_SIZE_T == SIZEOF_INT
|
||||||
|
#define SIZE_T_MAX UINT_MAX
|
||||||
|
#elif SIZEOF_SIZE_T == SIZEOF_LONG
|
||||||
|
#define SIZE_T_MAX ULONG_MAX
|
||||||
|
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
|
||||||
|
#define SIZE_T_MAX ULLONG_MAX
|
||||||
|
#else
|
||||||
|
#error Unable to determine size of size_t
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "arraylist.h"
|
#include "arraylist.h"
|
||||||
|
|
||||||
struct array_list*
|
struct array_list *array_list_new(array_list_free_fn *free_fn)
|
||||||
array_list_new(array_list_free_fn *free_fn)
|
|
||||||
{
|
{
|
||||||
struct array_list *arr;
|
struct array_list *arr;
|
||||||
|
|
||||||
arr = (struct array_list*)calloc(1, sizeof(struct array_list));
|
arr = (struct array_list *)malloc(sizeof(struct array_list));
|
||||||
if(!arr) return NULL;
|
if (!arr)
|
||||||
|
return NULL;
|
||||||
arr->size = ARRAY_LIST_DEFAULT_SIZE;
|
arr->size = ARRAY_LIST_DEFAULT_SIZE;
|
||||||
arr->length = 0;
|
arr->length = 0;
|
||||||
arr->free_fn = free_fn;
|
arr->free_fn = free_fn;
|
||||||
if(!(arr->array = (void**)calloc(sizeof(void*), arr->size))) {
|
if (!(arr->array = (void **)malloc(arr->size * sizeof(void *))))
|
||||||
|
{
|
||||||
free(arr);
|
free(arr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void
|
extern void array_list_free(struct array_list *arr)
|
||||||
array_list_free(struct array_list *arr)
|
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
for (i = 0; i < arr->length; i++)
|
for (i = 0; i < arr->length; i++)
|
||||||
if(arr->array[i]) arr->free_fn(arr->array[i]);
|
if (arr->array[i])
|
||||||
|
arr->free_fn(arr->array[i]);
|
||||||
free(arr->array);
|
free(arr->array);
|
||||||
free(arr);
|
free(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void *array_list_get_idx(struct array_list *arr, size_t i)
|
||||||
array_list_get_idx(struct array_list *arr, int i)
|
|
||||||
{
|
{
|
||||||
if(i >= arr->length) return NULL;
|
if (i >= arr->length)
|
||||||
|
return NULL;
|
||||||
return arr->array[i];
|
return arr->array[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int array_list_expand_internal(struct array_list *arr, int max)
|
static int array_list_expand_internal(struct array_list *arr, size_t max)
|
||||||
{
|
{
|
||||||
void *t;
|
void *t;
|
||||||
int new_size;
|
size_t new_size;
|
||||||
|
|
||||||
if(max < arr->size) return 0;
|
if (max < arr->size)
|
||||||
new_size = json_max(arr->size << 1, max);
|
return 0;
|
||||||
if(!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
|
/* Avoid undefined behaviour on size_t overflow */
|
||||||
|
if (arr->size >= SIZE_T_MAX / 2)
|
||||||
|
new_size = max;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new_size = arr->size << 1;
|
||||||
|
if (new_size < max)
|
||||||
|
new_size = max;
|
||||||
|
}
|
||||||
|
if (new_size > (~((size_t)0)) / sizeof(void *))
|
||||||
|
return -1;
|
||||||
|
if (!(t = realloc(arr->array, new_size * sizeof(void *))))
|
||||||
|
return -1;
|
||||||
arr->array = (void **)t;
|
arr->array = (void **)t;
|
||||||
(void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
|
|
||||||
arr->size = new_size;
|
arr->size = new_size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
//static inline int _array_list_put_idx(struct array_list *arr, size_t idx, void *data)
|
||||||
array_list_put_idx(struct array_list *arr, int idx, void *data)
|
int array_list_put_idx(struct array_list *arr, size_t idx, void *data)
|
||||||
{
|
{
|
||||||
if(array_list_expand_internal(arr, idx+1)) return -1;
|
if (idx > SIZE_T_MAX - 1)
|
||||||
if(arr->array[idx]) arr->free_fn(arr->array[idx]);
|
return -1;
|
||||||
|
if (array_list_expand_internal(arr, idx + 1))
|
||||||
|
return -1;
|
||||||
|
if (idx < arr->length && arr->array[idx])
|
||||||
|
arr->free_fn(arr->array[idx]);
|
||||||
arr->array[idx] = data;
|
arr->array[idx] = data;
|
||||||
if(arr->length <= idx) arr->length = idx + 1;
|
if (idx > arr->length)
|
||||||
|
{
|
||||||
|
/* Zero out the arraylist slots in between the old length
|
||||||
|
and the newly added entry so we know those entries are
|
||||||
|
empty.
|
||||||
|
e.g. when setting array[7] in an array that used to be
|
||||||
|
only 5 elements longs, array[5] and array[6] need to be
|
||||||
|
set to 0.
|
||||||
|
*/
|
||||||
|
memset(arr->array + arr->length, 0, (idx - arr->length) * sizeof(void *));
|
||||||
|
}
|
||||||
|
if (arr->length <= idx)
|
||||||
|
arr->length = idx + 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int array_list_add(struct array_list *arr, void *data)
|
||||||
array_list_add(struct array_list *arr, void *data)
|
|
||||||
{
|
{
|
||||||
return array_list_put_idx(arr, arr->length, data);
|
/* Repeat some of array_list_put_idx() so we can skip several
|
||||||
|
checks that we know are unnecessary when appending at the end
|
||||||
|
*/
|
||||||
|
size_t idx = arr->length;
|
||||||
|
if (idx > SIZE_T_MAX - 1)
|
||||||
|
return -1;
|
||||||
|
if (array_list_expand_internal(arr, idx + 1))
|
||||||
|
return -1;
|
||||||
|
arr->array[idx] = data;
|
||||||
|
arr->length++;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *))
|
||||||
array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *))
|
|
||||||
{
|
{
|
||||||
qsort(arr->array, arr->length, sizeof(arr->array[0]),
|
qsort(arr->array, arr->length, sizeof(arr->array[0]), compar);
|
||||||
(int (*)(const void *, const void *))sort_fn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void *array_list_bsearch(const void **key, struct array_list *arr,
|
||||||
array_list_length(struct array_list *arr)
|
int (*compar)(const void *, const void *))
|
||||||
|
{
|
||||||
|
return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]), compar);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t array_list_length(struct array_list *arr)
|
||||||
{
|
{
|
||||||
return arr->length;
|
return arr->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int array_list_del_idx(struct array_list *arr, size_t idx, size_t count)
|
||||||
|
{
|
||||||
|
size_t i, stop;
|
||||||
|
|
||||||
|
/* Avoid overflow in calculation with large indices. */
|
||||||
|
if (idx > SIZE_T_MAX - count)
|
||||||
|
return -1;
|
||||||
|
stop = idx + count;
|
||||||
|
if (idx >= arr->length || stop > arr->length)
|
||||||
|
return -1;
|
||||||
|
for (i = idx; i < stop; ++i)
|
||||||
|
{
|
||||||
|
if (arr->array[i])
|
||||||
|
arr->free_fn(arr->array[i]);
|
||||||
|
}
|
||||||
|
memmove(arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void *));
|
||||||
|
arr->length -= count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
39
arraylist.h
39
arraylist.h
@@ -9,6 +9,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Internal methods for working with json_type_array objects.
|
||||||
|
* Although this is exposed by the json_object_get_array() method,
|
||||||
|
* it is not recommended for direct use.
|
||||||
|
*/
|
||||||
#ifndef _arraylist_h_
|
#ifndef _arraylist_h_
|
||||||
#define _arraylist_h_
|
#define _arraylist_h_
|
||||||
|
|
||||||
@@ -16,6 +22,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#define ARRAY_LIST_DEFAULT_SIZE 32
|
#define ARRAY_LIST_DEFAULT_SIZE 32
|
||||||
|
|
||||||
typedef void(array_list_free_fn)(void *data);
|
typedef void(array_list_free_fn)(void *data);
|
||||||
@@ -23,31 +31,30 @@ typedef void (array_list_free_fn) (void *data);
|
|||||||
struct array_list
|
struct array_list
|
||||||
{
|
{
|
||||||
void **array;
|
void **array;
|
||||||
int length;
|
size_t length;
|
||||||
int size;
|
size_t size;
|
||||||
array_list_free_fn *free_fn;
|
array_list_free_fn *free_fn;
|
||||||
};
|
};
|
||||||
|
typedef struct array_list array_list;
|
||||||
|
|
||||||
extern struct array_list*
|
extern struct array_list *array_list_new(array_list_free_fn *free_fn);
|
||||||
array_list_new(array_list_free_fn *free_fn);
|
|
||||||
|
|
||||||
extern void
|
extern void array_list_free(struct array_list *al);
|
||||||
array_list_free(struct array_list *al);
|
|
||||||
|
|
||||||
extern void*
|
extern void *array_list_get_idx(struct array_list *al, size_t i);
|
||||||
array_list_get_idx(struct array_list *al, int i);
|
|
||||||
|
|
||||||
extern int
|
extern int array_list_put_idx(struct array_list *al, size_t i, void *data);
|
||||||
array_list_put_idx(struct array_list *al, int i, void *data);
|
|
||||||
|
|
||||||
extern int
|
extern int array_list_add(struct array_list *al, void *data);
|
||||||
array_list_add(struct array_list *al, void *data);
|
|
||||||
|
|
||||||
extern int
|
extern size_t array_list_length(struct array_list *al);
|
||||||
array_list_length(struct array_list *al);
|
|
||||||
|
|
||||||
extern void
|
extern void array_list_sort(struct array_list *arr, int (*compar)(const void *, const void *));
|
||||||
array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *));
|
|
||||||
|
extern void *array_list_bsearch(const void **key, struct array_list *arr,
|
||||||
|
int (*compar)(const void *, const void *));
|
||||||
|
|
||||||
|
extern int array_list_del_idx(struct array_list *arr, size_t idx, size_t count);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
13
autogen.sh
13
autogen.sh
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
autoreconf -v --install || exit 1
|
|
||||||
|
|
||||||
# If there are any options, assume the user wants to run configure.
|
|
||||||
# To run configure w/o any options, use ./autogen.sh --configure
|
|
||||||
if [ $# -gt 0 ] ; then
|
|
||||||
case "$1" in
|
|
||||||
--conf*)
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
exec ./configure "$@"
|
|
||||||
fi
|
|
||||||
80
bench/README.bench.md
Normal file
80
bench/README.bench.md
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
Benchmark tests for json-c
|
||||||
|
|
||||||
|
General strategy:
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
* Identify "after" commit hash
|
||||||
|
* Use provided directory
|
||||||
|
* Use provided commit hash
|
||||||
|
* Local changes in current working directory
|
||||||
|
* ${cur_branch}
|
||||||
|
* Identify "before" commit hash, in order of preference
|
||||||
|
* Use provided directory
|
||||||
|
* Use provided commit hash
|
||||||
|
* Use origin/${cur_branch}, if different from ${after_commit}
|
||||||
|
* Use previous release
|
||||||
|
|
||||||
|
* If not using existing dir, clone to src-${after_commit}
|
||||||
|
* or, checkout appropriate commit in existing src-${after_commit}
|
||||||
|
* Create build & install dirs for ${after_commit}
|
||||||
|
* Build & install ${after_commit}
|
||||||
|
* Compile benchmark programs against install-${after_commit}
|
||||||
|
|
||||||
|
* If not using existing dir, clone to src-${before_commit}
|
||||||
|
* or, checkout appropriate commit in existing src-${before_commit}
|
||||||
|
* Create build & install dirs for ${before_commit}
|
||||||
|
* Build & install ${before_commit}
|
||||||
|
* Compile benchmark programs against install-${before_commit}
|
||||||
|
|
||||||
|
* Run benchmark in each location
|
||||||
|
* Compare results
|
||||||
|
|
||||||
|
heaptrack memory profiler
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
https://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux.html
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
yum install libdwarf-devel elfutils boost-devel libunwind-devel
|
||||||
|
|
||||||
|
git clone git://anongit.kde.org/heaptrack
|
||||||
|
cd heaptrack
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=$HOME/heaptrack-install ..
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Issues
|
||||||
|
--------
|
||||||
|
|
||||||
|
* jc-bench.sh is incomplete.
|
||||||
|
|
||||||
|
* valgrind massif misreports "extra-heap" bytes?
|
||||||
|
|
||||||
|
"json_parse -n canada.json" shows 38640 KB maxrss.
|
||||||
|
|
||||||
|
Using valgrind --tool=massif, a large amount of memory is listed as
|
||||||
|
wasted "extra-heap" bytes. (~5.6MB)
|
||||||
|
|
||||||
|
```
|
||||||
|
valgrind --tool=massif --massif-out-file=massif.out ./json_parse -n ~/canada.json
|
||||||
|
ms_print massif.out
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Using heaptrack, and analyzing the histogram, only shows ~2.6MB
|
||||||
|
```
|
||||||
|
heaptrack ./json_parse -n canada.json
|
||||||
|
heaptrack --analyze heaptrack*gz -H histgram.out
|
||||||
|
awk ' { s=$1; count=$2; ru=(int((s+ 15) / 16)) * 16; wasted = ((ru-s)*count); print s, count, ru-s, wasted; total=total+wasted} END { print "Total: ", total }' histogram.out
|
||||||
|
```
|
||||||
|
|
||||||
|
With the (unreleased) arraylist trimming changes, maxrss reported by
|
||||||
|
getrusage() goes down, but massif claims *more* total usage, and a HUGE
|
||||||
|
extra-heap amount (50% of total).
|
||||||
|
|
||||||
284
bench/jc-bench.sh
Executable file
284
bench/jc-bench.sh
Executable file
@@ -0,0 +1,284 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Benchmarking harness for json-c
|
||||||
|
#
|
||||||
|
# Use this to compare the behavior of two different versions of the library,
|
||||||
|
# such as json-c-0.14 release vs master, master vs local changes, etc...
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
trap 'echo "FAILED!"' EXIT
|
||||||
|
|
||||||
|
RUNDIR=$(dirname "$0")
|
||||||
|
RUNDIR=$(cd "$RUNDIR" && pwd)
|
||||||
|
|
||||||
|
TOP=$(cd "$RUNDIR/.." && pwd)
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
exitval=$1
|
||||||
|
errmsg=$2
|
||||||
|
if [ $exitval -ne 0 ] ; then
|
||||||
|
exec 1>&2
|
||||||
|
fi
|
||||||
|
if [ ! -z "$errmsg" ] ; then
|
||||||
|
echo "ERROR: $errmsg" 1>&2
|
||||||
|
fi
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $0 [-h] [-v] [--build] [--run] [--compare] ...XAX...
|
||||||
|
EOF
|
||||||
|
|
||||||
|
exit $extival
|
||||||
|
}
|
||||||
|
|
||||||
|
before_arg=
|
||||||
|
after_arg=
|
||||||
|
do_all=1
|
||||||
|
do_build=0
|
||||||
|
do_run=0
|
||||||
|
do_compare=0
|
||||||
|
|
||||||
|
while [ $# -gt 0 ] ; do
|
||||||
|
case "$1" in
|
||||||
|
--before)
|
||||||
|
before_arg=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--after)
|
||||||
|
after_arg=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--build)
|
||||||
|
do_all=0
|
||||||
|
do_build=1
|
||||||
|
;;
|
||||||
|
--run)
|
||||||
|
do_all=0
|
||||||
|
do_run=1
|
||||||
|
;;
|
||||||
|
--compare)
|
||||||
|
do_all=0
|
||||||
|
do_compare=1
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
usage 0 ""
|
||||||
|
;;
|
||||||
|
-v)
|
||||||
|
set -x
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage 1 "Unknown args: $*"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
WORK="${RUNDIR}/work"
|
||||||
|
mkdir -p "${WORK}"
|
||||||
|
|
||||||
|
DATA="${RUNDIR}/data"
|
||||||
|
mkdir -p "${DATA}"
|
||||||
|
|
||||||
|
for file in citm_catalog.json twitter.json canada.json ; do
|
||||||
|
if [ ! -r "${DATA}/${file}" ] ; then
|
||||||
|
echo "Fetching ${file} from github.com/mloskot/json_benchmark"
|
||||||
|
URL="https://github.com/mloskot/json_benchmark/raw/master/data/${file}"
|
||||||
|
curl -s -L -o "${DATA}/${file}" "$URL"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Identify "after" commit hash, in order of preference
|
||||||
|
if [ ! -z "$after_arg" -a -d "$after_arg" ] ; then
|
||||||
|
# Use provided directory
|
||||||
|
after_src_dir="$after_arg"
|
||||||
|
after_commit=
|
||||||
|
echo "Using provided directory [$after_arg] as 'after'"
|
||||||
|
else
|
||||||
|
_commit=
|
||||||
|
if [ ! -z "$after_arg" ] ; then
|
||||||
|
# Use provided commit hash
|
||||||
|
_commit=$(git rev-parse --verify "$after_arg")
|
||||||
|
fi
|
||||||
|
if [ ! -z "$_commit" ] ;then
|
||||||
|
after_src_dir= # i.e. current tree
|
||||||
|
after_commit="$_commit"
|
||||||
|
echo "Using provided commit [$after_arg => $_commit] as 'after'"
|
||||||
|
else
|
||||||
|
# Local changes in current working directory
|
||||||
|
# ${cur_branch}
|
||||||
|
after_src_dir=$TOP
|
||||||
|
after_commit=
|
||||||
|
echo "Using local changes in $TOP as 'after'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Identify "before" commit hash, in order of preference
|
||||||
|
if [ ! -z "$before_arg" -a -d "$before_arg" ] ; then
|
||||||
|
# Use provided directory
|
||||||
|
before_src_dir="$before_arg"
|
||||||
|
before_commit=
|
||||||
|
echo "Using provided directory [$before_arg] as 'before'"
|
||||||
|
else
|
||||||
|
_commit=
|
||||||
|
if [ ! -z "$before_arg" ] ; then
|
||||||
|
# Use provided commit hash
|
||||||
|
_commit=$(git rev-parse --verify "$before_arg")
|
||||||
|
fi
|
||||||
|
if [ ! -z "$_commit" ] ;then
|
||||||
|
before_src_dir= # i.e. current tree
|
||||||
|
before_commit="$_commit"
|
||||||
|
echo "Using provided commit [$before_arg => $_commit] as 'before'"
|
||||||
|
else
|
||||||
|
# Use origin/${cur_branch}, if different from ${after_commit}
|
||||||
|
_cur_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
_commit=
|
||||||
|
if [ ! -z "${_cur_branch}" ] ; then
|
||||||
|
_commit=$(git rev-parse --verify "origin/${_cur_branch}")
|
||||||
|
echo "Using origin/${_cur_branch} [$_commit] as 'before'"
|
||||||
|
fi
|
||||||
|
if [ "$_commit" = "${after_commit}" ] ; then
|
||||||
|
_commit=
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$_commit" ] ; then
|
||||||
|
before_src_dir= # i.e. current tree
|
||||||
|
before_commit="$_commit"
|
||||||
|
else
|
||||||
|
# Use previous release
|
||||||
|
before_src_dir= # i.e. current tree
|
||||||
|
before_commit="$(git tag | sort | tail -1)"
|
||||||
|
echo "Using previous release [$before_commit] as 'before'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
compile_benchmark()
|
||||||
|
{
|
||||||
|
local bname=$1
|
||||||
|
local src_dir="$2"
|
||||||
|
local src_commit="$3"
|
||||||
|
|
||||||
|
local build_dir="${WORK}/$bname/build"
|
||||||
|
local inst_dir="${WORK}/$bname/install"
|
||||||
|
local bench_dir="${WORK}/$bname/bench"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "=========== $bname ==========="
|
||||||
|
echo
|
||||||
|
|
||||||
|
mkdir -p "${build_dir}"
|
||||||
|
mkdir -p "${inst_dir}"
|
||||||
|
mkdir -p "${bench_dir}"
|
||||||
|
|
||||||
|
if [ ! -z "$src_commit" ] ; then
|
||||||
|
# Resolve the short hash, tag or branch name to full hash
|
||||||
|
src_commit=$(git rev-parse $src_commit)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# No src dir specified, clone and checkout $src_commit
|
||||||
|
if [ -z "$src_dir" ] ; then
|
||||||
|
src_dir="${WORK}/$bname/src"
|
||||||
|
echo "=== Using sources in $src_dir"
|
||||||
|
mkdir -p "$src_dir"
|
||||||
|
at_commit=$(git --git-dir="$src_dir/.git" rev-parse HEAD 2> /dev/null || true)
|
||||||
|
echo "at_commit: $at_commit"
|
||||||
|
if [ -z "$at_commit" ] ; then
|
||||||
|
# Assume it's an empty dir
|
||||||
|
git clone -n "$TOP" "$src_dir"
|
||||||
|
fi
|
||||||
|
git -C "$src_dir" --git-dir="$src_dir/.git" checkout "$src_commit"
|
||||||
|
fi
|
||||||
|
# else, use the provided $src_dir
|
||||||
|
|
||||||
|
if [ -e "${src_dir}/CMakeLists.txt" ] ; then
|
||||||
|
cd "${build_dir}"
|
||||||
|
cmake -DCMAKE_INSTALL_PREFIX="${inst_dir}" "${src_dir}"
|
||||||
|
else
|
||||||
|
# Old versions of json-c used automake/autoconf
|
||||||
|
cd "${src_dir}"
|
||||||
|
sh autogen.sh # always run it, configure doesn't always work
|
||||||
|
cd "${build_dir}"
|
||||||
|
"${src_dir}/configure" --prefix="${inst_dir}"
|
||||||
|
fi
|
||||||
|
make all install
|
||||||
|
|
||||||
|
cd "${bench_dir}"
|
||||||
|
cmake -DCMAKE_PREFIX_PATH="${inst_dir}" "${TOP}/apps"
|
||||||
|
make all
|
||||||
|
}
|
||||||
|
|
||||||
|
# XXX TODO: name "after" and "before" uniquely using the dir & commit
|
||||||
|
|
||||||
|
if [ $do_all -ne 0 -o $do_build -ne 0 ] ; then
|
||||||
|
sleep 5 # Wait slightly, to allow the human to read the message
|
||||||
|
# about what exactly we're doing to benchmark.
|
||||||
|
compile_benchmark "after" "${after_src_dir}" "${after_commit}"
|
||||||
|
compile_benchmark "before" "${before_src_dir}" "${before_commit}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_benchmark()
|
||||||
|
{
|
||||||
|
local bname=$1
|
||||||
|
local inst_dir="${WORK}/$bname/install"
|
||||||
|
local bench_dir="${WORK}/$bname/bench"
|
||||||
|
|
||||||
|
local INPUT=${DATA}/canada.json
|
||||||
|
|
||||||
|
cd "${bench_dir}"
|
||||||
|
mkdir -p results
|
||||||
|
(time ./json_parse -n "${INPUT}") > results/basic_timing.out 2>&1
|
||||||
|
valgrind --tool=massif --massif-out-file=massif.out ./json_parse -n "${INPUT}"
|
||||||
|
ms_print massif.out > results/ms_print.out
|
||||||
|
heaptrack -o heaptrack_out ./json_parse -n "${INPUT}"
|
||||||
|
heaptrack --analyze heaptrack_out.gz -H histogram.out > results/heaptrack.out
|
||||||
|
awk ' { s=$1; count=$2; ru=(int((s+ 15) / 16)) * 16; wasted = ((ru-s)*count); print s, count, ru-s, wasted; total=total+wasted} END { print "Total: ", total }' histogram.out > results/histogram2.out
|
||||||
|
|
||||||
|
# XXX stamp some info about what was built & run into ./results/.
|
||||||
|
|
||||||
|
echo "DONE with $bname"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $do_all -ne 0 -o $do_run -ne 0 ] ; then
|
||||||
|
run_benchmark "after"
|
||||||
|
run_benchmark "before"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $do_compare -ne 0 ] ; then
|
||||||
|
# XXX this needs better analysis
|
||||||
|
cd "${WORK}"
|
||||||
|
diff -udr before/bench/results after/bench/results || true
|
||||||
|
else
|
||||||
|
echo "To compare results, run:"
|
||||||
|
echo "$0 --compare"
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap '' EXIT
|
||||||
|
|
||||||
|
:<<=cut
|
||||||
|
|
||||||
|
Benchmarks to run:
|
||||||
|
|
||||||
|
* Parse JSON strings, of various sizes and characteristics
|
||||||
|
* Flags: STRICT vs. non-STRICT, validate UTF8
|
||||||
|
|
||||||
|
* Serialization time
|
||||||
|
* plain, spaces, pretty
|
||||||
|
|
||||||
|
* json_c_visit tests
|
||||||
|
* JSON pointer tests
|
||||||
|
|
||||||
|
Things to record and compare:
|
||||||
|
|
||||||
|
* Running time
|
||||||
|
* Peak memory usage
|
||||||
|
* Useful bytes vs. overhead for memory allocations
|
||||||
|
* Total number of allocations
|
||||||
|
* Average allocation size
|
||||||
|
* Log of all allocation sizes
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
28
bits.h
28
bits.h
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
|
|
||||||
* Michael Clark <michael@metaparadigm.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the MIT license. See COPYING for details.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _bits_h_
|
|
||||||
#define _bits_h_
|
|
||||||
|
|
||||||
#ifndef json_min
|
|
||||||
#define json_min(a,b) ((a) < (b) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef json_max
|
|
||||||
#define json_max(a,b) ((a) > (b) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
|
|
||||||
#define error_ptr(error) ((void*)error)
|
|
||||||
#define error_description(error) (json_tokener_errors[error])
|
|
||||||
#define is_error(ptr) (ptr == NULL)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
90
cmake-configure
Executable file
90
cmake-configure
Executable file
@@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Wrapper around cmake to emulate useful options
|
||||||
|
# from the previous autoconf-based configure script.
|
||||||
|
|
||||||
|
RUNDIR=$(dirname "$0")
|
||||||
|
RUNDIR=$(cd "$RUNDIR" && pwd)
|
||||||
|
CURDIR=$(pwd)
|
||||||
|
|
||||||
|
FLAGS=()
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
exitval="$1"
|
||||||
|
errmsg="$2"
|
||||||
|
|
||||||
|
if [ $exitval -ne 0 ] ; then
|
||||||
|
exec 1>&2
|
||||||
|
fi
|
||||||
|
if [ ! -z "$errmsg" ] ; then
|
||||||
|
echo "ERROR: $errmsg" 1>&2
|
||||||
|
fi
|
||||||
|
cat <<EOF
|
||||||
|
$0 [<configure_options>] [-- [<cmake options>]]
|
||||||
|
--prefix=PREFIX install architecture-independent files in PREFIX
|
||||||
|
--enable-threading Enable code to support partly multi-threaded use
|
||||||
|
--enable-rdrand Enable RDRAND Hardware RNG Hash Seed generation on
|
||||||
|
supported x86/x64 platforms.
|
||||||
|
--enable-shared build shared libraries [default=yes]
|
||||||
|
--enable-static build static libraries [default=yes]
|
||||||
|
--disable-Bsymbolic Avoid linking with -Bsymbolic-function
|
||||||
|
--disable-werror Avoid treating compiler warnings as fatal errors
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$CURDIR" = "$RUNDIR" ] ; then
|
||||||
|
usage 1 "Please mkdir some other build directory, and run this script from there."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! cmake --version ; then
|
||||||
|
usage 1 "Unable to find a working cmake, please be sure you have it installed and on your PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while [ $# -gt 0 ] ; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
usage 0
|
||||||
|
;;
|
||||||
|
--prefix)
|
||||||
|
FLAGS+=(-DCMAKE_INSTALL_PREFIX="$2")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--prefix=*)
|
||||||
|
FLAGS+=(-DCMAKE_INSTALL_PREFIX="${1##--prefix=}")
|
||||||
|
;;
|
||||||
|
--enable-threading)
|
||||||
|
FLAGS+=(-DENABLE_THREADING=ON)
|
||||||
|
;;
|
||||||
|
--enable-rdrand)
|
||||||
|
FLAGS+=(-DENABLE_RDRAND=ON)
|
||||||
|
;;
|
||||||
|
--enable-shared)
|
||||||
|
FLAGS+=(-DBUILD_SHARED_LIBS=ON)
|
||||||
|
;;
|
||||||
|
--enable-static)
|
||||||
|
FLAGS+=(-DBUILD_STATIC_LIBS=ON)
|
||||||
|
;;
|
||||||
|
--disable-Bsymbolic)
|
||||||
|
FLAGS+=(-DDISABLE_BSYMBOLIC=ON)
|
||||||
|
;;
|
||||||
|
--disable-werror)
|
||||||
|
FLAGS+=(-DDISABLE_WERROR=ON)
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
usage 1 "Unknown arguments: $*"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
exec cmake "${FLAGS[@]}" "$@" "${RUNDIR}"
|
||||||
4
cmake/Config.cmake.in
Normal file
4
cmake/Config.cmake.in
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
||||||
213
cmake/config.h.in
Normal file
213
cmake/config.h.in
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
|
||||||
|
/* Enable RDRAND Hardware RNG Hash Seed */
|
||||||
|
#cmakedefine ENABLE_RDRAND "@ENABLE_RDRAND@"
|
||||||
|
|
||||||
|
/* Enable partial threading support */
|
||||||
|
#cmakedefine ENABLE_THREADING "@@"
|
||||||
|
|
||||||
|
/* Define if .gnu.warning accepts long strings. */
|
||||||
|
#cmakedefine HAS_GNU_WARNING_LONG "@@"
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
|
#cmakedefine HAVE_DLFCN_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <endian.h> header file. */
|
||||||
|
#cmakedefine HAVE_ENDIAN_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||||
|
#cmakedefine HAVE_FCNTL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#cmakedefine HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <limits.h> header file. */
|
||||||
|
#cmakedefine HAVE_LIMITS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <locale.h> header file. */
|
||||||
|
#cmakedefine HAVE_LOCALE_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
|
#cmakedefine HAVE_MEMORY_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDARG_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDINT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDLIB_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
|
#cmakedefine HAVE_STRINGS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
|
#cmakedefine HAVE_STRING_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <syslog.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYSLOG_H @HAVE_SYSLOG_H@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/cdefs.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_CDEFS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_PARAM_H @HAVE_SYS_PARAM_H@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_RESOURCE_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_STAT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <xlocale.h> header file. */
|
||||||
|
#cmakedefine HAVE_XLOCALE_H
|
||||||
|
|
||||||
|
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||||
|
#cmakedefine HAVE_DOPRNT
|
||||||
|
|
||||||
|
/* Has atomic builtins */
|
||||||
|
#cmakedefine HAVE_ATOMIC_BUILTINS
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you
|
||||||
|
don't. */
|
||||||
|
#cmakedefine HAVE_DECL_INFINITY
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#cmakedefine HAVE_DECL_ISINF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#cmakedefine HAVE_DECL_ISNAN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */
|
||||||
|
#cmakedefine HAVE_DECL_NAN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `_finite', and to 0 if you
|
||||||
|
don't. */
|
||||||
|
#cmakedefine HAVE_DECL__FINITE
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#cmakedefine HAVE_DECL__ISNAN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `open' function. */
|
||||||
|
#cmakedefine HAVE_OPEN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `realloc' function. */
|
||||||
|
#cmakedefine HAVE_REALLOC
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `setlocale' function. */
|
||||||
|
#cmakedefine HAVE_SETLOCALE
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `snprintf' function. */
|
||||||
|
#cmakedefine HAVE_SNPRINTF
|
||||||
|
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strcasecmp' function. */
|
||||||
|
#cmakedefine HAVE_STRCASECMP @HAVE_STRCASECMP@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strdup' function. */
|
||||||
|
#cmakedefine HAVE_STRDUP
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strerror' function. */
|
||||||
|
#cmakedefine HAVE_STRERROR
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strncasecmp' function. */
|
||||||
|
#cmakedefine HAVE_STRNCASECMP @HAVE_STRNCASECMP@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `uselocale' function. */
|
||||||
|
#cmakedefine HAVE_USELOCALE
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vasprintf' function. */
|
||||||
|
#cmakedefine HAVE_VASPRINTF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vprintf' function. */
|
||||||
|
#cmakedefine HAVE_VPRINTF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vsnprintf' function. */
|
||||||
|
#cmakedefine HAVE_VSNPRINTF
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vsyslog' function. */
|
||||||
|
#cmakedefine HAVE_VSYSLOG @HAVE_VSYSLOG@
|
||||||
|
|
||||||
|
/* Define if you have the `getrusage' function. */
|
||||||
|
#cmakedefine HAVE_GETRUSAGE
|
||||||
|
|
||||||
|
#cmakedefine HAVE_STRTOLL
|
||||||
|
#if !defined(HAVE_STRTOLL)
|
||||||
|
#define strtoll @json_c_strtoll@
|
||||||
|
/* #cmakedefine json_c_strtoll @json_c_strtoll@*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#cmakedefine HAVE_STRTOULL
|
||||||
|
#if !defined(HAVE_STRTOULL)
|
||||||
|
#define strtoull @json_c_strtoull@
|
||||||
|
/* #cmakedefine json_c_strtoull @json_c_strtoull@ */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Have __thread */
|
||||||
|
#cmakedefine HAVE___THREAD
|
||||||
|
|
||||||
|
/* Public define for json_inttypes.h */
|
||||||
|
#cmakedefine JSON_C_HAVE_INTTYPES_H @JSON_C_HAVE_INTTYPES_H@
|
||||||
|
|
||||||
|
/* Name of package */
|
||||||
|
#define PACKAGE "@PROJECT_NAME@"
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#define PACKAGE_BUGREPORT "@JSON_C_BUGREPORT@"
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#define PACKAGE_NAME "@PROJECT_NAME@"
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#define PACKAGE_STRING "@PROJECT_NAME@ @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@"
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#define PACKAGE_TARNAME "@PROJECT_NAME@"
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#define PACKAGE_URL "https://github.com/json-c/json-c"
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#define PACKAGE_VERSION "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@"
|
||||||
|
|
||||||
|
/* The number of bytes in type int */
|
||||||
|
#cmakedefine SIZEOF_INT @SIZEOF_INT@
|
||||||
|
|
||||||
|
/* The number of bytes in type int64_t */
|
||||||
|
#cmakedefine SIZEOF_INT64_T @SIZEOF_INT64_T@
|
||||||
|
|
||||||
|
/* The number of bytes in type long */
|
||||||
|
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
|
||||||
|
|
||||||
|
/* The number of bytes in type long long */
|
||||||
|
#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
|
||||||
|
|
||||||
|
/* The number of bytes in type size_t */
|
||||||
|
#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
|
||||||
|
|
||||||
|
/* The number of bytes in type ssize_t */
|
||||||
|
#cmakedefine SIZEOF_SSIZE_T @SIZEOF_SSIZE_T@
|
||||||
|
|
||||||
|
/* Specifier for __thread */
|
||||||
|
#cmakedefine SPEC___THREAD @SPEC___THREAD@
|
||||||
|
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#cmakedefine STDC_HEADERS
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#define VERSION "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@"
|
||||||
|
|
||||||
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
|
#cmakedefine const
|
||||||
|
|
||||||
|
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||||
|
#cmakedefine size_t
|
||||||
2
cmake/json_config.h.in
Normal file
2
cmake/json_config.h.in
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#cmakedefine JSON_C_HAVE_INTTYPES_H @JSON_C_HAVE_INTTYPES_H@
|
||||||
174
config.h.in
174
config.h.in
@@ -1,174 +0,0 @@
|
|||||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
|
||||||
|
|
||||||
/* Enable RDRANR Hardware RNG Hash Seed */
|
|
||||||
#undef ENABLE_RDRAND
|
|
||||||
|
|
||||||
/* Define if .gnu.warning accepts long strings. */
|
|
||||||
#undef HAS_GNU_WARNING_LONG
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you
|
|
||||||
don't. */
|
|
||||||
#undef HAVE_DECL_INFINITY
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
|
|
||||||
*/
|
|
||||||
#undef HAVE_DECL_ISINF
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
|
|
||||||
*/
|
|
||||||
#undef HAVE_DECL_ISNAN
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */
|
|
||||||
#undef HAVE_DECL_NAN
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `_finite', and to 0 if you
|
|
||||||
don't. */
|
|
||||||
#undef HAVE_DECL__FINITE
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't.
|
|
||||||
*/
|
|
||||||
#undef HAVE_DECL__ISNAN
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
|
||||||
#undef HAVE_DLFCN_H
|
|
||||||
|
|
||||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
|
||||||
#undef HAVE_DOPRNT
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <endian.h> header file. */
|
|
||||||
#undef HAVE_ENDIAN_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
|
||||||
#undef HAVE_FCNTL_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
|
||||||
#undef HAVE_INTTYPES_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <limits.h> header file. */
|
|
||||||
#undef HAVE_LIMITS_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <locale.h> header file. */
|
|
||||||
#undef HAVE_LOCALE_H
|
|
||||||
|
|
||||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
|
||||||
to 0 otherwise. */
|
|
||||||
#undef HAVE_MALLOC
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <memory.h> header file. */
|
|
||||||
#undef HAVE_MEMORY_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `open' function. */
|
|
||||||
#undef HAVE_OPEN
|
|
||||||
|
|
||||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
|
||||||
and to 0 otherwise. */
|
|
||||||
#undef HAVE_REALLOC
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `setlocale' function. */
|
|
||||||
#undef HAVE_SETLOCALE
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `snprintf' function. */
|
|
||||||
#undef HAVE_SNPRINTF
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
|
||||||
#undef HAVE_STDARG_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdint.h> header file. */
|
|
||||||
#undef HAVE_STDINT_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
|
||||||
#undef HAVE_STDLIB_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `strcasecmp' function. */
|
|
||||||
#undef HAVE_STRCASECMP
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `strdup' function. */
|
|
||||||
#undef HAVE_STRDUP
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `strerror' function. */
|
|
||||||
#undef HAVE_STRERROR
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <strings.h> header file. */
|
|
||||||
#undef HAVE_STRINGS_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <string.h> header file. */
|
|
||||||
#undef HAVE_STRING_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `strncasecmp' function. */
|
|
||||||
#undef HAVE_STRNCASECMP
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <syslog.h> header file. */
|
|
||||||
#undef HAVE_SYSLOG_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/cdefs.h> header file. */
|
|
||||||
#undef HAVE_SYS_CDEFS_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
|
||||||
#undef HAVE_SYS_PARAM_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
|
||||||
#undef HAVE_SYS_STAT_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
|
||||||
#undef HAVE_SYS_TYPES_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
|
||||||
#undef HAVE_UNISTD_H
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `vasprintf' function. */
|
|
||||||
#undef HAVE_VASPRINTF
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `vprintf' function. */
|
|
||||||
#undef HAVE_VPRINTF
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `vsnprintf' function. */
|
|
||||||
#undef HAVE_VSNPRINTF
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `vsyslog' function. */
|
|
||||||
#undef HAVE_VSYSLOG
|
|
||||||
|
|
||||||
/* Public define for json_inttypes.h */
|
|
||||||
#undef JSON_C_HAVE_INTTYPES_H
|
|
||||||
|
|
||||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|
||||||
*/
|
|
||||||
#undef LT_OBJDIR
|
|
||||||
|
|
||||||
/* Name of package */
|
|
||||||
#undef PACKAGE
|
|
||||||
|
|
||||||
/* Define to the address where bug reports for this package should be sent. */
|
|
||||||
#undef PACKAGE_BUGREPORT
|
|
||||||
|
|
||||||
/* Define to the full name of this package. */
|
|
||||||
#undef PACKAGE_NAME
|
|
||||||
|
|
||||||
/* Define to the full name and version of this package. */
|
|
||||||
#undef PACKAGE_STRING
|
|
||||||
|
|
||||||
/* Define to the one symbol short name of this package. */
|
|
||||||
#undef PACKAGE_TARNAME
|
|
||||||
|
|
||||||
/* Define to the home page for this package. */
|
|
||||||
#undef PACKAGE_URL
|
|
||||||
|
|
||||||
/* Define to the version of this package. */
|
|
||||||
#undef PACKAGE_VERSION
|
|
||||||
|
|
||||||
/* Define to 1 if you have the ANSI C header files. */
|
|
||||||
#undef STDC_HEADERS
|
|
||||||
|
|
||||||
/* Version number of package */
|
|
||||||
#undef VERSION
|
|
||||||
|
|
||||||
/* Define to empty if `const' does not conform to ANSI C. */
|
|
||||||
#undef const
|
|
||||||
|
|
||||||
/* Define to rpl_malloc if the replacement function should be used. */
|
|
||||||
#undef malloc
|
|
||||||
|
|
||||||
/* Define to rpl_realloc if the replacement function should be used. */
|
|
||||||
#undef realloc
|
|
||||||
|
|
||||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
|
||||||
#undef size_t
|
|
||||||
169
config.h.win32
169
config.h.win32
@@ -1,26 +1,50 @@
|
|||||||
/*
|
|
||||||
* $Id: config.h.win32,v 1.2 2006/01/26 02:16:28 mclark Exp $
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
|
|
||||||
* Michael Clark <michael@metaparadigm.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the MIT license. See COPYING for details.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* config.h.win32 Generated by configure. */
|
|
||||||
|
|
||||||
#define PACKAGE_STRING "JSON C Library 0.2"
|
|
||||||
#define PACKAGE_BUGREPORT "json-c@googlegroups.com"
|
|
||||||
#define PACKAGE_NAME "JSON C Library"
|
|
||||||
#define PACKAGE_TARNAME "json-c"
|
|
||||||
#define PACKAGE_VERSION "0.2"
|
|
||||||
|
|
||||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
|
/* Enable RDRANR Hardware RNG Hash Seed */
|
||||||
|
#undef ENABLE_RDRAND
|
||||||
|
|
||||||
|
/* Define if .gnu.warning accepts long strings. */
|
||||||
|
#undef HAS_GNU_WARNING_LONG
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `INFINITY', and to 0 if you
|
||||||
|
don't. */
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__)
|
||||||
|
#define HAVE_DECL_INFINITY 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__)
|
||||||
|
#define HAVE_DECL_ISINF 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__)
|
||||||
|
#define HAVE_DECL_ISNAN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `nan', and to 0 if you don't. */
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(__MINGW32__)
|
||||||
|
#define HAVE_DECL_NAN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `_finite', and to 0 if you
|
||||||
|
don't. */
|
||||||
|
#define HAVE_DECL__FINITE 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the declaration of `_isnan', and to 0 if you don't.
|
||||||
|
*/
|
||||||
|
#define HAVE_DECL__ISNAN 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
|
#define HAVE_DLFCN_H 1
|
||||||
|
|
||||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||||
/* #undef HAVE_DOPRNT */
|
#define HAVE_DOPRNT 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <endian.h> header file. */
|
||||||
|
#undef HAVE_ENDIAN_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||||
#define HAVE_FCNTL_H 1
|
#define HAVE_FCNTL_H 1
|
||||||
@@ -31,6 +55,9 @@
|
|||||||
/* Define to 1 if you have the <limits.h> header file. */
|
/* Define to 1 if you have the <limits.h> header file. */
|
||||||
#define HAVE_LIMITS_H 1
|
#define HAVE_LIMITS_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <locale.h> header file. */
|
||||||
|
#define HAVE_LOCALE_H 1
|
||||||
|
|
||||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||||
to 0 otherwise. */
|
to 0 otherwise. */
|
||||||
#define HAVE_MALLOC 1
|
#define HAVE_MALLOC 1
|
||||||
@@ -39,23 +66,36 @@
|
|||||||
#define HAVE_MEMORY_H 1
|
#define HAVE_MEMORY_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `open' function. */
|
/* Define to 1 if you have the `open' function. */
|
||||||
#undef HAVE_OPEN
|
#define HAVE_OPEN 1
|
||||||
|
|
||||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||||
and to 0 otherwise. */
|
and to 0 otherwise. */
|
||||||
#define HAVE_REALLOC 1
|
#define HAVE_REALLOC 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `setlocale' function. */
|
||||||
|
#define HAVE_SETLOCALE 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `snprintf' function. */
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define HAVE_SNPRINTF 1
|
||||||
|
#else
|
||||||
|
#undef HAVE_SNPRINTF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||||
|
#define HAVE_STDARG_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdint.h> header file. */
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
#define HAVE_STDINT_H 1
|
#define HAVE_STDINT_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||||
#define HAVE_STDLIB_H 1
|
#define HAVE_STDLIB_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `strdup' function. */
|
/* Define to 1 if you have the `strcasecmp' function. */
|
||||||
#undef HAVE_STRNDUP
|
#define HAVE_STRCASECMP 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
/* Define to 1 if you have the `strdup' function. */
|
||||||
#define HAVE_STDARG_H 1
|
#define HAVE_STRDUP 0
|
||||||
|
|
||||||
/* Define to 1 if you have the `strerror' function. */
|
/* Define to 1 if you have the `strerror' function. */
|
||||||
#define HAVE_STRERROR 1
|
#define HAVE_STRERROR 1
|
||||||
@@ -66,11 +106,30 @@
|
|||||||
/* Define to 1 if you have the <string.h> header file. */
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
#define HAVE_STRING_H 1
|
#define HAVE_STRING_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strncasecmp' function. */
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define HAVE_STRNCASECMP 1
|
||||||
|
#else
|
||||||
|
#undef HAVE_STRNCASECMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#cmakedefine HAVE_STRTOLL
|
||||||
|
#cmakedefine strtoll @cmake_strtoll@
|
||||||
|
#cmakedefine HAVE_STRTOULL
|
||||||
|
#cmakedefine strtoull @cmake_strtoull@
|
||||||
|
|
||||||
/* Define to 1 if you have the <syslog.h> header file. */
|
/* Define to 1 if you have the <syslog.h> header file. */
|
||||||
#undef HAVE_SYSLOG_H
|
#undef HAVE_SYSLOG_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/cdefs.h> header file. */
|
||||||
|
#define HAVE_SYS_CDEFS_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define HAVE_SYS_PARAM_H 1
|
||||||
|
#else
|
||||||
#undef HAVE_SYS_PARAM_H
|
#undef HAVE_SYS_PARAM_H
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
#define HAVE_SYS_STAT_H 1
|
#define HAVE_SYS_STAT_H 1
|
||||||
@@ -79,16 +138,70 @@
|
|||||||
#define HAVE_SYS_TYPES_H 1
|
#define HAVE_SYS_TYPES_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <unistd.h> header file. */
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define HAVE_UNISTD_H 1
|
||||||
|
#else
|
||||||
#undef HAVE_UNISTD_H
|
#undef HAVE_UNISTD_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vasprintf' function. */
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#define HAVE_VASPRINTF 1
|
||||||
|
#else
|
||||||
|
#undef HAVE_VASPRINTF
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define to 1 if you have the `vprintf' function. */
|
/* Define to 1 if you have the `vprintf' function. */
|
||||||
#undef HAVE_VPRINTF
|
#define HAVE_VPRINTF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `vsnprintf' function. */
|
||||||
|
#define HAVE_VSNPRINTF 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `vsyslog' function. */
|
/* Define to 1 if you have the `vsyslog' function. */
|
||||||
#undef HAVE_VSYSLOG
|
#undef HAVE_VSYSLOG
|
||||||
|
|
||||||
/* Define to 1 if you have the `strncasecmp' function. */
|
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||||
#undef HAVE_STRNCASECMP
|
*/
|
||||||
|
#undef LT_OBJDIR
|
||||||
|
|
||||||
|
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||||
|
/* #undef NO_MINUS_C_MINUS_O */
|
||||||
|
|
||||||
|
/* Name of package */
|
||||||
|
#define PACKAGE "json-c"
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#define PACKAGE_BUGREPORT "json-c@googlegroups.com"
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#define PACKAGE_NAME "JSON C Library"
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#define PACKAGE_STRING "JSON C Library 0.14.99"
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#define PACKAGE_TARNAME "json-c"
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#define PACKAGE_URL "https://github.com/json-c/json-c"
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#define PACKAGE_VERSION "0.14.99"
|
||||||
|
|
||||||
/* Define to 1 if you have the ANSI C header files. */
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
#define STDC_HEADERS 1
|
#define STDC_HEADERS 1
|
||||||
|
|
||||||
|
/* Version number of package */
|
||||||
|
#define VERSION "0.14.99"
|
||||||
|
|
||||||
|
/* Define to empty if `const' does not conform to ANSI C. */
|
||||||
|
/* #undef const */
|
||||||
|
|
||||||
|
/* Define to rpl_malloc if the replacement function should be used. */
|
||||||
|
/* #undef malloc */
|
||||||
|
|
||||||
|
/* Define to rpl_realloc if the replacement function should be used. */
|
||||||
|
/* #undef realloc */
|
||||||
|
|
||||||
|
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||||
|
/* #undef size_t */
|
||||||
|
|||||||
107
configure.ac
107
configure.ac
@@ -1,107 +0,0 @@
|
|||||||
AC_PREREQ(2.52)
|
|
||||||
|
|
||||||
# Process this file with autoconf to produce a configure script.
|
|
||||||
AC_INIT([json-c], 0.11.99, [json-c@googlegroups.com])
|
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE
|
|
||||||
|
|
||||||
AC_PROG_MAKE_SET
|
|
||||||
|
|
||||||
AC_ARG_ENABLE(rdrand,
|
|
||||||
AS_HELP_STRING([--enable-rdrand],
|
|
||||||
[Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]),
|
|
||||||
[if test x$enableval = xyes; then
|
|
||||||
enable_rdrand=yes
|
|
||||||
AC_DEFINE(ENABLE_RDRAND, 1, [Enable RDRANR Hardware RNG Hash Seed])
|
|
||||||
fi])
|
|
||||||
|
|
||||||
if test "x$enable_rdrand" = "xyes"; then
|
|
||||||
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed enabled on supported x86/x64 platforms])
|
|
||||||
else
|
|
||||||
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable])
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checks for programs.
|
|
||||||
|
|
||||||
# Checks for libraries.
|
|
||||||
|
|
||||||
# Checks for header files.
|
|
||||||
AM_PROG_CC_C_O
|
|
||||||
AC_CONFIG_HEADER(config.h)
|
|
||||||
AC_CONFIG_HEADER(json_config.h)
|
|
||||||
AC_HEADER_STDC
|
|
||||||
AC_CHECK_HEADERS(fcntl.h limits.h strings.h syslog.h unistd.h [sys/cdefs.h] [sys/param.h] stdarg.h locale.h endian.h)
|
|
||||||
AC_CHECK_HEADER(inttypes.h,[AC_DEFINE([JSON_C_HAVE_INTTYPES_H],[1],[Public define for json_inttypes.h])])
|
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
|
||||||
AC_C_CONST
|
|
||||||
AC_TYPE_SIZE_T
|
|
||||||
|
|
||||||
# Checks for library functions.
|
|
||||||
AC_FUNC_VPRINTF
|
|
||||||
AC_FUNC_MEMCMP
|
|
||||||
AC_FUNC_MALLOC
|
|
||||||
AC_FUNC_REALLOC
|
|
||||||
AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale)
|
|
||||||
AC_CHECK_DECLS([INFINITY], [], [], [[#include <math.h>]])
|
|
||||||
AC_CHECK_DECLS([nan], [], [], [[#include <math.h>]])
|
|
||||||
AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]])
|
|
||||||
AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
|
|
||||||
AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
|
|
||||||
AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])
|
|
||||||
|
|
||||||
#check if .section.gnu.warning accepts long strings (for __warn_references)
|
|
||||||
AC_LANG_PUSH([C])
|
|
||||||
|
|
||||||
AC_MSG_CHECKING([if .gnu.warning accepts long strings])
|
|
||||||
AC_LINK_IFELSE([AC_LANG_SOURCE([[
|
|
||||||
extern void json_object_get();
|
|
||||||
__asm__(".section .gnu.json_object_get,\n\t.ascii \"Please link against libjson-c instead of libjson\"\n\t.text");
|
|
||||||
|
|
||||||
int main(int c,char* v) {return 0;}
|
|
||||||
]])], [
|
|
||||||
AC_DEFINE(HAS_GNU_WARNING_LONG, 1, [Define if .gnu.warning accepts long strings.])
|
|
||||||
AC_MSG_RESULT(yes)
|
|
||||||
], [
|
|
||||||
AC_MSG_RESULT(no)
|
|
||||||
])
|
|
||||||
|
|
||||||
AC_LANG_POP([C])
|
|
||||||
|
|
||||||
AM_PROG_LIBTOOL
|
|
||||||
|
|
||||||
# Check for the -Bsymbolic-functions linker flag
|
|
||||||
AC_ARG_ENABLE([Bsymbolic],
|
|
||||||
[AS_HELP_STRING([--disable-Bsymbolic], [Avoid linking with -Bsymbolic-function])],
|
|
||||||
[],
|
|
||||||
[enable_Bsymbolic=check])
|
|
||||||
|
|
||||||
AS_IF([test "x$enable_Bsymbolic" = "xcheck"],
|
|
||||||
[
|
|
||||||
saved_LDFLAGS="${LDFLAGS}"
|
|
||||||
AC_MSG_CHECKING([for -Bsymbolic-functions linker flag])
|
|
||||||
LDFLAGS=-Wl,-Bsymbolic-functions
|
|
||||||
AC_TRY_LINK([], [int main (void) { return 0; }],
|
|
||||||
[
|
|
||||||
AC_MSG_RESULT([yes])
|
|
||||||
enable_Bsymbolic=yes
|
|
||||||
],
|
|
||||||
[
|
|
||||||
AC_MSG_RESULT([no])
|
|
||||||
enable_Bsymbolic=no
|
|
||||||
])
|
|
||||||
LDFLAGS="${saved_LDFLAGS}"
|
|
||||||
])
|
|
||||||
|
|
||||||
AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
|
|
||||||
AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
|
||||||
Makefile
|
|
||||||
json-c.pc
|
|
||||||
tests/Makefile
|
|
||||||
json-c-uninstalled.pc
|
|
||||||
])
|
|
||||||
|
|
||||||
AC_OUTPUT
|
|
||||||
|
|
||||||
33
debug.c
33
debug.c
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#if HAVE_SYSLOG_H
|
#if HAVE_SYSLOG_H
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
@@ -33,8 +33,14 @@
|
|||||||
static int _syslog = 0;
|
static int _syslog = 0;
|
||||||
static int _debug = 0;
|
static int _debug = 0;
|
||||||
|
|
||||||
void mc_set_debug(int debug) { _debug = debug; }
|
void mc_set_debug(int debug)
|
||||||
int mc_get_debug(void) { return _debug; }
|
{
|
||||||
|
_debug = debug;
|
||||||
|
}
|
||||||
|
int mc_get_debug(void)
|
||||||
|
{
|
||||||
|
return _debug;
|
||||||
|
}
|
||||||
|
|
||||||
extern void mc_set_syslog(int syslog)
|
extern void mc_set_syslog(int syslog)
|
||||||
{
|
{
|
||||||
@@ -44,12 +50,15 @@ extern void mc_set_syslog(int syslog)
|
|||||||
void mc_debug(const char *msg, ...)
|
void mc_debug(const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
if(_debug) {
|
if (_debug)
|
||||||
|
{
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
#if HAVE_VSYSLOG
|
#if HAVE_VSYSLOG
|
||||||
if(_syslog) {
|
if (_syslog)
|
||||||
|
{
|
||||||
vsyslog(LOG_DEBUG, msg, ap);
|
vsyslog(LOG_DEBUG, msg, ap);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
vprintf(msg, ap);
|
vprintf(msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@@ -61,9 +70,11 @@ void mc_error(const char *msg, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
#if HAVE_VSYSLOG
|
#if HAVE_VSYSLOG
|
||||||
if(_syslog) {
|
if (_syslog)
|
||||||
|
{
|
||||||
vsyslog(LOG_ERR, msg, ap);
|
vsyslog(LOG_ERR, msg, ap);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
vfprintf(stderr, msg, ap);
|
vfprintf(stderr, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@@ -74,9 +85,11 @@ void mc_info(const char *msg, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
#if HAVE_VSYSLOG
|
#if HAVE_VSYSLOG
|
||||||
if(_syslog) {
|
if (_syslog)
|
||||||
|
{
|
||||||
vsyslog(LOG_INFO, msg, ap);
|
vsyslog(LOG_INFO, msg, ap);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
vfprintf(stderr, msg, ap);
|
vfprintf(stderr, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|||||||
55
debug.h
55
debug.h
@@ -10,6 +10,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
#ifndef _DEBUG_H_
|
#ifndef _DEBUG_H_
|
||||||
#define _DEBUG_H_
|
#define _DEBUG_H_
|
||||||
|
|
||||||
@@ -19,14 +23,22 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void mc_set_debug(int debug);
|
#ifndef JSON_EXPORT
|
||||||
extern int mc_get_debug(void);
|
#if defined(_MSC_VER)
|
||||||
|
#define JSON_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JSON_EXPORT extern
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void mc_set_syslog(int syslog);
|
JSON_EXPORT void mc_set_debug(int debug);
|
||||||
|
JSON_EXPORT int mc_get_debug(void);
|
||||||
|
|
||||||
extern void mc_debug(const char *msg, ...);
|
JSON_EXPORT void mc_set_syslog(int syslog);
|
||||||
extern void mc_error(const char *msg, ...);
|
|
||||||
extern void mc_info(const char *msg, ...);
|
JSON_EXPORT void mc_debug(const char *msg, ...);
|
||||||
|
JSON_EXPORT void mc_error(const char *msg, ...);
|
||||||
|
JSON_EXPORT void mc_info(const char *msg, ...);
|
||||||
|
|
||||||
#ifndef __STRING
|
#ifndef __STRING
|
||||||
#define __STRING(x) #x
|
#define __STRING(x) #x
|
||||||
@@ -34,13 +46,20 @@ extern void mc_info(const char *msg, ...);
|
|||||||
|
|
||||||
#ifndef PARSER_BROKEN_FIXED
|
#ifndef PARSER_BROKEN_FIXED
|
||||||
|
|
||||||
#define JASSERT(cond) do {} while(0)
|
#define JASSERT(cond) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define JASSERT(cond) do { \
|
#define JASSERT(cond) \
|
||||||
if (!(cond)) { \
|
do \
|
||||||
mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
|
{ \
|
||||||
|
if (!(cond)) \
|
||||||
|
{ \
|
||||||
|
mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
*(int *)0 = 1; \
|
*(int *)0 = 1; \
|
||||||
abort(); \
|
abort(); \
|
||||||
} \
|
} \
|
||||||
@@ -57,11 +76,19 @@ extern void mc_info(const char *msg, ...);
|
|||||||
#define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
|
#define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
|
||||||
#define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
|
#define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
|
#define MC_SET_DEBUG(x) \
|
||||||
|
if (0) \
|
||||||
|
mc_set_debug(x)
|
||||||
#define MC_GET_DEBUG() (0)
|
#define MC_GET_DEBUG() (0)
|
||||||
#define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
|
#define MC_SET_SYSLOG(x) \
|
||||||
#define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
|
if (0) \
|
||||||
#define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
|
mc_set_syslog(x)
|
||||||
|
#define MC_DEBUG(x, ...) \
|
||||||
|
if (0) \
|
||||||
|
mc_debug(x, ##__VA_ARGS__)
|
||||||
|
#define MC_INFO(x, ...) \
|
||||||
|
if (0) \
|
||||||
|
mc_info(x, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
16
doc/CMakeLists.txt
Normal file
16
doc/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# generate doxygen documentation for json-c API
|
||||||
|
|
||||||
|
find_package(Doxygen)
|
||||||
|
|
||||||
|
if (DOXYGEN_FOUND)
|
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
message(STATUS "Wrote ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
|
||||||
|
|
||||||
|
add_custom_target(doc
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
|
else (DOXYGEN_FOUND)
|
||||||
|
message("Warning: doxygen not found, the 'doc' target will not be included")
|
||||||
|
endif(DOXYGEN_FOUND)
|
||||||
2353
doc/Doxyfile.in
Normal file
2353
doc/Doxyfile.in
Normal file
File diff suppressed because it is too large
Load Diff
6
fuzz/README.md
Normal file
6
fuzz/README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Fuzzers
|
||||||
|
|
||||||
|
This directory contains fuzzers that
|
||||||
|
target [llvm's LibFuzzer](https://llvm.org/docs/LibFuzzer.html). They are built
|
||||||
|
and run automatically by
|
||||||
|
Google's [OSS-Fuzz](https://github.com/google/oss-fuzz/) infrastructure.
|
||||||
52
fuzz/build.sh
Executable file
52
fuzz/build.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash -eu
|
||||||
|
# Copyright 2018 Google Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# This should be run from the top of the json-c source tree.
|
||||||
|
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DBUILD_SHARED_LIBS=OFF ..
|
||||||
|
make -j$(nproc)
|
||||||
|
|
||||||
|
LIB=$(pwd)/libjson-c.a
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# These seem to be set externally, but let's assign defaults to
|
||||||
|
# make it possible to at least partially test this standalone.
|
||||||
|
: ${SRC:=$(dirname "$0")}
|
||||||
|
: ${OUT:=$SRC/out}
|
||||||
|
: ${CXX:=gcc}
|
||||||
|
: ${CXXFLAGS:=}
|
||||||
|
|
||||||
|
[ -d "$OUT" ] || mkdir "$OUT"
|
||||||
|
cp $SRC/*.dict $OUT/.
|
||||||
|
|
||||||
|
# XXX this doesn't seem to make much sense, since $SRC is presumably
|
||||||
|
# the "fuzz" directory, which is _inside_ the json-c repo, rather than
|
||||||
|
# the other way around, but I'm just preserving existing behavior. -erh
|
||||||
|
INCS=$SRC/json-c
|
||||||
|
# Compat when testing standalone
|
||||||
|
[ -e "${INCS}" ] || ln -s .. "${INCS}"
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -v
|
||||||
|
for f in $SRC/*_fuzzer.cc; do
|
||||||
|
fuzzer=$(basename "$f" _fuzzer.cc)
|
||||||
|
$CXX $CXXFLAGS -std=c++11 -I$INCS \
|
||||||
|
$SRC/${fuzzer}_fuzzer.cc -o $OUT/${fuzzer}_fuzzer \
|
||||||
|
-lFuzzingEngine $LIB
|
||||||
|
done
|
||||||
14
fuzz/tokener_parse_ex_fuzzer.cc
Normal file
14
fuzz/tokener_parse_ex_fuzzer.cc
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
|
{
|
||||||
|
const char *data1 = reinterpret_cast<const char *>(data);
|
||||||
|
json_tokener *tok = json_tokener_new();
|
||||||
|
json_object *obj = json_tokener_parse_ex(tok, data1, size);
|
||||||
|
|
||||||
|
json_object_put(obj);
|
||||||
|
json_tokener_free(tok);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
18
fuzz/tokener_parse_ex_fuzzer.dict
Normal file
18
fuzz/tokener_parse_ex_fuzzer.dict
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
","
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
","
|
||||||
|
":"
|
||||||
|
"e"
|
||||||
|
"e+"
|
||||||
|
"e-"
|
||||||
|
"E"
|
||||||
|
"E+"
|
||||||
|
"E-"
|
||||||
|
"\""
|
||||||
|
"null"
|
||||||
|
"1"
|
||||||
|
"1.234"
|
||||||
|
"3e4"
|
||||||
270
issues_closed_for_0.13.md
Normal file
270
issues_closed_for_0.13.md
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
|
||||||
|
This list was created with:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=1" > issues1.out
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=2" > issues2.out
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2014-04-10+created%3A<2017-12-01&sort=created&order=asc&per_page=400&page=3" > issues3.out
|
||||||
|
jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md
|
||||||
|
sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md
|
||||||
|
#... manual editing ...
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Issues and Pull Requests closed for the 0.13 release
|
||||||
|
(since commit f84d9c, the 0.12 branch point, 2014-04-10)
|
||||||
|
|
||||||
|
|
||||||
|
[Issue #61](https://github.com/json-c/json-c/issues/61) - Make json_object_object_add() indicate success or failure, test fix \
|
||||||
|
[Issue #113](https://github.com/json-c/json-c/issues/113) - Build fixes (make dist and make distcheck) \
|
||||||
|
[Issue #124](https://github.com/json-c/json-c/issues/124) - Fixing build \
|
||||||
|
[Issue #125](https://github.com/json-c/json-c/issues/125) - Fix compile error(variable size set but not used) on g++4.6 \
|
||||||
|
[Issue #126](https://github.com/json-c/json-c/issues/126) - Removed unused size variable. \
|
||||||
|
[Issue #127](https://github.com/json-c/json-c/issues/127) - remove unused `size` variable \
|
||||||
|
[Issue #128](https://github.com/json-c/json-c/issues/128) - Remove unused variable from json_tokenizer.c \
|
||||||
|
[Issue #130](https://github.com/json-c/json-c/issues/130) - Failed to compile under Ubuntu 13.10 32bit \
|
||||||
|
[Issue #131](https://github.com/json-c/json-c/issues/131) - undefined symbol: __sync_val_compare_and_swap_4 \
|
||||||
|
[Issue #132](https://github.com/json-c/json-c/issues/132) - Remove unused variable 'size' \
|
||||||
|
[Issue #133](https://github.com/json-c/json-c/issues/133) - Update and rename README to README.md \
|
||||||
|
[Issue #134](https://github.com/json-c/json-c/issues/134) - Must remove variable size... \
|
||||||
|
[Issue #135](https://github.com/json-c/json-c/issues/135) - bits.h uses removed json_tokener_errors\[error\] \
|
||||||
|
[Issue #136](https://github.com/json-c/json-c/issues/136) - Error when running make check \
|
||||||
|
[Issue #137](https://github.com/json-c/json-c/issues/137) - config.h.in should not be in git \
|
||||||
|
[Issue #138](https://github.com/json-c/json-c/issues/138) - Can't build on RHEL 6.5 due to dependency on automake-1.14 \
|
||||||
|
[Issue #140](https://github.com/json-c/json-c/issues/140) - Code bug in random_test.c evaluating same expression twice \
|
||||||
|
[Issue #141](https://github.com/json-c/json-c/issues/141) - Removed duplicate check in random_seed test - bug #140 \
|
||||||
|
[Issue #142](https://github.com/json-c/json-c/issues/142) - Please undeprecate json_object_object_get \
|
||||||
|
[Issue #144](https://github.com/json-c/json-c/issues/144) - Introduce json_object_from_fd \
|
||||||
|
[Issue #145](https://github.com/json-c/json-c/issues/145) - Handle % character properly \
|
||||||
|
[Issue #146](https://github.com/json-c/json-c/issues/146) - TAGS rename \
|
||||||
|
[Issue #148](https://github.com/json-c/json-c/issues/148) - Bump the soname \
|
||||||
|
[Issue #149](https://github.com/json-c/json-c/issues/149) - SONAME bump \
|
||||||
|
[Issue #150](https://github.com/json-c/json-c/issues/150) - Fix build using MinGW. \
|
||||||
|
[Issue #151](https://github.com/json-c/json-c/issues/151) - Remove json_type enum trailing comma \
|
||||||
|
[Issue #152](https://github.com/json-c/json-c/issues/152) - error while compiling json-c library version 0.11 \
|
||||||
|
[Issue #153](https://github.com/json-c/json-c/issues/153) - improve doc for json_object_to_json_string() \
|
||||||
|
[Issue #154](https://github.com/json-c/json-c/issues/154) - double precision \
|
||||||
|
[Issue #155](https://github.com/json-c/json-c/issues/155) - add bsearch for arrays \
|
||||||
|
[Issue #156](https://github.com/json-c/json-c/issues/156) - Remove trailing whitespaces \
|
||||||
|
[Issue #157](https://github.com/json-c/json-c/issues/157) - JSON-C shall not exit on calloc fail. \
|
||||||
|
[Issue #158](https://github.com/json-c/json-c/issues/158) - while using json-c 0.11, I am facing strange crash issue in json_object_put. \
|
||||||
|
[Issue #159](https://github.com/json-c/json-c/issues/159) - json_tokener.c compile error \
|
||||||
|
[Issue #160](https://github.com/json-c/json-c/issues/160) - missing header file on windows?? \
|
||||||
|
[Issue #161](https://github.com/json-c/json-c/issues/161) - Is there a way to append to file? \
|
||||||
|
[Issue #162](https://github.com/json-c/json-c/issues/162) - json_util: add directory check for POSIX distros \
|
||||||
|
[Issue #163](https://github.com/json-c/json-c/issues/163) - Fix Win32 build problems \
|
||||||
|
[Issue #164](https://github.com/json-c/json-c/issues/164) - made it compile and link on Widnows (as static library) \
|
||||||
|
[Issue #165](https://github.com/json-c/json-c/issues/165) - json_object_to_json_string_ext length \
|
||||||
|
[Issue #167](https://github.com/json-c/json-c/issues/167) - Can't build on Windows with Visual Studio 2010 \
|
||||||
|
[Issue #168](https://github.com/json-c/json-c/issues/168) - Tightening the number parsing algorithm \
|
||||||
|
[Issue #169](https://github.com/json-c/json-c/issues/169) - Doesn't compile on ubuntu 14.04, 64bit \
|
||||||
|
[Issue #170](https://github.com/json-c/json-c/issues/170) - Generated files in repository \
|
||||||
|
[Issue #171](https://github.com/json-c/json-c/issues/171) - Update configuration for VS2010 and win64 \
|
||||||
|
[Issue #172](https://github.com/json-c/json-c/issues/172) - Adding support for parsing octal numbers \
|
||||||
|
[Issue #173](https://github.com/json-c/json-c/issues/173) - json_parse_int64 doesn't work correctly at illumos \
|
||||||
|
[Issue #174](https://github.com/json-c/json-c/issues/174) - Adding JSON_C_TO_STRING_PRETTY_TAB flag \
|
||||||
|
[Issue #175](https://github.com/json-c/json-c/issues/175) - make check fails 4 tests with overflows when built with ASAN \
|
||||||
|
[Issue #176](https://github.com/json-c/json-c/issues/176) - Possible to delete an array element at a given idx ? \
|
||||||
|
[Issue #177](https://github.com/json-c/json-c/issues/177) - Fix compiler warnings \
|
||||||
|
[Issue #178](https://github.com/json-c/json-c/issues/178) - Unable to compile on CentOS5 \
|
||||||
|
[Issue #179](https://github.com/json-c/json-c/issues/179) - Added array_list_del_idx and json_object_array_del_idx \
|
||||||
|
[Issue #180](https://github.com/json-c/json-c/issues/180) - Enable silent build by default \
|
||||||
|
[Issue #181](https://github.com/json-c/json-c/issues/181) - json_tokener_parse_ex accepts invalid JSON \
|
||||||
|
[Issue #182](https://github.com/json-c/json-c/issues/182) - Link against libm when needed \
|
||||||
|
[Issue #183](https://github.com/json-c/json-c/issues/183) - Apply compile warning fix to master branch \
|
||||||
|
[Issue #184](https://github.com/json-c/json-c/issues/184) - Use only GCC-specific flags when compiling with GCC \
|
||||||
|
[Issue #185](https://github.com/json-c/json-c/issues/185) - compile error \
|
||||||
|
[Issue #186](https://github.com/json-c/json-c/issues/186) - Syntax error \
|
||||||
|
[Issue #187](https://github.com/json-c/json-c/issues/187) - array_list_get_idx and negative indexes. \
|
||||||
|
[Issue #188](https://github.com/json-c/json-c/issues/188) - json_object_object_foreach warnings \
|
||||||
|
[Issue #189](https://github.com/json-c/json-c/issues/189) - noisy json_object_from_file: error opening file \
|
||||||
|
[Issue #190](https://github.com/json-c/json-c/issues/190) - warning: initialization discards const qualifier from pointer target type \[enabled by default\] \
|
||||||
|
[Issue #192](https://github.com/json-c/json-c/issues/192) - json_tokener_parse accepts invalid JSON {"key": "value" , } \
|
||||||
|
[Issue #193](https://github.com/json-c/json-c/issues/193) - Make serialization format of doubles configurable \
|
||||||
|
[Issue #194](https://github.com/json-c/json-c/issues/194) - Add utility function for comparing json_objects \
|
||||||
|
[Issue #195](https://github.com/json-c/json-c/issues/195) - Call uselocale instead of setlocale \
|
||||||
|
[Issue #196](https://github.com/json-c/json-c/issues/196) - Performance improvements \
|
||||||
|
[Issue #197](https://github.com/json-c/json-c/issues/197) - Time for a new release? \
|
||||||
|
[Issue #198](https://github.com/json-c/json-c/issues/198) - Fix possible memory leak and remove superfluous NULL checks before free() \
|
||||||
|
[Issue #199](https://github.com/json-c/json-c/issues/199) - Fix build in Visual Studio \
|
||||||
|
[Issue #200](https://github.com/json-c/json-c/issues/200) - Add build scripts for CI platforms \
|
||||||
|
[Issue #201](https://github.com/json-c/json-c/issues/201) - disable forward-slash escaping? \
|
||||||
|
[Issue #202](https://github.com/json-c/json-c/issues/202) - Array with objects support \
|
||||||
|
[Issue #203](https://github.com/json-c/json-c/issues/203) - Add source position/coordinates to API \
|
||||||
|
[Issue #204](https://github.com/json-c/json-c/issues/204) - json-c/json.h not found \
|
||||||
|
[Issue #205](https://github.com/json-c/json-c/issues/205) - json-c Compiled with Visual Studios \
|
||||||
|
[Issue #206](https://github.com/json-c/json-c/issues/206) - what do i use in place of json_object_object_get? \
|
||||||
|
[Issue #207](https://github.com/json-c/json-c/issues/207) - Add support for property pairs directly added to arrays \
|
||||||
|
[Issue #208](https://github.com/json-c/json-c/issues/208) - Performance enhancements (mainly) to json_object_to_json_string() \
|
||||||
|
[Issue #209](https://github.com/json-c/json-c/issues/209) - fix regression from 2d549662be832da838aa063da2efa78ee3b99668 \
|
||||||
|
[Issue #210](https://github.com/json-c/json-c/issues/210) - Use size_t for arrays \
|
||||||
|
[Issue #211](https://github.com/json-c/json-c/issues/211) - Atomic updates for the refcount \
|
||||||
|
[Issue #212](https://github.com/json-c/json-c/issues/212) - Refcount doesn't work between threads \
|
||||||
|
[Issue #213](https://github.com/json-c/json-c/issues/213) - fix to compile with microsoft visual c++ 2010 \
|
||||||
|
[Issue #214](https://github.com/json-c/json-c/issues/214) - Some non-GNU systems support __sync_val_compare_and_swap \
|
||||||
|
[Issue #215](https://github.com/json-c/json-c/issues/215) - Build json-c for window 64 bit. \
|
||||||
|
[Issue #216](https://github.com/json-c/json-c/issues/216) - configure: check realloc with AC_CHECK_FUNCS() to fix cross-compilation. \
|
||||||
|
[Issue #217](https://github.com/json-c/json-c/issues/217) - Checking for functions in float.h \
|
||||||
|
[Issue #218](https://github.com/json-c/json-c/issues/218) - Use a macro to indicate C99 to the compiler \
|
||||||
|
[Issue #219](https://github.com/json-c/json-c/issues/219) - Fix various potential null ptr deref and int32 overflows \
|
||||||
|
[Issue #220](https://github.com/json-c/json-c/issues/220) - Add utility function for comparing json_objects \
|
||||||
|
[Issue #221](https://github.com/json-c/json-c/issues/221) - JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly \
|
||||||
|
[Issue #222](https://github.com/json-c/json-c/issues/222) - Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly \
|
||||||
|
[Issue #223](https://github.com/json-c/json-c/issues/223) - Clarify json_object_get_string documentation of NULL handling & return \
|
||||||
|
[Issue #224](https://github.com/json-c/json-c/issues/224) - json_tokener.c - all warnings being treated as errors \
|
||||||
|
[Issue #225](https://github.com/json-c/json-c/issues/225) - Hi, will you support clib as a "registry"? \
|
||||||
|
[Issue #227](https://github.com/json-c/json-c/issues/227) - Bump SOVERSION to 3 \
|
||||||
|
[Issue #228](https://github.com/json-c/json-c/issues/228) - avoid double slashes from json \
|
||||||
|
[Issue #229](https://github.com/json-c/json-c/issues/229) - configure fails: checking size of size_t... configure: error: cannot determine a size for size_t \
|
||||||
|
[Issue #230](https://github.com/json-c/json-c/issues/230) - Use stdint.h to check for size_t size \
|
||||||
|
[Issue #231](https://github.com/json-c/json-c/issues/231) - Fix size_t size check for first-time builds \
|
||||||
|
[Issue #232](https://github.com/json-c/json-c/issues/232) - tests/tests1: fix printf format for size_t arguments \
|
||||||
|
[Issue #233](https://github.com/json-c/json-c/issues/233) - Include stddef.h in json_object.h \
|
||||||
|
[Issue #234](https://github.com/json-c/json-c/issues/234) - Add public API to use userdata independently of custom serializer \
|
||||||
|
[Issue #235](https://github.com/json-c/json-c/issues/235) - Undefined symbols Error for architecture x86_64 on Mac \
|
||||||
|
[Issue #236](https://github.com/json-c/json-c/issues/236) - Building a project which uses json-c with flag -Wcast-qual causes compilation errors \
|
||||||
|
[Issue #237](https://github.com/json-c/json-c/issues/237) - handle escaped utf-8 \
|
||||||
|
[Issue #238](https://github.com/json-c/json-c/issues/238) - linkhash.c: optimised the table_free path \
|
||||||
|
[Issue #239](https://github.com/json-c/json-c/issues/239) - initialize null terminator of new printbuf \
|
||||||
|
[Issue #240](https://github.com/json-c/json-c/issues/240) - Compile error: Variable set but not used \
|
||||||
|
[Issue #241](https://github.com/json-c/json-c/issues/241) - getting error in date string 19\/07\/2016, fixed for error 19/07/2016 \
|
||||||
|
[Issue #242](https://github.com/json-c/json-c/issues/242) - json_tokener_parse error \
|
||||||
|
[Issue #243](https://github.com/json-c/json-c/issues/243) - Fix #165 \
|
||||||
|
[Issue #244](https://github.com/json-c/json-c/issues/244) - Error while compiling source from RHEL5, could you please help me to fix this \
|
||||||
|
[Issue #245](https://github.com/json-c/json-c/issues/245) - json-c compile in window xp \
|
||||||
|
[Issue #246](https://github.com/json-c/json-c/issues/246) - Mac: uselocale failed to build \
|
||||||
|
[Issue #247](https://github.com/json-c/json-c/issues/247) - json_object_array_del_idx function has segment fault error? \
|
||||||
|
[Issue #248](https://github.com/json-c/json-c/issues/248) - Minor changes in C source code \
|
||||||
|
[Issue #249](https://github.com/json-c/json-c/issues/249) - Improving README \
|
||||||
|
[Issue #250](https://github.com/json-c/json-c/issues/250) - Improving .gitignore \
|
||||||
|
[Issue #251](https://github.com/json-c/json-c/issues/251) - Adding a file for EditorConfig \
|
||||||
|
[Issue #252](https://github.com/json-c/json-c/issues/252) - Very minor changes not related to C source code \
|
||||||
|
[Issue #253](https://github.com/json-c/json-c/issues/253) - Adding a test with cppcheck for Travis CI \
|
||||||
|
[Issue #254](https://github.com/json-c/json-c/issues/254) - Very minor changes to some tests \
|
||||||
|
[Issue #255](https://github.com/json-c/json-c/issues/255) - Minor changes in C source code \
|
||||||
|
[Issue #256](https://github.com/json-c/json-c/issues/256) - Mailing list dead? \
|
||||||
|
[Issue #257](https://github.com/json-c/json-c/issues/257) - Defining a coding style \
|
||||||
|
[Issue #258](https://github.com/json-c/json-c/issues/258) - Enable CI services \
|
||||||
|
[Issue #259](https://github.com/json-c/json-c/issues/259) - Fails to parse valid json \
|
||||||
|
[Issue #260](https://github.com/json-c/json-c/issues/260) - Adding an object to itself \
|
||||||
|
[Issue #261](https://github.com/json-c/json-c/issues/261) - Lack of proper documentation \
|
||||||
|
[Issue #262](https://github.com/json-c/json-c/issues/262) - Add Cmakefile and fix compiler warning. \
|
||||||
|
[Issue #263](https://github.com/json-c/json-c/issues/263) - Compiler Warnings with VS2015 \
|
||||||
|
[Issue #264](https://github.com/json-c/json-c/issues/264) - successed in simple test while failed in my project \
|
||||||
|
[Issue #265](https://github.com/json-c/json-c/issues/265) - Conformance report for reference \
|
||||||
|
[Issue #266](https://github.com/json-c/json-c/issues/266) - crash perhaps related to reference counting \
|
||||||
|
[Issue #267](https://github.com/json-c/json-c/issues/267) - Removes me as Win32 maintainer, because I'm not. \
|
||||||
|
[Issue #268](https://github.com/json-c/json-c/issues/268) - Documentation of json_object_to_json_string gives no information about memory management \
|
||||||
|
[Issue #269](https://github.com/json-c/json-c/issues/269) - json_object_<type>_set(json_object *o,<type> value) API for value setting in json object private structure \
|
||||||
|
[Issue #270](https://github.com/json-c/json-c/issues/270) - new API json_object_new_double_f(doubel d,const char * fmt); \
|
||||||
|
[Issue #271](https://github.com/json-c/json-c/issues/271) - Cannot compile using CMake on macOS \
|
||||||
|
[Issue #273](https://github.com/json-c/json-c/issues/273) - fixed wrong object name in json_object_all_values_equal \
|
||||||
|
[Issue #274](https://github.com/json-c/json-c/issues/274) - Support for 64 bit pointers on Windows \
|
||||||
|
[Issue #275](https://github.com/json-c/json-c/issues/275) - Out-of-bounds read in json_tokener_parse_ex \
|
||||||
|
[Issue #276](https://github.com/json-c/json-c/issues/276) - ./configure for centos release 6.7(final) failure \
|
||||||
|
[Issue #277](https://github.com/json-c/json-c/issues/277) - Json object set xxx \
|
||||||
|
[Issue #278](https://github.com/json-c/json-c/issues/278) - Serialization of double with no fractional component drops trailing zero \
|
||||||
|
[Issue #279](https://github.com/json-c/json-c/issues/279) - Segmentation fault in array_list_length() \
|
||||||
|
[Issue #280](https://github.com/json-c/json-c/issues/280) - Should json_object_array_get_idx check whether input obj is array? \
|
||||||
|
[Issue #281](https://github.com/json-c/json-c/issues/281) - how to pretty print json-c? \
|
||||||
|
[Issue #282](https://github.com/json-c/json-c/issues/282) - ignore temporary files \
|
||||||
|
[Issue #283](https://github.com/json-c/json-c/issues/283) - json_pointer: add first revision based on RFC 6901 \
|
||||||
|
[Issue #284](https://github.com/json-c/json-c/issues/284) - Resusing json_tokener object \
|
||||||
|
[Issue #285](https://github.com/json-c/json-c/issues/285) - Revert "compat/strdup.h: move common compat check for strdup() to own \
|
||||||
|
[Issue #286](https://github.com/json-c/json-c/issues/286) - json_tokener_parse_ex() returns json_tokener_continue on zero-length string \
|
||||||
|
[Issue #287](https://github.com/json-c/json-c/issues/287) - json_pointer: extend setter & getter with printf() style arguments \
|
||||||
|
[Issue #288](https://github.com/json-c/json-c/issues/288) - Fix _GNU_SOURCE define for vasprintf \
|
||||||
|
[Issue #289](https://github.com/json-c/json-c/issues/289) - bugfix: floating point representaion without fractional part \
|
||||||
|
[Issue #290](https://github.com/json-c/json-c/issues/290) - duplicate an json_object \
|
||||||
|
[Issue #291](https://github.com/json-c/json-c/issues/291) - isspace assert error \
|
||||||
|
[Issue #292](https://github.com/json-c/json-c/issues/292) - configure error "./configure: line 13121: syntax error near unexpected token `-Wall'" \
|
||||||
|
[Issue #293](https://github.com/json-c/json-c/issues/293) - how to make with bitcode for ios \
|
||||||
|
[Issue #294](https://github.com/json-c/json-c/issues/294) - Adding UTF-8 validation. Fixes #122 \
|
||||||
|
[Issue #295](https://github.com/json-c/json-c/issues/295) - cross compile w/ mingw \
|
||||||
|
[Issue #296](https://github.com/json-c/json-c/issues/296) - Missing functions header in json_object.h \
|
||||||
|
[Issue #297](https://github.com/json-c/json-c/issues/297) - could not parse string to Json object? Like string str=\"helloworld;E\\test\\log\\;end\" \
|
||||||
|
[Issue #298](https://github.com/json-c/json-c/issues/298) - Building using CMake doesn't work \
|
||||||
|
[Issue #299](https://github.com/json-c/json-c/issues/299) - Improve json_object -> string performance \
|
||||||
|
[Issue #300](https://github.com/json-c/json-c/issues/300) - Running tests with MinGW build \
|
||||||
|
[Issue #301](https://github.com/json-c/json-c/issues/301) - How to deep copy json_object in C++ ? \
|
||||||
|
[Issue #302](https://github.com/json-c/json-c/issues/302) - json_tokener_parse_ex doesn't parse JSON values \
|
||||||
|
[Issue #303](https://github.com/json-c/json-c/issues/303) - fix doc in tokener header file \
|
||||||
|
[Issue #304](https://github.com/json-c/json-c/issues/304) - (.text+0x72846): undefined reference to `is_error' \
|
||||||
|
[Issue #305](https://github.com/json-c/json-c/issues/305) - Fix compilation without C-99 option \
|
||||||
|
[Issue #306](https://github.com/json-c/json-c/issues/306) - ./configure: line 12748 -error=deprecated-declarations \
|
||||||
|
[Issue #307](https://github.com/json-c/json-c/issues/307) - Memory leak in json_tokener_parse \
|
||||||
|
[Issue #308](https://github.com/json-c/json-c/issues/308) - AM_PROG_LIBTOOL not found on Linux \
|
||||||
|
[Issue #309](https://github.com/json-c/json-c/issues/309) - GCC 7 reports various -Wimplicit-fallthrough= errors \
|
||||||
|
[Issue #310](https://github.com/json-c/json-c/issues/310) - Add FALLTHRU comment to handle GCC7 warnings. \
|
||||||
|
[Issue #311](https://github.com/json-c/json-c/issues/311) - Fix error C3688 when compiling on Visual Studio 2015 \
|
||||||
|
[Issue #312](https://github.com/json-c/json-c/issues/312) - Fix CMake Build process improved for MinGW and MSYS2 \
|
||||||
|
[Issue #313](https://github.com/json-c/json-c/issues/313) - VERBOSE=1 make check; tests/test_util_file.test.c and tests/test_util_file.expected out of sync \
|
||||||
|
[Issue #315](https://github.com/json-c/json-c/issues/315) - Passing -1 to json_tokener_parse_ex is possibly unsafe \
|
||||||
|
[Issue #316](https://github.com/json-c/json-c/issues/316) - Memory Returned by json_object_to_json_string not freed \
|
||||||
|
[Issue #317](https://github.com/json-c/json-c/issues/317) - json_object_get_string gives segmentation error \
|
||||||
|
[Issue #318](https://github.com/json-c/json-c/issues/318) - PVS-Studio static analyzer analyze results \
|
||||||
|
[Issue #319](https://github.com/json-c/json-c/issues/319) - Windows: Fix dynamic library build with Visual Studio \
|
||||||
|
[Issue #320](https://github.com/json-c/json-c/issues/320) - Can't compile in Mac OS X El Capitan \
|
||||||
|
[Issue #321](https://github.com/json-c/json-c/issues/321) - build,cmake: fix vasprintf implicit definition and generate both static & shared libs \
|
||||||
|
[Issue #322](https://github.com/json-c/json-c/issues/322) - can not link with libjson-c.a \
|
||||||
|
[Issue #323](https://github.com/json-c/json-c/issues/323) - implicit fallthrough detected by gcc 7.1 \
|
||||||
|
[Issue #324](https://github.com/json-c/json-c/issues/324) - JsonPath like function? \
|
||||||
|
[Issue #325](https://github.com/json-c/json-c/issues/325) - Fix stack buffer overflow in json_object_double_to_json_string_format() \
|
||||||
|
[Issue #327](https://github.com/json-c/json-c/issues/327) - why json-c so hard to compile \
|
||||||
|
[Issue #328](https://github.com/json-c/json-c/issues/328) - json_object: implement json_object_deep_copy() function \
|
||||||
|
[Issue #329](https://github.com/json-c/json-c/issues/329) - build,cmake: build,cmake: rename libjson-c-static.a to libjson-c.a \
|
||||||
|
[Issue #330](https://github.com/json-c/json-c/issues/330) - tests: symlink basic tests to a single file that has the common code \
|
||||||
|
[Issue #331](https://github.com/json-c/json-c/issues/331) - Safe use of snprintf() / vsnprintf() for Visual studio, and thread-safety fix \
|
||||||
|
[Issue #332](https://github.com/json-c/json-c/issues/332) - Valgrind: invalid read after json_object_array_del_idx. \
|
||||||
|
[Issue #333](https://github.com/json-c/json-c/issues/333) - Replace obsolete AM_PROG_LIBTOOL \
|
||||||
|
[Issue #335](https://github.com/json-c/json-c/issues/335) - README.md: show build status tag from travis-ci.org \
|
||||||
|
[Issue #336](https://github.com/json-c/json-c/issues/336) - tests: fix tests in travis-ci.org \
|
||||||
|
[Issue #337](https://github.com/json-c/json-c/issues/337) - Synchronize "potentially racy" random seed in lh_char_hash() \
|
||||||
|
[Issue #338](https://github.com/json-c/json-c/issues/338) - implement json_object_int_inc(json_object *, int64_t) \
|
||||||
|
[Issue #339](https://github.com/json-c/json-c/issues/339) - Json schema validation \
|
||||||
|
[Issue #340](https://github.com/json-c/json-c/issues/340) - strerror_override: add extern "C" and JSON_EXPORT specifiers for Visual C++ compilers \
|
||||||
|
[Issue #341](https://github.com/json-c/json-c/issues/341) - character "/" parse as "\/" \
|
||||||
|
[Issue #342](https://github.com/json-c/json-c/issues/342) - No such file or directory "/usr/include/json.h" \
|
||||||
|
[Issue #343](https://github.com/json-c/json-c/issues/343) - Can't parse json \
|
||||||
|
[Issue #344](https://github.com/json-c/json-c/issues/344) - Fix Mingw build \
|
||||||
|
[Issue #345](https://github.com/json-c/json-c/issues/345) - Fix make dist and make distcheck \
|
||||||
|
[Issue #346](https://github.com/json-c/json-c/issues/346) - Clamp double to int32 when narrowing in json_object_get_int. \
|
||||||
|
[Issue #347](https://github.com/json-c/json-c/issues/347) - MSVC linker error json_c_strerror \
|
||||||
|
[Issue #348](https://github.com/json-c/json-c/issues/348) - why \
|
||||||
|
[Issue #349](https://github.com/json-c/json-c/issues/349) - `missing` is missing? \
|
||||||
|
[Issue #350](https://github.com/json-c/json-c/issues/350) - stderror-override and disable-shared \
|
||||||
|
[Issue #351](https://github.com/json-c/json-c/issues/351) - SIZE_T_MAX redefined from limits.h \
|
||||||
|
[Issue #352](https://github.com/json-c/json-c/issues/352) - `INSTALL` overrides an automake script. \
|
||||||
|
[Issue #353](https://github.com/json-c/json-c/issues/353) - Documentation issues \
|
||||||
|
[Issue #354](https://github.com/json-c/json-c/issues/354) - Fixes #351 #352 #353 \
|
||||||
|
[Issue #355](https://github.com/json-c/json-c/issues/355) - 1.make it can been compiled with Visual Studio 2010 by modify the CMakeList.txt and others \
|
||||||
|
[Issue #356](https://github.com/json-c/json-c/issues/356) - VS2008 test test_util_file.cpp err! \
|
||||||
|
[Issue #357](https://github.com/json-c/json-c/issues/357) - __json_c_strerror incompatibility with link-time optimization \
|
||||||
|
[Issue #358](https://github.com/json-c/json-c/issues/358) - make issue \
|
||||||
|
[Issue #359](https://github.com/json-c/json-c/issues/359) - update CMakeLists.txt for compile with visual studio at least 2010 \
|
||||||
|
[Issue #360](https://github.com/json-c/json-c/issues/360) - Use strtoll() to parse ints \
|
||||||
|
[Issue #361](https://github.com/json-c/json-c/issues/361) - Fix double to int cast overflow in json_object_get_int64. \
|
||||||
|
[Issue #362](https://github.com/json-c/json-c/issues/362) - CMake Package Config \
|
||||||
|
[Issue #363](https://github.com/json-c/json-c/issues/363) - Issue #338, add json_object_add_int functions \
|
||||||
|
[Issue #364](https://github.com/json-c/json-c/issues/364) - Cmake is Errir \
|
||||||
|
[Issue #365](https://github.com/json-c/json-c/issues/365) - added fallthrough for gcc7 \
|
||||||
|
[Issue #366](https://github.com/json-c/json-c/issues/366) - how to check the json string,crash! \
|
||||||
|
[Issue #367](https://github.com/json-c/json-c/issues/367) - Is json-c support "redirect" semantic? \
|
||||||
|
[Issue #368](https://github.com/json-c/json-c/issues/368) - Add examples \
|
||||||
|
[Issue #369](https://github.com/json-c/json-c/issues/369) - How to build json-c library for android? \
|
||||||
|
[Issue #370](https://github.com/json-c/json-c/issues/370) - Compiling using clang-cl \
|
||||||
|
[Issue #371](https://github.com/json-c/json-c/issues/371) - Invalid parsing for Infinity with json-c 0.12 \
|
||||||
|
[Issue #372](https://github.com/json-c/json-c/issues/372) - Json-c 0.12: Fixed Infinity bug \
|
||||||
|
[Issue #373](https://github.com/json-c/json-c/issues/373) - build: fix build on appveyor CI \
|
||||||
|
[Issue #374](https://github.com/json-c/json-c/issues/374) - Undefined symbols for architecture x86_64: \
|
||||||
|
[Issue #375](https://github.com/json-c/json-c/issues/375) - what would happened when json_object_object_add add the same key \
|
||||||
|
[Issue #376](https://github.com/json-c/json-c/issues/376) - Eclipse error \
|
||||||
|
[Issue #377](https://github.com/json-c/json-c/issues/377) - on gcc 7.2.0 on my linux distribution with json-c 2013-04-02 source \
|
||||||
|
[Issue #378](https://github.com/json-c/json-c/issues/378) - Eclipse: library (libjson-c) not found, but configured \
|
||||||
|
[Issue #379](https://github.com/json-c/json-c/issues/379) - error: this statement may fall through \[-Werror=implicit-fallthrough=\] \
|
||||||
|
[Issue #380](https://github.com/json-c/json-c/issues/380) - Build on Windows \
|
||||||
|
[Issue #381](https://github.com/json-c/json-c/issues/381) - Fix makedist \
|
||||||
|
[Issue #382](https://github.com/json-c/json-c/issues/382) - Memory leak for json_tokener_parse_ex for version 0.12.1 \
|
||||||
|
[Issue #383](https://github.com/json-c/json-c/issues/383) - Fix a compiler warning. \
|
||||||
|
[Issue #384](https://github.com/json-c/json-c/issues/384) - Fix a VS 2015 compiler warnings. \
|
||||||
202
issues_closed_for_0.14.md
Normal file
202
issues_closed_for_0.14.md
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
This list was created with:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=1" > issues1.out
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=2" > issues2.out
|
||||||
|
curl https://api.github.com/search/issues?q="repo%3Ajson-c%2Fjson-c+closed%3A>2017-12-07+created%3A<2020-04-17&sort=created&order=asc&per_page=400&page=3" > issues3.out
|
||||||
|
jq -r '.items[] | "[" + .title + "](" + .url + ")" | tostring' issues?.out > issues.md
|
||||||
|
sed -e's,^\[ *\(.*\)\](https://api.github.com/.*/\([0-9].*\)),[Issue #\2](https://github.com/json-c/json-c/issues/\2) - \1,' -i issues.md
|
||||||
|
#... manual editing ...
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Issues and Pull Requests closed for the 0.14 release (since commit d582d3a(2017-12-07) to a911439(2020-04-17))
|
||||||
|
|
||||||
|
|
||||||
|
[Issue #122](https://github.com/json-c/json-c/issues/122) - Add utf-8 validation when parsing strings. \
|
||||||
|
[Issue #139](https://github.com/json-c/json-c/issues/139) - json_object_from_file cannot accept max_depth \
|
||||||
|
[Issue #143](https://github.com/json-c/json-c/issues/143) - RFE / enhancement for full 64-bit signed/unsigned support \
|
||||||
|
[Issue #147](https://github.com/json-c/json-c/issues/147) - Please introduce soname bump if API changed \
|
||||||
|
[Issue #166](https://github.com/json-c/json-c/issues/166) - Need a way to specify nesting depth when opening JSON file \
|
||||||
|
[Issue #226](https://github.com/json-c/json-c/issues/226) - There is no json_object_new_null() \
|
||||||
|
[Issue #314](https://github.com/json-c/json-c/issues/314) - new release ? \
|
||||||
|
[Issue #326](https://github.com/json-c/json-c/issues/326) - Please extend api json_object_get_uint64 \
|
||||||
|
[Issue #334](https://github.com/json-c/json-c/issues/334) - Switch json-c builds to use CMake \
|
||||||
|
[Issue #386](https://github.com/json-c/json-c/issues/386) - Makefile: Add ACLOCAL_AMFLAGS \
|
||||||
|
[Issue #387](https://github.com/json-c/json-c/issues/387) - doc: Use other doxygen feature to specify mainpage \
|
||||||
|
[Issue #388](https://github.com/json-c/json-c/issues/388) - json_object: Add size_t json_object_sizeof() \
|
||||||
|
[Issue #389](https://github.com/json-c/json-c/issues/389) - json_object: Avoid double free (and thus a segfault) when ref_count gets < 0 \
|
||||||
|
[Issue #390](https://github.com/json-c/json-c/issues/390) - json_object: Add const size_t json_c_object_sizeof() \
|
||||||
|
[Issue #391](https://github.com/json-c/json-c/issues/391) - Fix non-GNUC define for JSON_C_CONST_FUNCTION \
|
||||||
|
[Issue #392](https://github.com/json-c/json-c/issues/392) - json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0 \
|
||||||
|
[Issue #393](https://github.com/json-c/json-c/issues/393) - json_object_private: Use unsigned 32-bit integer type for refcount \
|
||||||
|
[Issue #394](https://github.com/json-c/json-c/issues/394) - Problem serializing double \
|
||||||
|
[Issue #395](https://github.com/json-c/json-c/issues/395) - Key gets modified if it contains "\" \
|
||||||
|
[Issue #396](https://github.com/json-c/json-c/issues/396) - Build failure with no threads uClibc toolchain \
|
||||||
|
[Issue #397](https://github.com/json-c/json-c/issues/397) - update json object with key. \
|
||||||
|
[Issue #398](https://github.com/json-c/json-c/issues/398) - Build failed. \
|
||||||
|
[Issue #399](https://github.com/json-c/json-c/issues/399) - Avoid uninitialized variable warnings \
|
||||||
|
[Issue #400](https://github.com/json-c/json-c/issues/400) - How to generate static lib (.a) \
|
||||||
|
[Issue #401](https://github.com/json-c/json-c/issues/401) - Warnings with Valgrind \
|
||||||
|
[Issue #402](https://github.com/json-c/json-c/issues/402) - Add fuzzers from OSS-Fuzz \
|
||||||
|
[Issue #403](https://github.com/json-c/json-c/issues/403) - Segmentation fault when double quotes is used \
|
||||||
|
[Issue #404](https://github.com/json-c/json-c/issues/404) - valgrind: memory leak \
|
||||||
|
[Issue #405](https://github.com/json-c/json-c/issues/405) - Missing API to determine an object is empty \
|
||||||
|
[Issue #406](https://github.com/json-c/json-c/issues/406) - Undefine NDEBUG for tests \
|
||||||
|
[Issue #407](https://github.com/json-c/json-c/issues/407) - json_tokener_parse is crash \
|
||||||
|
[Issue #408](https://github.com/json-c/json-c/issues/408) - bug in array_list_del_idx when array_list_length()==1 \
|
||||||
|
[Issue #410](https://github.com/json-c/json-c/issues/410) - Fixed typos \
|
||||||
|
[Issue #411](https://github.com/json-c/json-c/issues/411) - Crash- signal SIGSEGV, Segmentation fault. ../sysdeps/x86_64/strlen.S: No such file or directory. \
|
||||||
|
[Issue #412](https://github.com/json-c/json-c/issues/412) - json_type changes during inter process communication. \
|
||||||
|
[Issue #413](https://github.com/json-c/json-c/issues/413) - how to read object of type `json_object *` in c++ \
|
||||||
|
[Issue #414](https://github.com/json-c/json-c/issues/414) - [Question] How JSON-c stores the serialized data in memory? \
|
||||||
|
[Issue #415](https://github.com/json-c/json-c/issues/415) - Resolve windows name conflict \
|
||||||
|
[Issue #416](https://github.com/json-c/json-c/issues/416) - segmentation fault in json_tokener_parse \
|
||||||
|
[Issue #417](https://github.com/json-c/json-c/issues/417) - json_tokener_parse json_object_object_get_ex with string value which is json string \
|
||||||
|
[Issue #418](https://github.com/json-c/json-c/issues/418) - json_object_from_* return value documented incorrectly \
|
||||||
|
[Issue #419](https://github.com/json-c/json-c/issues/419) - Suggestion: document (and define) that json_object_put() accepts NULL pointer to object \
|
||||||
|
[Issue #420](https://github.com/json-c/json-c/issues/420) - arraylist: Fixed names of parameters for callback function \
|
||||||
|
[Issue #421](https://github.com/json-c/json-c/issues/421) - install json_object_iterator.h header file \
|
||||||
|
[Issue #422](https://github.com/json-c/json-c/issues/422) - json_object_get_double() does not set errno when there is no valid conversion \
|
||||||
|
[Issue #423](https://github.com/json-c/json-c/issues/423) - memory leak \
|
||||||
|
[Issue #424](https://github.com/json-c/json-c/issues/424) - Parse string contains "\" or "/" errors \
|
||||||
|
[Issue #425](https://github.com/json-c/json-c/issues/425) - what this is? \
|
||||||
|
[Issue #426](https://github.com/json-c/json-c/issues/426) - __deprecated not supported on clang. \
|
||||||
|
[Issue #427](https://github.com/json-c/json-c/issues/427) - CMake: builds involving this target will not be correct \
|
||||||
|
[Issue #430](https://github.com/json-c/json-c/issues/430) - json_object_object_del() and Segmentation fault \
|
||||||
|
[Issue #431](https://github.com/json-c/json-c/issues/431) - cmake: Bump required version \
|
||||||
|
[Issue #432](https://github.com/json-c/json-c/issues/432) - The real CMake support. \
|
||||||
|
[Issue #433](https://github.com/json-c/json-c/issues/433) - The real CMake support. \
|
||||||
|
[Issue #434](https://github.com/json-c/json-c/issues/434) - The real CMake support \
|
||||||
|
[Issue #435](https://github.com/json-c/json-c/issues/435) - json_object_object_del() segmentation fault \
|
||||||
|
[Issue #436](https://github.com/json-c/json-c/issues/436) - Improve pkgconfig setting \
|
||||||
|
[Issue #437](https://github.com/json-c/json-c/issues/437) - Bad link in README.md \
|
||||||
|
[Issue #438](https://github.com/json-c/json-c/issues/438) - Bad link in README.html \
|
||||||
|
[Issue #439](https://github.com/json-c/json-c/issues/439) - reserved identifier violation \
|
||||||
|
[Issue #440](https://github.com/json-c/json-c/issues/440) - Use of angle brackets around file names for include statements \
|
||||||
|
[Issue #441](https://github.com/json-c/json-c/issues/441) - fix c flag loss during cmake building \
|
||||||
|
[Issue #442](https://github.com/json-c/json-c/issues/442) - error in configure file \
|
||||||
|
[Issue #443](https://github.com/json-c/json-c/issues/443) - remove pretty spaces when using pretty tabs \
|
||||||
|
[Issue #444](https://github.com/json-c/json-c/issues/444) - Document refcount of json_tokener_parse_ex return \
|
||||||
|
[Issue #445](https://github.com/json-c/json-c/issues/445) - Add missing "make check" target to cmake config \
|
||||||
|
[Issue #446](https://github.com/json-c/json-c/issues/446) - Forward slashes get escaped \
|
||||||
|
[Issue #448](https://github.com/json-c/json-c/issues/448) - Buffer overflow in json-c \
|
||||||
|
[Issue #449](https://github.com/json-c/json-c/issues/449) - Need of json_type_int64 returned by json_object_get_type() \
|
||||||
|
[Issue #450](https://github.com/json-c/json-c/issues/450) - Allow use json-c cmake as subproject \
|
||||||
|
[Issue #452](https://github.com/json-c/json-c/issues/452) - Update README.md \
|
||||||
|
[Issue #453](https://github.com/json-c/json-c/issues/453) - Fixed misalignment in JSON string due to space after \n being printed... \
|
||||||
|
[Issue #454](https://github.com/json-c/json-c/issues/454) - json_object_private: save 8 bytes in struct json_object in 64-bit arc… \
|
||||||
|
[Issue #455](https://github.com/json-c/json-c/issues/455) - index.html:fix dead link \
|
||||||
|
[Issue #456](https://github.com/json-c/json-c/issues/456) - STYLE.txt:remove executable permissions \
|
||||||
|
[Issue #457](https://github.com/json-c/json-c/issues/457) - .gitignore:add build directory \
|
||||||
|
[Issue #458](https://github.com/json-c/json-c/issues/458) - README.md:fix dead "file.html" link \
|
||||||
|
[Issue #459](https://github.com/json-c/json-c/issues/459) - README.html:fix link to Doxygen docs, remove WIN32 link \
|
||||||
|
[Issue #460](https://github.com/json-c/json-c/issues/460) - No docs for json_object_new_string_len() \
|
||||||
|
[Issue #461](https://github.com/json-c/json-c/issues/461) - json_object.c:set errno in json_object_get_double() \
|
||||||
|
[Issue #462](https://github.com/json-c/json-c/issues/462) - json_object.h:document json_object_new_string_len() \
|
||||||
|
[Issue #463](https://github.com/json-c/json-c/issues/463) - please check newlocale api first argument valuse. \
|
||||||
|
[Issue #465](https://github.com/json-c/json-c/issues/465) - CMakeLists.txt doesn't contain json_object_iterator.h which json.h includes \
|
||||||
|
[Issue #466](https://github.com/json-c/json-c/issues/466) - configure:3610: error: C compiler cannot create executables \
|
||||||
|
[Issue #467](https://github.com/json-c/json-c/issues/467) - Fix compiler warnings \
|
||||||
|
[Issue #468](https://github.com/json-c/json-c/issues/468) - Fix compiler warnings \
|
||||||
|
[Issue #469](https://github.com/json-c/json-c/issues/469) - Build under alpine with pecl install & docker-php-ext-enable? \
|
||||||
|
[Issue #470](https://github.com/json-c/json-c/issues/470) - cfuhash_foreach_remove doesn't upate cfuhash_num_entries \
|
||||||
|
[Issue #472](https://github.com/json-c/json-c/issues/472) - Segmentation fault in json_object_iter_begin \
|
||||||
|
[Issue #473](https://github.com/json-c/json-c/issues/473) - Convert ChangeLog to valid UTF-8 encoding. \
|
||||||
|
[Issue #474](https://github.com/json-c/json-c/issues/474) - Installation directories empty with CMake in pkg-config. \
|
||||||
|
[Issue #475](https://github.com/json-c/json-c/issues/475) - improvement proposal for json_object_object_foreach \
|
||||||
|
[Issue #477](https://github.com/json-c/json-c/issues/477) - Hang/Crash with large strings \
|
||||||
|
[Issue #478](https://github.com/json-c/json-c/issues/478) - json_object_get_string_len returns 0 when value is number \
|
||||||
|
[Issue #479](https://github.com/json-c/json-c/issues/479) - I want to use it in iOS or Android but I can't compile \
|
||||||
|
[Issue #480](https://github.com/json-c/json-c/issues/480) - json-c-0.12.1 failed making from source code \
|
||||||
|
[Issue #481](https://github.com/json-c/json-c/issues/481) - error while loading shared libraries: libjson-c.so.4 \
|
||||||
|
[Issue #482](https://github.com/json-c/json-c/issues/482) - Error "double free or corruption" after free() \
|
||||||
|
[Issue #483](https://github.com/json-c/json-c/issues/483) - compatible with rarely-used Chinese characters in GBK charset \
|
||||||
|
[Issue #485](https://github.com/json-c/json-c/issues/485) - Install CMake module files \
|
||||||
|
[Issue #486](https://github.com/json-c/json-c/issues/486) - In the case of negative double value, it is formatted without including ".0" \
|
||||||
|
[Issue #488](https://github.com/json-c/json-c/issues/488) - Some APIs are not exported when built as shared lib on Win32 \
|
||||||
|
[Issue #489](https://github.com/json-c/json-c/issues/489) - Don't use -Werror by default \
|
||||||
|
[Issue #490](https://github.com/json-c/json-c/issues/490) - do not compile with -Werror by default \
|
||||||
|
[Issue #491](https://github.com/json-c/json-c/issues/491) - build: add option --disable-werror to configure \
|
||||||
|
[Issue #492](https://github.com/json-c/json-c/issues/492) - lack some quick usage in readme \
|
||||||
|
[Issue #494](https://github.com/json-c/json-c/issues/494) - Code generator? \
|
||||||
|
[Issue #495](https://github.com/json-c/json-c/issues/495) - README.md:fix 2 typos \
|
||||||
|
[Issue #496](https://github.com/json-c/json-c/issues/496) - json_pointer.h:suggest minor grammar improvement for pointer doc \
|
||||||
|
[Issue #497](https://github.com/json-c/json-c/issues/497) - add common header for all tests \
|
||||||
|
[Issue #498](https://github.com/json-c/json-c/issues/498) - double_serializer_test fails (with valgrind) \
|
||||||
|
[Issue #499](https://github.com/json-c/json-c/issues/499) - .travis.yml:test on more recent clang and gcc versions \
|
||||||
|
[Issue #500](https://github.com/json-c/json-c/issues/500) - test/Makefile.am:add missing deps for test1 and test2 \
|
||||||
|
[Issue #501](https://github.com/json-c/json-c/issues/501) - undefine NDEBUG for tests \
|
||||||
|
[Issue #502](https://github.com/json-c/json-c/issues/502) - configure error \
|
||||||
|
[Issue #503](https://github.com/json-c/json-c/issues/503) - json-c retuns OK when Invalid json string is passed \
|
||||||
|
[Issue #504](https://github.com/json-c/json-c/issues/504) - json_object_put coredump \
|
||||||
|
[Issue #505](https://github.com/json-c/json-c/issues/505) - Add vcpkg installation instructions \
|
||||||
|
[Issue #506](https://github.com/json-c/json-c/issues/506) - Cannot parse more than one object \
|
||||||
|
[Issue #509](https://github.com/json-c/json-c/issues/509) - Sometimes a double value is not serialized \
|
||||||
|
[Issue #510](https://github.com/json-c/json-c/issues/510) - Bump so-name and improve CMake \
|
||||||
|
[Issue #511](https://github.com/json-c/json-c/issues/511) - Reduce lines for better optimization \
|
||||||
|
[Issue #512](https://github.com/json-c/json-c/issues/512) - Properly append to CMAKE_C_FLAGS string \
|
||||||
|
[Issue #513](https://github.com/json-c/json-c/issues/513) - What does `userdata` means?And what is the case we can use it? \
|
||||||
|
[Issue #514](https://github.com/json-c/json-c/issues/514) - Json c 0.13 \
|
||||||
|
[Issue #515](https://github.com/json-c/json-c/issues/515) - Mies suomesta fixes segfaults and logic errors \
|
||||||
|
[Issue #516](https://github.com/json-c/json-c/issues/516) - Lja slight mods \
|
||||||
|
[Issue #518](https://github.com/json-c/json-c/issues/518) - Escape character "\\003\", get unexpected value \
|
||||||
|
[Issue #519](https://github.com/json-c/json-c/issues/519) - Add test case obj token \
|
||||||
|
[Issue #520](https://github.com/json-c/json-c/issues/520) - Adding type uint64 \
|
||||||
|
[Issue #521](https://github.com/json-c/json-c/issues/521) - build cmake windows 10 \
|
||||||
|
[Issue #522](https://github.com/json-c/json-c/issues/522) - update json_visit testcase \
|
||||||
|
[Issue #523](https://github.com/json-c/json-c/issues/523) - update tsetcase for tokener_c \
|
||||||
|
[Issue #524](https://github.com/json-c/json-c/issues/524) - Increase coverage \
|
||||||
|
[Issue #525](https://github.com/json-c/json-c/issues/525) - update pointer test case \
|
||||||
|
[Issue #526](https://github.com/json-c/json-c/issues/526) - Increased the test coverage of printbuf.c 82% to 92%. \
|
||||||
|
[Issue #527](https://github.com/json-c/json-c/issues/527) - Arraylist testcase \
|
||||||
|
[Issue #528](https://github.com/json-c/json-c/issues/528) - Solve issue #108. Skip \u0000 while parsing. \
|
||||||
|
[Issue #529](https://github.com/json-c/json-c/issues/529) - Increased the test coverage of json_c_version.c 0% to 100%. \
|
||||||
|
[Issue #530](https://github.com/json-c/json-c/issues/530) - validate utf-8 string before parse \
|
||||||
|
[Issue #531](https://github.com/json-c/json-c/issues/531) - validate utf-8 string \
|
||||||
|
[Issue #532](https://github.com/json-c/json-c/issues/532) - json_object_object_get_ex returning the original object \
|
||||||
|
[Issue #533](https://github.com/json-c/json-c/issues/533) - Fix "make check" \
|
||||||
|
[Issue #535](https://github.com/json-c/json-c/issues/535) - short string optimization: excessive array length \
|
||||||
|
[Issue #536](https://github.com/json-c/json-c/issues/536) - add json_object_new_null() \
|
||||||
|
[Issue #538](https://github.com/json-c/json-c/issues/538) - update shortstring and arraylist parameters \
|
||||||
|
[Issue #539](https://github.com/json-c/json-c/issues/539) - double serializes to the old value after set_double \
|
||||||
|
[Issue #541](https://github.com/json-c/json-c/issues/541) - add coveralls auto tool to json-c \
|
||||||
|
[Issue #542](https://github.com/json-c/json-c/issues/542) - add uint64 data to json-c \
|
||||||
|
[Issue #543](https://github.com/json-c/json-c/issues/543) - Readme \
|
||||||
|
[Issue #544](https://github.com/json-c/json-c/issues/544) - Increase distcheck target in cmake \
|
||||||
|
[Issue #545](https://github.com/json-c/json-c/issues/545) - add doc target in cmake \
|
||||||
|
[Issue #546](https://github.com/json-c/json-c/issues/546) - Add uninstall target in cmake \
|
||||||
|
[Issue #547](https://github.com/json-c/json-c/issues/547) - modify json-c default build type, and fix up the assert() errors in t… \
|
||||||
|
[Issue #548](https://github.com/json-c/json-c/issues/548) - Solve some problems about cmake build type (debug/release) \
|
||||||
|
[Issue #549](https://github.com/json-c/json-c/issues/549) - lib installation issues \
|
||||||
|
[Issue #550](https://github.com/json-c/json-c/issues/550) - Format codes with clang-format tool? \
|
||||||
|
[Issue #551](https://github.com/json-c/json-c/issues/551) - Allow hexadecimal number format convention parsing \
|
||||||
|
[Issue #553](https://github.com/json-c/json-c/issues/553) - Fix/clang ubsan \
|
||||||
|
[Issue #554](https://github.com/json-c/json-c/issues/554) - RFC 8259 compatibility mode \
|
||||||
|
[Issue #555](https://github.com/json-c/json-c/issues/555) - Format json-c with clang-format tool \
|
||||||
|
[Issue #556](https://github.com/json-c/json-c/issues/556) - Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64 \
|
||||||
|
[Issue #557](https://github.com/json-c/json-c/issues/557) - Add option in CMAKE to not build documentation \
|
||||||
|
[Issue #558](https://github.com/json-c/json-c/issues/558) - modify the doc target message \
|
||||||
|
[Issue #559](https://github.com/json-c/json-c/issues/559) - json_c_visit() not exported on Windows \
|
||||||
|
[Issue #560](https://github.com/json-c/json-c/issues/560) - error: implicit declaration of function '_strtoi64' \
|
||||||
|
[Issue #561](https://github.com/json-c/json-c/issues/561) - add the badge in README.md and test the coveralls \
|
||||||
|
[Issue #562](https://github.com/json-c/json-c/issues/562) - Bugfix and testcases supplements \
|
||||||
|
[Issue #563](https://github.com/json-c/json-c/issues/563) - Changed order of calloc args to match stdlib \
|
||||||
|
[Issue #564](https://github.com/json-c/json-c/issues/564) - Remove autogenerated files \
|
||||||
|
[Issue #565](https://github.com/json-c/json-c/issues/565) - test the CI and ignore this PR \
|
||||||
|
[Issue #566](https://github.com/json-c/json-c/issues/566) - add the json_types.h to Makefile.am \
|
||||||
|
[Issue #567](https://github.com/json-c/json-c/issues/567) - Install json_types.h with autotools build as well. \
|
||||||
|
[Issue #568](https://github.com/json-c/json-c/issues/568) - Adding better support to MinGW \
|
||||||
|
[Issue #569](https://github.com/json-c/json-c/issues/569) - Handling of -Bsymbolic-function in CMakeLists.txt is deficient \
|
||||||
|
[Issue #571](https://github.com/json-c/json-c/issues/571) - CMake: Bump SONAME to 5. \
|
||||||
|
[Issue #572](https://github.com/json-c/json-c/issues/572) - Small fixes to CMakeLists \
|
||||||
|
[Issue #573](https://github.com/json-c/json-c/issues/573) - Fix coveralls submission. \
|
||||||
|
[Issue #574](https://github.com/json-c/json-c/issues/574) - autogen.sh missing from repository \
|
||||||
|
[Issue #575](https://github.com/json-c/json-c/issues/575) - Small cosmetics. \
|
||||||
|
[Issue #576](https://github.com/json-c/json-c/issues/576) - Test coverage for json_c_version. \
|
||||||
|
[Issue #577](https://github.com/json-c/json-c/issues/577) - Be verbose on failing json_c_version test. \
|
||||||
|
[Issue #578](https://github.com/json-c/json-c/issues/578) - CMake: Install pkgconfig file in proper location by default \
|
||||||
|
[Issue #579](https://github.com/json-c/json-c/issues/579) - Enforce strict prototypes. \
|
||||||
|
[Issue #580](https://github.com/json-c/json-c/issues/580) - Fix CMake tests for enforced strict prototypes. \
|
||||||
|
[Issue #581](https://github.com/json-c/json-c/issues/581) - CMakeLists: do not enforce strict prototypes on Windows. \
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
prefix=
|
|
||||||
exec_prefix=
|
|
||||||
libdir=@abs_top_builddir@
|
|
||||||
includedir=@abs_top_srcdir@
|
|
||||||
|
|
||||||
Name: json
|
|
||||||
Description: JSON implementation in C
|
|
||||||
Version: @VERSION@
|
|
||||||
Requires:
|
|
||||||
Libs: -L@abs_top_builddir@ -ljson-c
|
|
||||||
Cflags: -I@abs_top_srcdir@
|
|
||||||
@@ -4,8 +4,9 @@ libdir=@libdir@
|
|||||||
includedir=@includedir@
|
includedir=@includedir@
|
||||||
|
|
||||||
Name: json-c
|
Name: json-c
|
||||||
Description: JSON implementation in C
|
Description: A JSON implementation in C
|
||||||
Version: @VERSION@
|
Version: @VERSION@
|
||||||
Requires:
|
Requires:
|
||||||
|
Libs.private: @LIBS@
|
||||||
Libs: -L${libdir} -ljson-c
|
Libs: -L${libdir} -ljson-c
|
||||||
Cflags: -I${includedir}/json-c
|
Cflags: -I${includedir} -I${includedir}/json-c
|
||||||
|
|||||||
179
json-c.vcproj
179
json-c.vcproj
@@ -1,179 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
|
||||||
<VisualStudioProject
|
|
||||||
ProjectType="Visual C++"
|
|
||||||
Version="7.10"
|
|
||||||
Name="json-c"
|
|
||||||
ProjectGUID="{04D8CDBE-FB3E-4362-87E6-07DC3C0083B2}"
|
|
||||||
Keyword="Win32Proj">
|
|
||||||
<Platforms>
|
|
||||||
<Platform
|
|
||||||
Name="Win32"/>
|
|
||||||
</Platforms>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
OutputDirectory="Debug"
|
|
||||||
IntermediateDirectory="Debug"
|
|
||||||
ConfigurationType="4"
|
|
||||||
CharacterSet="2">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
|
||||||
MinimalRebuild="TRUE"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="5"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
Detect64BitPortabilityProblems="TRUE"
|
|
||||||
DebugInformationFormat="4"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLibrarianTool"
|
|
||||||
OutputFile="$(OutDir)/jsonD.lib"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
CommandLine="copy config.h.win32 config.h"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedWrapperGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|Win32"
|
|
||||||
OutputDirectory="Release"
|
|
||||||
IntermediateDirectory="Release"
|
|
||||||
ConfigurationType="4"
|
|
||||||
CharacterSet="2">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
|
||||||
RuntimeLibrary="4"
|
|
||||||
UsePrecompiledHeader="0"
|
|
||||||
WarningLevel="3"
|
|
||||||
Detect64BitPortabilityProblems="TRUE"
|
|
||||||
DebugInformationFormat="3"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLibrarianTool"
|
|
||||||
OutputFile="$(OutDir)/json.lib"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedWrapperGeneratorTool"/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<References>
|
|
||||||
</References>
|
|
||||||
<Files>
|
|
||||||
<Filter
|
|
||||||
Name="Source Files"
|
|
||||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
|
||||||
<File
|
|
||||||
RelativePath=".\arraylist.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\debug.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_object.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_tokener.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_util.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\linkhash.c">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\printbuf.c">
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Header Files"
|
|
||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
|
||||||
<File
|
|
||||||
RelativePath=".\arraylist.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\bits.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\debug.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_object.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_object_private.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_tokener.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\json_util.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\linkhash.h">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\printbuf.h">
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Resource Files"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
|
||||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Documentation"
|
|
||||||
Filter="">
|
|
||||||
<File
|
|
||||||
RelativePath=".\Doxyfile">
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<File
|
|
||||||
RelativePath=".\config.h.win32">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\README-WIN32.html">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\README.html">
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
<Globals>
|
|
||||||
</Globals>
|
|
||||||
</VisualStudioProject>
|
|
||||||
18
json.h
18
json.h
@@ -10,6 +10,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief A convenience header that may be included instead of other individual ones.
|
||||||
|
*/
|
||||||
#ifndef _json_h_
|
#ifndef _json_h_
|
||||||
#define _json_h_
|
#define _json_h_
|
||||||
|
|
||||||
@@ -17,15 +21,15 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "bits.h"
|
|
||||||
#include "debug.h"
|
|
||||||
#include "linkhash.h"
|
|
||||||
#include "arraylist.h"
|
#include "arraylist.h"
|
||||||
#include "json_util.h"
|
#include "debug.h"
|
||||||
#include "json_object.h"
|
|
||||||
#include "json_tokener.h"
|
|
||||||
#include "json_object_iterator.h"
|
|
||||||
#include "json_c_version.h"
|
#include "json_c_version.h"
|
||||||
|
#include "json_object.h"
|
||||||
|
#include "json_object_iterator.h"
|
||||||
|
#include "json_pointer.h"
|
||||||
|
#include "json_tokener.h"
|
||||||
|
#include "json_util.h"
|
||||||
|
#include "linkhash.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,3 @@ int json_c_version_num(void)
|
|||||||
{
|
{
|
||||||
return JSON_C_VERSION_NUM;
|
return JSON_C_VERSION_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012 Eric Haszlakiewicz
|
* Copyright (c) 2012,2017 Eric Haszlakiewicz
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the MIT license. See COPYING for details.
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Methods for retrieving the json-c version.
|
||||||
|
*/
|
||||||
#ifndef _json_c_version_h_
|
#ifndef _json_c_version_h_
|
||||||
#define _json_c_version_h_
|
#define _json_c_version_h_
|
||||||
|
|
||||||
#define JSON_C_MAJOR_VERSION 0
|
#ifdef __cplusplus
|
||||||
#define JSON_C_MINOR_VERSION 11
|
extern "C" {
|
||||||
#define JSON_C_MICRO_VERSION 99
|
#endif
|
||||||
#define JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | \
|
|
||||||
(JSON_C_MINOR_VERSION << 8) | \
|
|
||||||
JSON_C_MICRO_VERSION)
|
|
||||||
#define JSON_C_VERSION "0.11.99"
|
|
||||||
|
|
||||||
const char *json_c_version(void); /* Returns JSON_C_VERSION */
|
#define JSON_C_MAJOR_VERSION 0
|
||||||
int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */
|
#define JSON_C_MINOR_VERSION 14
|
||||||
|
#define JSON_C_MICRO_VERSION 99
|
||||||
|
#define JSON_C_VERSION_NUM \
|
||||||
|
((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION)
|
||||||
|
#define JSON_C_VERSION "0.14.99"
|
||||||
|
|
||||||
|
#ifndef JSON_EXPORT
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define JSON_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JSON_EXPORT extern
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see JSON_C_VERSION
|
||||||
|
* @return the version of the json-c library as a string
|
||||||
|
*/
|
||||||
|
JSON_EXPORT const char *json_c_version(void); /* Returns JSON_C_VERSION */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The json-c version encoded into an int, with the low order 8 bits
|
||||||
|
* being the micro version, the next higher 8 bits being the minor version
|
||||||
|
* and the next higher 8 bits being the major version.
|
||||||
|
* For example, 7.12.99 would be 0x00070B63.
|
||||||
|
*
|
||||||
|
* @see JSON_C_VERSION_NUM
|
||||||
|
* @return the version of the json-c library as an int
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
5
json_config.h.win32
Normal file
5
json_config.h.win32
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1800
|
||||||
|
#define JSON_C_HAVE_INTTYPES_H 1
|
||||||
|
#endif
|
||||||
@@ -1,27 +1,23 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
#ifndef _json_inttypes_h_
|
#ifndef _json_inttypes_h_
|
||||||
#define _json_inttypes_h_
|
#define _json_inttypes_h_
|
||||||
|
|
||||||
#include "json_config.h"
|
#include "json_config.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
#ifdef JSON_C_HAVE_INTTYPES_H
|
||||||
|
/* inttypes.h includes stdint.h */
|
||||||
/* Anything less than Visual Studio C++ 10 is missing stdint.h and inttypes.h */
|
#include <inttypes.h>
|
||||||
typedef __int32 int32_t;
|
|
||||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
|
||||||
#define INT32_MAX ((int32_t)_I32_MAX)
|
|
||||||
typedef __int64 int64_t;
|
|
||||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
|
||||||
#define INT64_MAX ((int64_t)_I64_MAX)
|
|
||||||
#define PRId64 "I64d"
|
|
||||||
#define SCNd64 "I64d"
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef JSON_C_HAVE_INTTYPES_H
|
#define PRId64 "I64d"
|
||||||
#include <inttypes.h>
|
#define SCNd64 "I64d"
|
||||||
#endif
|
#define PRIu64 "I64u"
|
||||||
/* inttypes.h includes stdint.h */
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
1618
json_object.c
1618
json_object.c
File diff suppressed because it is too large
Load Diff
680
json_object.h
680
json_object.h
@@ -10,6 +10,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Core json-c API. Start here, or with json_tokener.h
|
||||||
|
*/
|
||||||
#ifndef _json_object_h_
|
#ifndef _json_object_h_
|
||||||
#define _json_object_h_
|
#define _json_object_h_
|
||||||
|
|
||||||
@@ -17,11 +21,23 @@
|
|||||||
#define THIS_FUNCTION_IS_DEPRECATED(func) func __attribute__((deprecated))
|
#define THIS_FUNCTION_IS_DEPRECATED(func) func __attribute__((deprecated))
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define THIS_FUNCTION_IS_DEPRECATED(func) __declspec(deprecated) func
|
#define THIS_FUNCTION_IS_DEPRECATED(func) __declspec(deprecated) func
|
||||||
|
#elif defined(__clang__)
|
||||||
|
#define THIS_FUNCTION_IS_DEPRECATED(func) func __deprecated
|
||||||
#else
|
#else
|
||||||
#define THIS_FUNCTION_IS_DEPRECATED(func) func
|
#define THIS_FUNCTION_IS_DEPRECATED(func) func
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define JSON_C_CONST_FUNCTION(func) func __attribute__((const))
|
||||||
|
#else
|
||||||
|
#define JSON_C_CONST_FUNCTION(func) func
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "json_inttypes.h"
|
#include "json_inttypes.h"
|
||||||
|
#include "json_types.h"
|
||||||
|
#include "printbuf.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -50,63 +66,69 @@ extern "C" {
|
|||||||
* for an example of the format.
|
* for an example of the format.
|
||||||
*/
|
*/
|
||||||
#define JSON_C_TO_STRING_PRETTY (1 << 1)
|
#define JSON_C_TO_STRING_PRETTY (1 << 1)
|
||||||
|
/**
|
||||||
|
* A flag for the json_object_to_json_string_ext() and
|
||||||
|
* json_object_to_file_ext() functions which causes
|
||||||
|
* the output to be formatted.
|
||||||
|
*
|
||||||
|
* Instead of a "Two Space Tab" this gives a single tab character.
|
||||||
|
*/
|
||||||
|
#define JSON_C_TO_STRING_PRETTY_TAB (1 << 3)
|
||||||
/**
|
/**
|
||||||
* A flag to drop trailing zero for float values
|
* A flag to drop trailing zero for float values
|
||||||
*/
|
*/
|
||||||
#define JSON_C_TO_STRING_NOZERO (1 << 2)
|
#define JSON_C_TO_STRING_NOZERO (1 << 2)
|
||||||
|
|
||||||
#undef FALSE
|
/**
|
||||||
#define FALSE ((json_bool)0)
|
* Don't escape forward slashes.
|
||||||
|
*/
|
||||||
#undef TRUE
|
#define JSON_C_TO_STRING_NOSLASHESCAPE (1 << 4)
|
||||||
#define TRUE ((json_bool)1)
|
|
||||||
|
|
||||||
extern const char *json_number_chars;
|
|
||||||
extern const char *json_hex_chars;
|
|
||||||
|
|
||||||
/* CAW: added for ANSI C iteration correctness */
|
|
||||||
struct json_object_iter
|
|
||||||
{
|
|
||||||
char *key;
|
|
||||||
struct json_object *val;
|
|
||||||
struct lh_entry *entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* forward structure definitions */
|
|
||||||
|
|
||||||
typedef int json_bool;
|
|
||||||
typedef struct printbuf printbuf;
|
|
||||||
typedef struct lh_table lh_table;
|
|
||||||
typedef struct array_list array_list;
|
|
||||||
typedef struct json_object json_object;
|
|
||||||
typedef struct json_object_iter json_object_iter;
|
|
||||||
typedef struct json_tokener json_tokener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of custom user delete functions. See json_object_set_serializer.
|
* A flag for the json_object_object_add_ex function which
|
||||||
|
* causes the value to be added without a check if it already exists.
|
||||||
|
* Note: it is the responsibility of the caller to ensure that no
|
||||||
|
* key is added multiple times. If this is done, results are
|
||||||
|
* unpredictable. While this option is somewhat dangerous, it
|
||||||
|
* permits potentially large performance savings in code that
|
||||||
|
* knows for sure the key values are unique (e.g. because the
|
||||||
|
* code adds a well-known set of constant key values).
|
||||||
*/
|
*/
|
||||||
typedef void (json_object_delete_fn)(struct json_object *jso, void *userdata);
|
#define JSON_C_OBJECT_ADD_KEY_IS_NEW (1 << 1)
|
||||||
|
/**
|
||||||
|
* A flag for the json_object_object_add_ex function which
|
||||||
|
* flags the key as being constant memory. This means that
|
||||||
|
* the key will NOT be copied via strdup(), resulting in a
|
||||||
|
* potentially huge performance win (malloc, strdup and
|
||||||
|
* free are usually performance hogs). It is acceptable to
|
||||||
|
* use this flag for keys in non-constant memory blocks if
|
||||||
|
* the caller ensure that the memory holding the key lives
|
||||||
|
* longer than the corresponding json object. However, this
|
||||||
|
* is somewhat dangerous and should only be done if really
|
||||||
|
* justified.
|
||||||
|
* The general use-case for this flag is cases where the
|
||||||
|
* key is given as a real constant value in the function
|
||||||
|
* call, e.g. as in
|
||||||
|
* json_object_object_add_ex(obj, "ip", json,
|
||||||
|
* JSON_C_OBJECT_KEY_IS_CONSTANT);
|
||||||
|
*/
|
||||||
|
#define JSON_C_OBJECT_KEY_IS_CONSTANT (1 << 2)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of a custom serialization function. See json_object_set_serializer.
|
* Set the global value of an option, which will apply to all
|
||||||
|
* current and future threads that have not set a thread-local value.
|
||||||
|
*
|
||||||
|
* @see json_c_set_serialization_double_format
|
||||||
*/
|
*/
|
||||||
typedef int (json_object_to_json_string_fn)(struct json_object *jso,
|
#define JSON_C_OPTION_GLOBAL (0)
|
||||||
struct printbuf *pb,
|
/**
|
||||||
int level,
|
* Set a thread-local value of an option, overriding the global value.
|
||||||
int flags);
|
* This will fail if json-c is not compiled with threading enabled, and
|
||||||
|
* with the __thread specifier (or equivalent) available.
|
||||||
/* supported object types */
|
*
|
||||||
|
* @see json_c_set_serialization_double_format
|
||||||
typedef enum json_type {
|
*/
|
||||||
/* If you change this, be sure to update json_type_to_name() too */
|
#define JSON_C_OPTION_THREAD (1)
|
||||||
json_type_null,
|
|
||||||
json_type_boolean,
|
|
||||||
json_type_double,
|
|
||||||
json_type_int,
|
|
||||||
json_type_object,
|
|
||||||
json_type_array,
|
|
||||||
json_type_string,
|
|
||||||
} json_type;
|
|
||||||
|
|
||||||
/* reference counting functions */
|
/* reference counting functions */
|
||||||
|
|
||||||
@@ -116,17 +138,18 @@ typedef enum json_type {
|
|||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_get(struct json_object *obj);
|
JSON_EXPORT struct json_object *json_object_get(struct json_object *obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrement the reference count of json_object and free if it reaches zero.
|
* Decrement the reference count of json_object and free if it reaches zero.
|
||||||
* You must have ownership of obj prior to doing this or you will cause an
|
* You must have ownership of obj prior to doing this or you will cause an
|
||||||
* imbalance in the reference count.
|
* imbalance in the reference count.
|
||||||
|
* An obj of NULL may be passed; in that case this call is a no-op.
|
||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns 1 if the object was freed.
|
* @returns 1 if the object was freed.
|
||||||
*/
|
*/
|
||||||
int json_object_put(struct json_object *obj);
|
JSON_EXPORT int json_object_put(struct json_object *obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the json_object is of a given type
|
* Check if the json_object is of a given type
|
||||||
@@ -138,9 +161,9 @@ int json_object_put(struct json_object *obj);
|
|||||||
json_type_int,
|
json_type_int,
|
||||||
json_type_object,
|
json_type_object,
|
||||||
json_type_array,
|
json_type_array,
|
||||||
json_type_string,
|
json_type_string
|
||||||
*/
|
*/
|
||||||
extern int json_object_is_type(struct json_object *obj, enum json_type type);
|
JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of the json_object. See also json_type_to_name() to turn this
|
* Get the type of the json_object. See also json_type_to_name() to turn this
|
||||||
@@ -154,39 +177,54 @@ extern int json_object_is_type(struct json_object *obj, enum json_type type);
|
|||||||
json_type_int,
|
json_type_int,
|
||||||
json_type_object,
|
json_type_object,
|
||||||
json_type_array,
|
json_type_array,
|
||||||
json_type_string,
|
json_type_string
|
||||||
*/
|
*/
|
||||||
extern enum json_type json_object_get_type(struct json_object *obj);
|
JSON_EXPORT enum json_type json_object_get_type(const struct json_object *obj);
|
||||||
|
|
||||||
|
|
||||||
/** Stringify object to json format.
|
/** Stringify object to json format.
|
||||||
* Equivalent to json_object_to_json_string_ext(obj, JSON_C_TO_STRING_SPACED)
|
* Equivalent to json_object_to_json_string_ext(obj, JSON_C_TO_STRING_SPACED)
|
||||||
|
* The pointer you get is an internal of your json object. You don't
|
||||||
|
* have to free it, later use of json_object_put() should be sufficient.
|
||||||
|
* If you can not ensure there's no concurrent access to *obj use
|
||||||
|
* strdup().
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a string in JSON format
|
* @returns a string in JSON format
|
||||||
*/
|
*/
|
||||||
extern const char* json_object_to_json_string(struct json_object *obj);
|
JSON_EXPORT const char *json_object_to_json_string(struct json_object *obj);
|
||||||
|
|
||||||
/** Stringify object to json format
|
/** Stringify object to json format
|
||||||
|
* @see json_object_to_json_string() for details on how to free string.
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param flags formatting options, see JSON_C_TO_STRING_PRETTY and other constants
|
* @param flags formatting options, see JSON_C_TO_STRING_PRETTY and other constants
|
||||||
* @returns a string in JSON format
|
* @returns a string in JSON format
|
||||||
*/
|
*/
|
||||||
extern const char* json_object_to_json_string_ext(struct json_object *obj, int
|
JSON_EXPORT const char *json_object_to_json_string_ext(struct json_object *obj, int flags);
|
||||||
flags);
|
|
||||||
|
/** Stringify object to json format
|
||||||
|
* @see json_object_to_json_string() for details on how to free string.
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param flags formatting options, see JSON_C_TO_STRING_PRETTY and other constants
|
||||||
|
* @param length a pointer where, if not NULL, the length (without null) is stored
|
||||||
|
* @returns a string in JSON format and the length if not NULL
|
||||||
|
*/
|
||||||
|
JSON_EXPORT const char *json_object_to_json_string_length(struct json_object *obj, int flags,
|
||||||
|
size_t *length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a custom serialization function to be used when this particular object
|
* Returns the userdata set by json_object_set_userdata() or
|
||||||
* is converted to a string by json_object_to_json_string.
|
* json_object_set_serializer()
|
||||||
*
|
*
|
||||||
* If a custom serializer is already set on this object, any existing
|
* @param jso the object to return the userdata for
|
||||||
* user_delete function is called before the new one is set.
|
*/
|
||||||
|
JSON_EXPORT void *json_object_get_userdata(json_object *jso);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an opaque userdata value for an object
|
||||||
*
|
*
|
||||||
* If to_string_func is NULL, the other parameters are ignored
|
* The userdata can be retrieved using json_object_get_userdata().
|
||||||
* and the default behaviour is reset.
|
|
||||||
*
|
*
|
||||||
* The userdata parameter is optional and may be passed as NULL. If provided,
|
* If custom userdata is already set on this object, any existing user_delete
|
||||||
* it is passed to to_string_func as-is. This parameter may be NULL even
|
* function is called before the new one is set.
|
||||||
* if user_delete is non-NULL.
|
|
||||||
*
|
*
|
||||||
* The user_delete parameter is optional and may be passed as NULL, even if
|
* The user_delete parameter is optional and may be passed as NULL, even if
|
||||||
* the userdata parameter is non-NULL. It will be called just before the
|
* the userdata parameter is non-NULL. It will be called just before the
|
||||||
@@ -195,15 +233,62 @@ flags);
|
|||||||
* If this is not provided, it is up to the caller to free the userdata at
|
* If this is not provided, it is up to the caller to free the userdata at
|
||||||
* an appropriate time. (i.e. after the json_object is deleted)
|
* an appropriate time. (i.e. after the json_object is deleted)
|
||||||
*
|
*
|
||||||
|
* Note: Objects created by parsing strings may have custom serializers set
|
||||||
|
* which expect the userdata to contain specific data (due to use of
|
||||||
|
* json_object_new_double_s()). In this case, json_object_set_serialiser() with
|
||||||
|
* NULL as to_string_func should be used instead to set the userdata and reset
|
||||||
|
* the serializer to its default value.
|
||||||
|
*
|
||||||
|
* @param jso the object to set the userdata for
|
||||||
|
* @param userdata an optional opaque cookie
|
||||||
|
* @param user_delete an optional function from freeing userdata
|
||||||
|
*/
|
||||||
|
JSON_EXPORT void json_object_set_userdata(json_object *jso, void *userdata,
|
||||||
|
json_object_delete_fn *user_delete);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a custom serialization function to be used when this particular object
|
||||||
|
* is converted to a string by json_object_to_json_string.
|
||||||
|
*
|
||||||
|
* If custom userdata is already set on this object, any existing user_delete
|
||||||
|
* function is called before the new one is set.
|
||||||
|
*
|
||||||
|
* If to_string_func is NULL the default behaviour is reset (but the userdata
|
||||||
|
* and user_delete fields are still set).
|
||||||
|
*
|
||||||
|
* The userdata parameter is optional and may be passed as NULL. It can be used
|
||||||
|
* to provide additional data for to_string_func to use. This parameter may
|
||||||
|
* be NULL even if user_delete is non-NULL.
|
||||||
|
*
|
||||||
|
* The user_delete parameter is optional and may be passed as NULL, even if
|
||||||
|
* the userdata parameter is non-NULL. It will be called just before the
|
||||||
|
* json_object is deleted, after it's reference count goes to zero
|
||||||
|
* (see json_object_put()).
|
||||||
|
* If this is not provided, it is up to the caller to free the userdata at
|
||||||
|
* an appropriate time. (i.e. after the json_object is deleted)
|
||||||
|
*
|
||||||
|
* Note that the userdata is the same as set by json_object_set_userdata(), so
|
||||||
|
* care must be taken not to overwrite the value when both a custom serializer
|
||||||
|
* and json_object_set_userdata() are used.
|
||||||
|
*
|
||||||
* @param jso the object to customize
|
* @param jso the object to customize
|
||||||
* @param to_string_func the custom serialization function
|
* @param to_string_func the custom serialization function
|
||||||
* @param userdata an optional opaque cookie
|
* @param userdata an optional opaque cookie
|
||||||
* @param user_delete an optional function from freeing userdata
|
* @param user_delete an optional function from freeing userdata
|
||||||
*/
|
*/
|
||||||
extern void json_object_set_serializer(json_object *jso,
|
JSON_EXPORT void json_object_set_serializer(json_object *jso,
|
||||||
json_object_to_json_string_fn to_string_func,
|
json_object_to_json_string_fn *to_string_func,
|
||||||
void *userdata,
|
void *userdata, json_object_delete_fn *user_delete);
|
||||||
json_object_delete_fn *user_delete);
|
|
||||||
|
#ifdef __clang__
|
||||||
|
/*
|
||||||
|
* Clang doesn't pay attention to the parameters defined in the
|
||||||
|
* function typedefs used here, so turn off spurious doc warnings.
|
||||||
|
* {
|
||||||
|
*/
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply call free on the userdata pointer.
|
* Simply call free on the userdata pointer.
|
||||||
@@ -212,7 +297,7 @@ extern void json_object_set_serializer(json_object *jso,
|
|||||||
* @param jso unused
|
* @param jso unused
|
||||||
* @param userdata the pointer that is passed to free().
|
* @param userdata the pointer that is passed to free().
|
||||||
*/
|
*/
|
||||||
json_object_delete_fn json_object_free_userdata;
|
JSON_EXPORT json_object_delete_fn json_object_free_userdata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the jso->_userdata string over to pb as-is.
|
* Copy the jso->_userdata string over to pb as-is.
|
||||||
@@ -223,8 +308,12 @@ json_object_delete_fn json_object_free_userdata;
|
|||||||
* @param level Ignored.
|
* @param level Ignored.
|
||||||
* @param flags Ignored.
|
* @param flags Ignored.
|
||||||
*/
|
*/
|
||||||
json_object_to_json_string_fn json_object_userdata_to_json_string;
|
JSON_EXPORT json_object_to_json_string_fn json_object_userdata_to_json_string;
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
/* } */
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
/* object type methods */
|
/* object type methods */
|
||||||
|
|
||||||
@@ -238,18 +327,23 @@ json_object_to_json_string_fn json_object_userdata_to_json_string;
|
|||||||
*
|
*
|
||||||
* @returns a json_object of type json_type_object
|
* @returns a json_object of type json_type_object
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_object(void);
|
JSON_EXPORT struct json_object *json_object_new_object(void);
|
||||||
|
|
||||||
/** Get the hashtable of a json_object of type json_type_object
|
/** Get the hashtable of a json_object of type json_type_object
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a linkhash
|
* @returns a linkhash
|
||||||
*/
|
*/
|
||||||
extern struct lh_table* json_object_get_object(struct json_object *obj);
|
JSON_EXPORT struct lh_table *json_object_get_object(const struct json_object *obj);
|
||||||
|
|
||||||
/** Get the size of an object in terms of the number of fields it has.
|
/** Get the size of an object in terms of the number of fields it has.
|
||||||
* @param obj the json_object whose length to return
|
* @param obj the json_object whose length to return
|
||||||
*/
|
*/
|
||||||
extern int json_object_object_length(struct json_object* obj);
|
JSON_EXPORT int json_object_object_length(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Get the sizeof (struct json_object).
|
||||||
|
* @returns a size_t with the sizeof (struct json_object)
|
||||||
|
*/
|
||||||
|
JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void));
|
||||||
|
|
||||||
/** Add an object field to a json_object of type json_type_object
|
/** Add an object field to a json_object of type json_type_object
|
||||||
*
|
*
|
||||||
@@ -266,11 +360,35 @@ extern int json_object_object_length(struct json_object* obj);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param key the object field name (a private copy will be duplicated)
|
* @param key the object field name (a private copy will be duplicated)
|
||||||
* @param val a json_object or NULL member to associate with the given field
|
* @param val a json_object or NULL member to associate with the given field
|
||||||
|
*
|
||||||
|
* @return On success, <code>0</code> is returned.
|
||||||
|
* On error, a negative value is returned.
|
||||||
*/
|
*/
|
||||||
extern void json_object_object_add(struct json_object* obj, const char *key,
|
JSON_EXPORT int json_object_object_add(struct json_object *obj, const char *key,
|
||||||
struct json_object *val);
|
struct json_object *val);
|
||||||
|
|
||||||
/** Get the json_object associate with a given object field
|
/** Add an object field to a json_object of type json_type_object
|
||||||
|
*
|
||||||
|
* The semantics are identical to json_object_object_add, except that an
|
||||||
|
* additional flag fields gives you more control over some detail aspects
|
||||||
|
* of processing. See the description of JSON_C_OBJECT_ADD_* flags for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param key the object field name (a private copy will be duplicated)
|
||||||
|
* @param val a json_object or NULL member to associate with the given field
|
||||||
|
* @param opts process-modifying options. To specify multiple options, use
|
||||||
|
* arithmetic or (OPT1|OPT2)
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_object_add_ex(struct json_object *obj, const char *const key,
|
||||||
|
struct json_object *const val, const unsigned opts);
|
||||||
|
|
||||||
|
/** Get the json_object associate with a given object field.
|
||||||
|
* Deprecated/discouraged: used json_object_object_get_ex instead.
|
||||||
|
*
|
||||||
|
* This returns NULL if the field is found but its value is null, or if
|
||||||
|
* the field is not found, or if obj is not a json_type_object. If you
|
||||||
|
* need to distinguish between these cases, use json_object_object_get_ex().
|
||||||
*
|
*
|
||||||
* *No* reference counts will be changed. There is no need to manually adjust
|
* *No* reference counts will be changed. There is no need to manually adjust
|
||||||
* reference counts through the json_object_put/json_object_get methods unless
|
* reference counts through the json_object_put/json_object_get methods unless
|
||||||
@@ -285,10 +403,9 @@ extern void json_object_object_add(struct json_object* obj, const char *key,
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param key the object field name
|
* @param key the object field name
|
||||||
* @returns the json_object associated with the given field name
|
* @returns the json_object associated with the given field name
|
||||||
* @deprecated Please use json_object_object_get_ex
|
|
||||||
*/
|
*/
|
||||||
THIS_FUNCTION_IS_DEPRECATED(extern struct json_object* json_object_object_get(struct json_object* obj,
|
JSON_EXPORT struct json_object *json_object_object_get(const struct json_object *obj,
|
||||||
const char *key));
|
const char *key);
|
||||||
|
|
||||||
/** Get the json_object associated with a given object field.
|
/** Get the json_object associated with a given object field.
|
||||||
*
|
*
|
||||||
@@ -308,8 +425,7 @@ THIS_FUNCTION_IS_DEPRECATED(extern struct json_object* json_object_object_get(st
|
|||||||
* It is safe to pass a NULL value.
|
* It is safe to pass a NULL value.
|
||||||
* @returns whether or not the key exists
|
* @returns whether or not the key exists
|
||||||
*/
|
*/
|
||||||
extern json_bool json_object_object_get_ex(struct json_object* obj,
|
JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object *obj, const char *key,
|
||||||
const char *key,
|
|
||||||
struct json_object **value);
|
struct json_object **value);
|
||||||
|
|
||||||
/** Delete the given json_object field
|
/** Delete the given json_object field
|
||||||
@@ -321,7 +437,7 @@ extern json_bool json_object_object_get_ex(struct json_object* obj,
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param key the object field name
|
* @param key the object field name
|
||||||
*/
|
*/
|
||||||
extern void json_object_object_del(struct json_object* obj, const char *key);
|
JSON_EXPORT void json_object_object_del(struct json_object *obj, const char *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate through all keys and values of an object.
|
* Iterate through all keys and values of an object.
|
||||||
@@ -339,68 +455,95 @@ extern void json_object_object_del(struct json_object* obj, const char *key);
|
|||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L
|
||||||
|
|
||||||
#define json_object_object_foreach(obj, key, val) \
|
#define json_object_object_foreach(obj, key, val) \
|
||||||
char *key; \
|
char *key = NULL; \
|
||||||
struct json_object *val __attribute__((__unused__)); \
|
struct json_object *val __attribute__((__unused__)) = NULL; \
|
||||||
for(struct lh_entry *entry ## key = json_object_get_object(obj)->head, *entry_next ## key = NULL; \
|
for (struct lh_entry *entry##key = json_object_get_object(obj)->head, \
|
||||||
({ if(entry ## key) { \
|
*entry_next##key = NULL; \
|
||||||
key = (char*)entry ## key->k; \
|
({ \
|
||||||
val = (struct json_object*)entry ## key->v; \
|
if (entry##key) \
|
||||||
|
{ \
|
||||||
|
key = (char *)lh_entry_k(entry##key); \
|
||||||
|
val = (struct json_object *)lh_entry_v(entry##key); \
|
||||||
entry_next##key = entry##key->next; \
|
entry_next##key = entry##key->next; \
|
||||||
} ; entry ## key; }); \
|
}; \
|
||||||
|
entry##key; \
|
||||||
|
}); \
|
||||||
entry##key = entry_next##key)
|
entry##key = entry_next##key)
|
||||||
|
|
||||||
#else /* ANSI C or MSC */
|
#else /* ANSI C or MSC */
|
||||||
|
|
||||||
#define json_object_object_foreach(obj, key, val) \
|
#define json_object_object_foreach(obj, key, val) \
|
||||||
char *key;\
|
char *key = NULL; \
|
||||||
struct json_object *val; \
|
struct json_object *val = NULL; \
|
||||||
struct lh_entry *entry##key; \
|
struct lh_entry *entry##key; \
|
||||||
struct lh_entry *entry_next##key = NULL; \
|
struct lh_entry *entry_next##key = NULL; \
|
||||||
for (entry##key = json_object_get_object(obj)->head; \
|
for (entry##key = json_object_get_object(obj)->head; \
|
||||||
(entry ## key ? ( \
|
(entry##key ? (key = (char *)lh_entry_k(entry##key), \
|
||||||
key = (char*)entry ## key->k, \
|
val = (struct json_object *)lh_entry_v(entry##key), \
|
||||||
val = (struct json_object*)entry ## key->v, \
|
entry_next##key = entry##key->next, entry##key) \
|
||||||
entry_next ## key = entry ## key->next, \
|
: 0); \
|
||||||
entry ## key) : 0); \
|
|
||||||
entry##key = entry_next##key)
|
entry##key = entry_next##key)
|
||||||
|
|
||||||
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L */
|
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L */
|
||||||
|
|
||||||
/** Iterate through all keys and values of an object (ANSI C Safe)
|
/** Iterate through all keys and values of an object (ANSI C Safe)
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param iter the object iterator
|
* @param iter the object iterator, use type json_object_iter
|
||||||
*/
|
*/
|
||||||
#define json_object_object_foreachC(obj, iter) \
|
#define json_object_object_foreachC(obj, iter) \
|
||||||
for(iter.entry = json_object_get_object(obj)->head; (iter.entry ? (iter.key = (char*)iter.entry->k, iter.val = (struct json_object*)iter.entry->v, iter.entry) : 0); iter.entry = iter.entry->next)
|
for (iter.entry = json_object_get_object(obj)->head; \
|
||||||
|
(iter.entry ? (iter.key = (char *)lh_entry_k(iter.entry), \
|
||||||
|
iter.val = (struct json_object *)lh_entry_v(iter.entry), iter.entry) \
|
||||||
|
: 0); \
|
||||||
|
iter.entry = iter.entry->next)
|
||||||
|
|
||||||
/* Array type methods */
|
/* Array type methods */
|
||||||
|
|
||||||
/** Create a new empty json_object of type json_type_array
|
/** Create a new empty json_object of type json_type_array
|
||||||
* @returns a json_object of type json_type_array
|
* @returns a json_object of type json_type_array
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_array(void);
|
JSON_EXPORT struct json_object *json_object_new_array(void);
|
||||||
|
|
||||||
/** Get the arraylist of a json_object of type json_type_array
|
/** Get the arraylist of a json_object of type json_type_array
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns an arraylist
|
* @returns an arraylist
|
||||||
*/
|
*/
|
||||||
extern struct array_list* json_object_get_array(struct json_object *obj);
|
JSON_EXPORT struct array_list *json_object_get_array(const struct json_object *obj);
|
||||||
|
|
||||||
/** Get the length of a json_object of type json_type_array
|
/** Get the length of a json_object of type json_type_array
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns an int
|
* @returns an int
|
||||||
*/
|
*/
|
||||||
extern int json_object_array_length(struct json_object *obj);
|
JSON_EXPORT size_t json_object_array_length(const struct json_object *obj);
|
||||||
|
|
||||||
/** Sorts the elements of jso of type json_type_array
|
/** Sorts the elements of jso of type json_type_array
|
||||||
*
|
*
|
||||||
* Pointers to the json_object pointers will be passed as the two arguments
|
* Pointers to the json_object pointers will be passed as the two arguments
|
||||||
* to @sort_fn
|
* to sort_fn
|
||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param jso the json_object instance
|
||||||
* @param sort_fn a sorting function
|
* @param sort_fn a sorting function
|
||||||
*/
|
*/
|
||||||
extern void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *));
|
JSON_EXPORT void json_object_array_sort(struct json_object *jso,
|
||||||
|
int (*sort_fn)(const void *, const void *));
|
||||||
|
|
||||||
|
/** Binary search a sorted array for a specified key object.
|
||||||
|
*
|
||||||
|
* It depends on your compare function what's sufficient as a key.
|
||||||
|
* Usually you create some dummy object with the parameter compared in
|
||||||
|
* it, to identify the right item you're actually looking for.
|
||||||
|
*
|
||||||
|
* @see json_object_array_sort() for hints on the compare function.
|
||||||
|
*
|
||||||
|
* @param key a dummy json_object with the right key
|
||||||
|
* @param jso the array object we're searching
|
||||||
|
* @param sort_fn the sort/compare function
|
||||||
|
*
|
||||||
|
* @return the wanted json_object instance
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *
|
||||||
|
json_object_array_bsearch(const struct json_object *key, const struct json_object *jso,
|
||||||
|
int (*sort_fn)(const void *, const void *));
|
||||||
|
|
||||||
/** Add an element to the end of a json_object of type json_type_array
|
/** Add an element to the end of a json_object of type json_type_array
|
||||||
*
|
*
|
||||||
@@ -411,8 +554,7 @@ extern void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param val the json_object to be added
|
* @param val the json_object to be added
|
||||||
*/
|
*/
|
||||||
extern int json_object_array_add(struct json_object *obj,
|
JSON_EXPORT int json_object_array_add(struct json_object *obj, struct json_object *val);
|
||||||
struct json_object *val);
|
|
||||||
|
|
||||||
/** Insert or replace an element at a specified index in an array (a json_object of type json_type_array)
|
/** Insert or replace an element at a specified index in an array (a json_object of type json_type_array)
|
||||||
*
|
*
|
||||||
@@ -429,38 +571,62 @@ extern int json_object_array_add(struct json_object *obj,
|
|||||||
* @param idx the index to insert the element at
|
* @param idx the index to insert the element at
|
||||||
* @param val the json_object to be added
|
* @param val the json_object to be added
|
||||||
*/
|
*/
|
||||||
extern int json_object_array_put_idx(struct json_object *obj, int idx,
|
JSON_EXPORT int json_object_array_put_idx(struct json_object *obj, size_t idx,
|
||||||
struct json_object *val);
|
struct json_object *val);
|
||||||
|
|
||||||
/** Get the element at specificed index of the array (a json_object of type json_type_array)
|
/** Get the element at specified index of the array (a json_object of type json_type_array)
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @param idx the index to get the element at
|
* @param idx the index to get the element at
|
||||||
* @returns the json_object at the specified index (or NULL)
|
* @returns the json_object at the specified index (or NULL)
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_array_get_idx(struct json_object *obj,
|
JSON_EXPORT struct json_object *json_object_array_get_idx(const struct json_object *obj,
|
||||||
int idx);
|
size_t idx);
|
||||||
|
|
||||||
|
/** Delete an elements from a specified index in an array (a json_object of type json_type_array)
|
||||||
|
*
|
||||||
|
* The reference count will be decremented for each of the deleted objects. If there
|
||||||
|
* are no more owners of an element that is being deleted, then the value is
|
||||||
|
* freed. Otherwise, the reference to the value will remain in memory.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param idx the index to start deleting elements at
|
||||||
|
* @param count the number of elements to delete
|
||||||
|
* @returns 0 if the elements were successfully deleted
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_array_del_idx(struct json_object *obj, size_t idx, size_t count);
|
||||||
|
|
||||||
/* json_bool type methods */
|
/* json_bool type methods */
|
||||||
|
|
||||||
/** Create a new empty json_object of type json_type_boolean
|
/** Create a new empty json_object of type json_type_boolean
|
||||||
* @param b a json_bool TRUE or FALSE (0 or 1)
|
* @param b a json_bool 1 or 0
|
||||||
* @returns a json_object of type json_type_boolean
|
* @returns a json_object of type json_type_boolean
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_boolean(json_bool b);
|
JSON_EXPORT struct json_object *json_object_new_boolean(json_bool b);
|
||||||
|
|
||||||
/** Get the json_bool value of a json_object
|
/** Get the json_bool value of a json_object
|
||||||
*
|
*
|
||||||
* The type is coerced to a json_bool if the passed object is not a json_bool.
|
* The type is coerced to a json_bool if the passed object is not a json_bool.
|
||||||
* integer and double objects will return FALSE if there value is zero
|
* integer and double objects will return 0 if there value is zero
|
||||||
* or TRUE otherwise. If the passed object is a string it will return
|
* or 1 otherwise. If the passed object is a string it will return
|
||||||
* TRUE if it has a non zero length. If any other object type is passed
|
* 1 if it has a non zero length. If any other object type is passed
|
||||||
* TRUE will be returned if the object is not NULL.
|
* 1 will be returned if the object is not NULL.
|
||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a json_bool
|
* @returns a json_bool
|
||||||
*/
|
*/
|
||||||
extern json_bool json_object_get_boolean(struct json_object *obj);
|
JSON_EXPORT json_bool json_object_get_boolean(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Set the json_bool value of a json_object
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_boolean and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_boolean
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_boolean(struct json_object *obj, json_bool new_value);
|
||||||
|
|
||||||
/* int type methods */
|
/* int type methods */
|
||||||
|
|
||||||
@@ -470,15 +636,19 @@ extern json_bool json_object_get_boolean(struct json_object *obj);
|
|||||||
* @param i the integer
|
* @param i the integer
|
||||||
* @returns a json_object of type json_type_int
|
* @returns a json_object of type json_type_int
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_int(int32_t i);
|
JSON_EXPORT struct json_object *json_object_new_int(int32_t i);
|
||||||
|
|
||||||
|
|
||||||
/** Create a new empty json_object of type json_type_int
|
/** Create a new empty json_object of type json_type_int
|
||||||
* @param i the integer
|
* @param i the integer
|
||||||
* @returns a json_object of type json_type_int
|
* @returns a json_object of type json_type_int
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_int64(int64_t i);
|
JSON_EXPORT struct json_object *json_object_new_int64(int64_t i);
|
||||||
|
|
||||||
|
/** Create a new empty json_object of type json_type_uint
|
||||||
|
* @param i the integer
|
||||||
|
* @returns a json_object of type json_type_uint
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_new_uint64(uint64_t i);
|
||||||
|
|
||||||
/** Get the int value of a json_object
|
/** Get the int value of a json_object
|
||||||
*
|
*
|
||||||
@@ -494,7 +664,35 @@ extern struct json_object* json_object_new_int64(int64_t i);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns an int
|
* @returns an int
|
||||||
*/
|
*/
|
||||||
extern int32_t json_object_get_int(struct json_object *obj);
|
JSON_EXPORT int32_t json_object_get_int(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Set the int value of a json_object
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_int and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_int
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_int(struct json_object *obj, int new_value);
|
||||||
|
|
||||||
|
/** Increment a json_type_int object by the given amount, which may be negative.
|
||||||
|
*
|
||||||
|
* If the type of obj is not json_type_int then 0 is returned with no further
|
||||||
|
* action taken.
|
||||||
|
* If the addition would result in a overflow, the object value
|
||||||
|
* is set to INT64_MAX.
|
||||||
|
* If the addition would result in a underflow, the object value
|
||||||
|
* is set to INT64_MIN.
|
||||||
|
* Neither overflow nor underflow affect the return value.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param val the value to add
|
||||||
|
* @returns 1 if the increment succeded, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_int_inc(struct json_object *obj, int64_t val);
|
||||||
|
|
||||||
/** Get the int value of a json_object
|
/** Get the int value of a json_object
|
||||||
*
|
*
|
||||||
@@ -509,16 +707,57 @@ extern int32_t json_object_get_int(struct json_object *obj);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns an int64
|
* @returns an int64
|
||||||
*/
|
*/
|
||||||
extern int64_t json_object_get_int64(struct json_object *obj);
|
JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Get the uint value of a json_object
|
||||||
|
*
|
||||||
|
* The type is coerced to a uint64 if the passed object is not a uint64.
|
||||||
|
* double objects will return their uint64 conversion. Strings will be
|
||||||
|
* parsed as an uint64. If no conversion exists then 0 is returned.
|
||||||
|
*
|
||||||
|
* NOTE: Set errno to 0 directly before a call to this function to determine
|
||||||
|
* whether or not conversion was successful (it does not clear the value for
|
||||||
|
* you).
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @returns an uint64
|
||||||
|
*/
|
||||||
|
JSON_EXPORT uint64_t json_object_get_uint64(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Set the int64_t value of a json_object
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_int and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_int
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_int64(struct json_object *obj, int64_t new_value);
|
||||||
|
|
||||||
|
/** Set the uint64_t value of a json_object
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_uint and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_uint
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_uint64(struct json_object *obj, uint64_t new_value);
|
||||||
|
|
||||||
/* double type methods */
|
/* double type methods */
|
||||||
|
|
||||||
/** Create a new empty json_object of type json_type_double
|
/** Create a new empty json_object of type json_type_double
|
||||||
|
*
|
||||||
|
* @see json_object_double_to_json_string() for how to set a custom format string.
|
||||||
|
*
|
||||||
* @param d the double
|
* @param d the double
|
||||||
* @returns a json_object of type json_type_double
|
* @returns a json_object of type json_type_double
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_double(double d);
|
JSON_EXPORT struct json_object *json_object_new_double(double d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new json_object of type json_type_double, using
|
* Create a new json_object of type json_type_double, using
|
||||||
@@ -528,20 +767,63 @@ extern struct json_object* json_object_new_double(double d);
|
|||||||
* inefficiently (e.g. 12.3 => "12.300000000000001") to be
|
* inefficiently (e.g. 12.3 => "12.300000000000001") to be
|
||||||
* serialized with the more convenient form.
|
* serialized with the more convenient form.
|
||||||
*
|
*
|
||||||
* Note: this is used by json_tokener_parse_ex() to allow for
|
* Notes:
|
||||||
|
*
|
||||||
|
* This is used by json_tokener_parse_ex() to allow for
|
||||||
* an exact re-serialization of a parsed object.
|
* an exact re-serialization of a parsed object.
|
||||||
*
|
*
|
||||||
* An equivalent sequence of calls is:
|
* The userdata field is used to store the string representation, so it
|
||||||
|
* can't be used for other data if this function is used.
|
||||||
|
*
|
||||||
|
* A roughly equivalent sequence of calls, with the difference being that
|
||||||
|
* the serialization function won't be reset by json_object_set_double(), is:
|
||||||
* @code
|
* @code
|
||||||
* jso = json_object_new_double(d);
|
* jso = json_object_new_double(d);
|
||||||
* json_object_set_serializer(d, json_object_userdata_to_json_string,
|
* json_object_set_serializer(jso, json_object_userdata_to_json_string,
|
||||||
* strdup(ds), json_object_free_userdata)
|
* strdup(ds), json_object_free_userdata);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @param d the numeric value of the double.
|
* @param d the numeric value of the double.
|
||||||
* @param ds the string representation of the double. This will be copied.
|
* @param ds the string representation of the double. This will be copied.
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_double_s(double d, const char *ds);
|
JSON_EXPORT struct json_object *json_object_new_double_s(double d, const char *ds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a global or thread-local json-c option, depending on whether
|
||||||
|
* JSON_C_OPTION_GLOBAL or JSON_C_OPTION_THREAD is passed.
|
||||||
|
* Thread-local options default to undefined, and inherit from the global
|
||||||
|
* value, even if the global value is changed after the thread is created.
|
||||||
|
* Attempting to set thread-local options when threading is not compiled in
|
||||||
|
* will result in an error. Be sure to check the return value.
|
||||||
|
*
|
||||||
|
* double_format is a "%g" printf format, such as "%.20g"
|
||||||
|
*
|
||||||
|
* @return -1 on errors, 0 on success.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_c_set_serialization_double_format(const char *double_format,
|
||||||
|
int global_or_thread);
|
||||||
|
|
||||||
|
/** Serialize a json_object of type json_type_double to a string.
|
||||||
|
*
|
||||||
|
* This function isn't meant to be called directly. Instead, you can set a
|
||||||
|
* custom format string for the serialization of this double using the
|
||||||
|
* following call (where "%.17g" actually is the default):
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* jso = json_object_new_double(d);
|
||||||
|
* json_object_set_serializer(jso, json_object_double_to_json_string,
|
||||||
|
* "%.17g", NULL);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @see printf(3) man page for format strings
|
||||||
|
*
|
||||||
|
* @param jso The json_type_double object that is serialized.
|
||||||
|
* @param pb The destination buffer.
|
||||||
|
* @param level Ignored.
|
||||||
|
* @param flags Ignored.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_double_to_json_string(struct json_object *jso, struct printbuf *pb,
|
||||||
|
int level, int flags);
|
||||||
|
|
||||||
/** Get the double floating point value of a json_object
|
/** Get the double floating point value of a json_object
|
||||||
*
|
*
|
||||||
@@ -566,8 +848,22 @@ extern struct json_object* json_object_new_double_s(double d, const char *ds);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a double floating point number
|
* @returns a double floating point number
|
||||||
*/
|
*/
|
||||||
extern double json_object_get_double(struct json_object *obj);
|
JSON_EXPORT double json_object_get_double(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Set the double value of a json_object
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_double and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_double
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* If the object was created with json_object_new_double_s(), the serialization
|
||||||
|
* function is reset to the default and the cached serialized value is cleared.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_double(struct json_object *obj, double new_value);
|
||||||
|
|
||||||
/* string type methods */
|
/* string type methods */
|
||||||
|
|
||||||
@@ -577,23 +873,39 @@ extern double json_object_get_double(struct json_object *obj);
|
|||||||
*
|
*
|
||||||
* @param s the string
|
* @param s the string
|
||||||
* @returns a json_object of type json_type_string
|
* @returns a json_object of type json_type_string
|
||||||
|
* @see json_object_new_string_len()
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_object_new_string(const char *s);
|
JSON_EXPORT struct json_object *json_object_new_string(const char *s);
|
||||||
|
|
||||||
extern struct json_object* json_object_new_string_len(const char *s, int len);
|
/** Create a new empty json_object of type json_type_string and allocate
|
||||||
|
* len characters for the new string.
|
||||||
|
*
|
||||||
|
* A copy of the string is made and the memory is managed by the json_object
|
||||||
|
*
|
||||||
|
* @param s the string
|
||||||
|
* @param len max length of the new string
|
||||||
|
* @returns a json_object of type json_type_string
|
||||||
|
* @see json_object_new_string()
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_new_string_len(const char *s, const int len);
|
||||||
|
|
||||||
/** Get the string value of a json_object
|
/** Get the string value of a json_object
|
||||||
*
|
*
|
||||||
* If the passed object is not of type json_type_string then the JSON
|
* If the passed object is of type json_type_null (i.e. obj == NULL),
|
||||||
* representation of the object is returned.
|
* NULL is returned.
|
||||||
|
*
|
||||||
|
* If the passed object of type json_type_string, the string contents
|
||||||
|
* are returned.
|
||||||
|
*
|
||||||
|
* Otherwise the JSON representation of the object is returned.
|
||||||
*
|
*
|
||||||
* The returned string memory is managed by the json_object and will
|
* The returned string memory is managed by the json_object and will
|
||||||
* be freed when the reference count of the json_object drops to zero.
|
* be freed when the reference count of the json_object drops to zero.
|
||||||
*
|
*
|
||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns a string
|
* @returns a string or NULL
|
||||||
*/
|
*/
|
||||||
extern const char* json_object_get_string(struct json_object *obj);
|
JSON_EXPORT const char *json_object_get_string(struct json_object *obj);
|
||||||
|
|
||||||
/** Get the string length of a json_object
|
/** Get the string length of a json_object
|
||||||
*
|
*
|
||||||
@@ -603,8 +915,104 @@ extern const char* json_object_get_string(struct json_object *obj);
|
|||||||
* @param obj the json_object instance
|
* @param obj the json_object instance
|
||||||
* @returns int
|
* @returns int
|
||||||
*/
|
*/
|
||||||
extern int json_object_get_string_len(struct json_object *obj);
|
JSON_EXPORT int json_object_get_string_len(const struct json_object *obj);
|
||||||
|
|
||||||
|
/** Set the string value of a json_object with zero terminated strings
|
||||||
|
* equivalent to json_object_set_string_len (obj, new_value, strlen(new_value))
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_string(json_object *obj, const char *new_value);
|
||||||
|
|
||||||
|
/** Set the string value of a json_object str
|
||||||
|
*
|
||||||
|
* The type of obj is checked to be a json_type_string and 0 is returned
|
||||||
|
* if it is not without any further actions. If type of obj is json_type_string
|
||||||
|
* the object value is changed to new_value
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance
|
||||||
|
* @param new_value the value to be set; Since string length is given in len this need not be zero terminated
|
||||||
|
* @param len the length of new_value
|
||||||
|
* @returns 1 if value is set correctly, 0 otherwise
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_set_string_len(json_object *obj, const char *new_value, int len);
|
||||||
|
|
||||||
|
/** This method exists only to provide a complementary function
|
||||||
|
* along the lines of the other json_object_new_* functions.
|
||||||
|
* It always returns NULL, and it is entirely acceptable to simply use NULL directly.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_new_null(void);
|
||||||
|
|
||||||
|
/** Check if two json_object's are equal
|
||||||
|
*
|
||||||
|
* If the passed objects are equal 1 will be returned.
|
||||||
|
* Equality is defined as follows:
|
||||||
|
* - json_objects of different types are never equal
|
||||||
|
* - json_objects of the same primitive type are equal if the
|
||||||
|
* c-representation of their value is equal
|
||||||
|
* - json-arrays are considered equal if all values at the same
|
||||||
|
* indices are equal (same order)
|
||||||
|
* - Complex json_objects are considered equal if all
|
||||||
|
* contained objects referenced by their key are equal,
|
||||||
|
* regardless their order.
|
||||||
|
*
|
||||||
|
* @param obj1 the first json_object instance
|
||||||
|
* @param obj2 the second json_object instance
|
||||||
|
* @returns whether both objects are equal or not
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_equal(struct json_object *obj1, struct json_object *obj2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a shallow copy of src into *dst as part of an overall json_object_deep_copy().
|
||||||
|
*
|
||||||
|
* If src is part of a containing object or array, parent will be non-NULL,
|
||||||
|
* and key or index will be provided.
|
||||||
|
* When shallow_copy is called *dst will be NULL, and must be non-NULL when it returns.
|
||||||
|
* src will never be NULL.
|
||||||
|
*
|
||||||
|
* If shallow_copy sets the serializer on an object, return 2 to indicate to
|
||||||
|
* json_object_deep_copy that it should not attempt to use the standard userdata
|
||||||
|
* copy function.
|
||||||
|
*
|
||||||
|
* @return On success 1 or 2, -1 on errors
|
||||||
|
*/
|
||||||
|
typedef int(json_c_shallow_copy_fn)(json_object *src, json_object *parent, const char *key,
|
||||||
|
size_t index, json_object **dst);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default shallow copy implementation for use with json_object_deep_copy().
|
||||||
|
* This simply calls the appropriate json_object_new_<type>() function and
|
||||||
|
* copies over the serializer function (_to_json_string internal field of
|
||||||
|
* the json_object structure) but not any _userdata or _user_delete values.
|
||||||
|
*
|
||||||
|
* If you're writing a custom shallow_copy function, perhaps because you're using
|
||||||
|
* your own custom serializer, you can call this first to create the new object
|
||||||
|
* before customizing it with json_object_set_serializer().
|
||||||
|
*
|
||||||
|
* @return 1 on success, -1 on errors, but never 2.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT json_c_shallow_copy_fn json_c_shallow_copy_default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the contents of the JSON object.
|
||||||
|
* The destination object must be initialized to NULL,
|
||||||
|
* to make sure this function won't overwrite an existing JSON object.
|
||||||
|
*
|
||||||
|
* This does roughly the same thing as
|
||||||
|
* `json_tokener_parse(json_object_get_string(src))`.
|
||||||
|
*
|
||||||
|
* @param src source JSON object whose contents will be copied
|
||||||
|
* @param dst pointer to the destination object where the contents of `src`;
|
||||||
|
* make sure this pointer is initialized to NULL
|
||||||
|
* @param shallow_copy an optional function to copy individual objects, needed
|
||||||
|
* when custom serializers are in use. See also
|
||||||
|
* json_object set_serializer.
|
||||||
|
*
|
||||||
|
* @returns 0 if the copy went well, -1 if an error occured during copy
|
||||||
|
* or if the destination pointer is non-NULL
|
||||||
|
*/
|
||||||
|
|
||||||
|
JSON_EXPORT int json_object_deep_copy(struct json_object *src, struct json_object **dst,
|
||||||
|
json_c_shallow_copy_fn *shallow_copy);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,13 +7,9 @@
|
|||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the MIT license. See COPYING for details.
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
*
|
*
|
||||||
* @brief json-c forces clients to use its private data
|
|
||||||
* structures for JSON Object iteration. This API
|
|
||||||
* implementation corrects that by abstracting the
|
|
||||||
* private json-c details.
|
|
||||||
*
|
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -63,8 +59,7 @@ static const void* kObjectEndIterValue = NULL;
|
|||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
struct json_object_iterator json_object_iter_begin(struct json_object *obj)
|
||||||
json_object_iter_begin(struct json_object* obj)
|
|
||||||
{
|
{
|
||||||
struct json_object_iterator iter;
|
struct json_object_iterator iter;
|
||||||
struct lh_table *pTable;
|
struct lh_table *pTable;
|
||||||
@@ -83,8 +78,7 @@ json_object_iter_begin(struct json_object* obj)
|
|||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
struct json_object_iterator json_object_iter_end(const struct json_object *obj)
|
||||||
json_object_iter_end(const struct json_object* obj)
|
|
||||||
{
|
{
|
||||||
struct json_object_iterator iter;
|
struct json_object_iterator iter;
|
||||||
|
|
||||||
@@ -99,47 +93,40 @@ json_object_iter_end(const struct json_object* obj)
|
|||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
void
|
void json_object_iter_next(struct json_object_iterator *iter)
|
||||||
json_object_iter_next(struct json_object_iterator* iter)
|
|
||||||
{
|
{
|
||||||
JASSERT(NULL != iter);
|
JASSERT(NULL != iter);
|
||||||
JASSERT(kObjectEndIterValue != iter->opaque_);
|
JASSERT(kObjectEndIterValue != iter->opaque_);
|
||||||
|
|
||||||
iter->opaque_ = ((struct lh_entry *)iter->opaque_)->next;
|
iter->opaque_ = ((const struct lh_entry *)iter->opaque_)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
const char*
|
const char *json_object_iter_peek_name(const struct json_object_iterator *iter)
|
||||||
json_object_iter_peek_name(const struct json_object_iterator* iter)
|
|
||||||
{
|
{
|
||||||
JASSERT(NULL != iter);
|
JASSERT(NULL != iter);
|
||||||
JASSERT(kObjectEndIterValue != iter->opaque_);
|
JASSERT(kObjectEndIterValue != iter->opaque_);
|
||||||
|
|
||||||
return (const char*)(((struct lh_entry *)iter->opaque_)->k);
|
return (const char *)(((const struct lh_entry *)iter->opaque_)->k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
struct json_object*
|
struct json_object *json_object_iter_peek_value(const struct json_object_iterator *iter)
|
||||||
json_object_iter_peek_value(const struct json_object_iterator* iter)
|
|
||||||
{
|
{
|
||||||
JASSERT(NULL != iter);
|
JASSERT(NULL != iter);
|
||||||
JASSERT(kObjectEndIterValue != iter->opaque_);
|
JASSERT(kObjectEndIterValue != iter->opaque_);
|
||||||
|
|
||||||
return (struct json_object*)(((struct lh_entry *)iter->opaque_)->v);
|
return (struct json_object *)lh_entry_v((const struct lh_entry *)iter->opaque_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
json_bool
|
json_bool json_object_iter_equal(const struct json_object_iterator *iter1,
|
||||||
json_object_iter_equal(const struct json_object_iterator* iter1,
|
|
||||||
const struct json_object_iterator *iter2)
|
const struct json_object_iterator *iter2)
|
||||||
{
|
{
|
||||||
JASSERT(NULL != iter1);
|
JASSERT(NULL != iter1);
|
||||||
@@ -148,12 +135,10 @@ json_object_iter_equal(const struct json_object_iterator* iter1,
|
|||||||
return (iter1->opaque_ == iter2->opaque_);
|
return (iter1->opaque_ == iter2->opaque_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
struct json_object_iterator json_object_iter_init_default(void)
|
||||||
json_object_iter_init_default(void)
|
|
||||||
{
|
{
|
||||||
struct json_object_iterator iter;
|
struct json_object_iterator iter;
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,11 @@
|
|||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the MIT license. See COPYING for details.
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
*
|
*
|
||||||
* @brief json-c forces clients to use its private data
|
* @brief An API for iterating over json_type_object objects,
|
||||||
* structures for JSON Object iteration. This API
|
* styled to be familiar to C++ programmers.
|
||||||
* corrects that by abstracting the private json-c
|
* Unlike json_object_object_foreach() and
|
||||||
* details.
|
* json_object_object_foreachC(), this avoids the need to expose
|
||||||
|
* json-c internals like lh_entry.
|
||||||
*
|
*
|
||||||
* API attributes: <br>
|
* API attributes: <br>
|
||||||
* * Thread-safe: NO<br>
|
* * Thread-safe: NO<br>
|
||||||
@@ -19,10 +20,10 @@
|
|||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef JSON_OBJECT_ITERATOR_H
|
#ifndef JSON_OBJECT_ITERATOR_H
|
||||||
#define JSON_OBJECT_ITERATOR_H
|
#define JSON_OBJECT_ITERATOR_H
|
||||||
|
|
||||||
|
#include "json_types.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -38,17 +39,16 @@ struct json_object_iter_info_;
|
|||||||
* The opaque iterator that references a name/value pair within
|
* The opaque iterator that references a name/value pair within
|
||||||
* a JSON Object instance or the "end" iterator value.
|
* a JSON Object instance or the "end" iterator value.
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator {
|
struct json_object_iterator
|
||||||
|
{
|
||||||
const void *opaque_;
|
const void *opaque_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* forward declaration of json-c's JSON value instance structure
|
* forward declaration of json-c's JSON value instance structure
|
||||||
*/
|
*/
|
||||||
struct json_object;
|
struct json_object;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes an iterator structure to a "default" value that
|
* Initializes an iterator structure to a "default" value that
|
||||||
* is convenient for initializing an iterator variable to a
|
* is convenient for initializing an iterator variable to a
|
||||||
@@ -71,8 +71,7 @@ struct json_object;
|
|||||||
*
|
*
|
||||||
* @return json_object_iterator
|
* @return json_object_iterator
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
JSON_EXPORT struct json_object_iterator json_object_iter_init_default(void);
|
||||||
json_object_iter_init_default(void);
|
|
||||||
|
|
||||||
/** Retrieves an iterator to the first pair of the JSON Object.
|
/** Retrieves an iterator to the first pair of the JSON Object.
|
||||||
*
|
*
|
||||||
@@ -105,8 +104,7 @@ json_object_iter_init_default(void);
|
|||||||
*
|
*
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
JSON_EXPORT struct json_object_iterator json_object_iter_begin(struct json_object *obj);
|
||||||
json_object_iter_begin(struct json_object* obj);
|
|
||||||
|
|
||||||
/** Retrieves the iterator that represents the position beyond the
|
/** Retrieves the iterator that represents the position beyond the
|
||||||
* last pair of the given JSON Object instance.
|
* last pair of the given JSON Object instance.
|
||||||
@@ -136,8 +134,7 @@ json_object_iter_begin(struct json_object* obj);
|
|||||||
* (i.e., NOT the last pair, but "beyond the last
|
* (i.e., NOT the last pair, but "beyond the last
|
||||||
* pair" value)
|
* pair" value)
|
||||||
*/
|
*/
|
||||||
struct json_object_iterator
|
JSON_EXPORT struct json_object_iterator json_object_iter_end(const struct json_object *obj);
|
||||||
json_object_iter_end(const struct json_object* obj);
|
|
||||||
|
|
||||||
/** Returns an iterator to the next pair, if any
|
/** Returns an iterator to the next pair, if any
|
||||||
*
|
*
|
||||||
@@ -154,9 +151,7 @@ json_object_iter_end(const struct json_object* obj);
|
|||||||
* of json_object_iter_end() for the same JSON Object
|
* of json_object_iter_end() for the same JSON Object
|
||||||
* instance.
|
* instance.
|
||||||
*/
|
*/
|
||||||
void
|
JSON_EXPORT void json_object_iter_next(struct json_object_iterator *iter);
|
||||||
json_object_iter_next(struct json_object_iterator* iter);
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns a const pointer to the name of the pair referenced
|
/** Returns a const pointer to the name of the pair referenced
|
||||||
* by the given iterator.
|
* by the given iterator.
|
||||||
@@ -173,9 +168,7 @@ json_object_iter_next(struct json_object_iterator* iter);
|
|||||||
* deleted or modified, and MUST NOT be modified or
|
* deleted or modified, and MUST NOT be modified or
|
||||||
* freed by the user.
|
* freed by the user.
|
||||||
*/
|
*/
|
||||||
const char*
|
JSON_EXPORT const char *json_object_iter_peek_name(const struct json_object_iterator *iter);
|
||||||
json_object_iter_peek_name(const struct json_object_iterator* iter);
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns a pointer to the json-c instance representing the
|
/** Returns a pointer to the json-c instance representing the
|
||||||
* value of the referenced name/value pair, without altering
|
* value of the referenced name/value pair, without altering
|
||||||
@@ -196,10 +189,9 @@ json_object_iter_peek_name(const struct json_object_iterator* iter);
|
|||||||
* the JSON Null value as a NULL json_object instance
|
* the JSON Null value as a NULL json_object instance
|
||||||
* pointer.
|
* pointer.
|
||||||
*/
|
*/
|
||||||
struct json_object*
|
JSON_EXPORT struct json_object *
|
||||||
json_object_iter_peek_value(const struct json_object_iterator *iter);
|
json_object_iter_peek_value(const struct json_object_iterator *iter);
|
||||||
|
|
||||||
|
|
||||||
/** Tests two iterators for equality. Typically used to test
|
/** Tests two iterators for equality. Typically used to test
|
||||||
* for end of iteration by comparing an iterator to the
|
* for end of iteration by comparing an iterator to the
|
||||||
* corresponding "end" iterator (that was derived from the same
|
* corresponding "end" iterator (that was derived from the same
|
||||||
@@ -226,14 +218,11 @@ json_object_iter_peek_value(const struct json_object_iterator* iter);
|
|||||||
* reference the same name/value pair or are both at
|
* reference the same name/value pair or are both at
|
||||||
* "end"); zero if they are not equal.
|
* "end"); zero if they are not equal.
|
||||||
*/
|
*/
|
||||||
json_bool
|
JSON_EXPORT json_bool json_object_iter_equal(const struct json_object_iterator *iter1,
|
||||||
json_object_iter_equal(const struct json_object_iterator* iter1,
|
|
||||||
const struct json_object_iterator *iter2);
|
const struct json_object_iterator *iter2);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* JSON_OBJECT_ITERATOR_H */
|
#endif /* JSON_OBJECT_ITERATOR_H */
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
#ifndef _json_object_private_h_
|
#ifndef _json_object_private_h_
|
||||||
#define _json_object_private_h_
|
#define _json_object_private_h_
|
||||||
|
|
||||||
@@ -16,30 +20,87 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (json_object_private_delete_fn)(struct json_object *o);
|
struct json_object;
|
||||||
|
#include "json_inttypes.h"
|
||||||
|
#include "json_types.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif /* HAVE_UNISTD_H */
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <BaseTsd.h>
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* json object int type, support extension*/
|
||||||
|
typedef enum json_object_int_type
|
||||||
|
{
|
||||||
|
json_object_int_type_int64,
|
||||||
|
json_object_int_type_uint64
|
||||||
|
} json_object_int_type;
|
||||||
|
|
||||||
struct json_object
|
struct json_object
|
||||||
{
|
{
|
||||||
enum json_type o_type;
|
enum json_type o_type;
|
||||||
json_object_private_delete_fn *_delete;
|
uint32_t _ref_count;
|
||||||
json_object_to_json_string_fn *_to_json_string;
|
json_object_to_json_string_fn *_to_json_string;
|
||||||
int _ref_count;
|
|
||||||
struct printbuf *_pb;
|
struct printbuf *_pb;
|
||||||
union data {
|
|
||||||
json_bool c_boolean;
|
|
||||||
double c_double;
|
|
||||||
int64_t c_int64;
|
|
||||||
struct lh_table *c_object;
|
|
||||||
struct array_list *c_array;
|
|
||||||
struct {
|
|
||||||
char *str;
|
|
||||||
int len;
|
|
||||||
} c_string;
|
|
||||||
} o;
|
|
||||||
json_object_delete_fn *_user_delete;
|
json_object_delete_fn *_user_delete;
|
||||||
void *_userdata;
|
void *_userdata;
|
||||||
|
// Actually longer, always malloc'd as some more-specific type.
|
||||||
|
// The rest of a struct json_object_${o_type} follows
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct json_object_object
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
struct lh_table *c_object;
|
||||||
|
};
|
||||||
|
struct json_object_array
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
struct array_list *c_array;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct json_object_boolean
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
json_bool c_boolean;
|
||||||
|
};
|
||||||
|
struct json_object_double
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
double c_double;
|
||||||
|
};
|
||||||
|
struct json_object_int
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
enum json_object_int_type cint_type;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
int64_t c_int64;
|
||||||
|
uint64_t c_uint64;
|
||||||
|
} cint;
|
||||||
|
};
|
||||||
|
struct json_object_string
|
||||||
|
{
|
||||||
|
struct json_object base;
|
||||||
|
ssize_t len; // Signed b/c negative lengths indicate data is a pointer
|
||||||
|
// Consider adding an "alloc" field here, if json_object_set_string calls
|
||||||
|
// to expand the length of a string are common operations to perform.
|
||||||
|
union
|
||||||
|
{
|
||||||
|
char idata[1]; // Immediate data. Actually longer
|
||||||
|
char *pdata; // Only when len < 0
|
||||||
|
} c_string;
|
||||||
|
};
|
||||||
|
|
||||||
|
void _json_c_set_last_err(const char *err_fmt, ...);
|
||||||
|
|
||||||
|
extern const char *json_number_chars;
|
||||||
|
extern const char *json_hex_chars;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
356
json_pointer.c
Normal file
356
json_pointer.c
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Alexandru Ardelean.
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "strerror_override.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "json_pointer.h"
|
||||||
|
#include "strdup_compat.h"
|
||||||
|
#include "vasprintf_compat.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaScript Object Notation (JSON) Pointer
|
||||||
|
* RFC 6901 - https://tools.ietf.org/html/rfc6901
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void string_replace_all_occurrences_with_char(char *s, const char *occur, char repl_char)
|
||||||
|
{
|
||||||
|
int slen = strlen(s);
|
||||||
|
int skip = strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */
|
||||||
|
char *p = s;
|
||||||
|
while ((p = strstr(p, occur)))
|
||||||
|
{
|
||||||
|
*p = repl_char;
|
||||||
|
p++;
|
||||||
|
slen -= skip;
|
||||||
|
memmove(p, (p + skip), slen - (p - s) + 1); /* includes null char too */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx)
|
||||||
|
{
|
||||||
|
int i, len = strlen(path);
|
||||||
|
/* this code-path optimizes a bit, for when we reference the 0-9 index range
|
||||||
|
* in a JSON array and because leading zeros not allowed
|
||||||
|
*/
|
||||||
|
if (len == 1)
|
||||||
|
{
|
||||||
|
if (isdigit((unsigned char)path[0]))
|
||||||
|
{
|
||||||
|
*idx = (path[0] - '0');
|
||||||
|
goto check_oob;
|
||||||
|
}
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* leading zeros not allowed per RFC */
|
||||||
|
if (path[0] == '0')
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* RFC states base-10 decimals */
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (!isdigit((unsigned char)path[i]))
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*idx = strtol(path, NULL, 10);
|
||||||
|
if (*idx < 0)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
check_oob:
|
||||||
|
len = json_object_array_length(jo);
|
||||||
|
if (*idx >= len)
|
||||||
|
{
|
||||||
|
errno = ENOENT;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int json_pointer_get_single_path(struct json_object *obj, char *path,
|
||||||
|
struct json_object **value)
|
||||||
|
{
|
||||||
|
if (json_object_is_type(obj, json_type_array))
|
||||||
|
{
|
||||||
|
int32_t idx;
|
||||||
|
if (!is_valid_index(obj, path, &idx))
|
||||||
|
return -1;
|
||||||
|
obj = json_object_array_get_idx(obj, idx);
|
||||||
|
if (obj)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
*value = obj;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Entry not found */
|
||||||
|
errno = ENOENT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RFC states that we first must eval all ~1 then all ~0 */
|
||||||
|
string_replace_all_occurrences_with_char(path, "~1", '/');
|
||||||
|
string_replace_all_occurrences_with_char(path, "~0", '~');
|
||||||
|
|
||||||
|
if (!json_object_object_get_ex(obj, path, value))
|
||||||
|
{
|
||||||
|
errno = ENOENT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int json_pointer_set_single_path(struct json_object *parent, const char *path,
|
||||||
|
struct json_object *value)
|
||||||
|
{
|
||||||
|
if (json_object_is_type(parent, json_type_array))
|
||||||
|
{
|
||||||
|
int32_t idx;
|
||||||
|
/* RFC (Chapter 4) states that '-' may be used to add new elements to an array */
|
||||||
|
if (path[0] == '-' && path[1] == '\0')
|
||||||
|
return json_object_array_add(parent, value);
|
||||||
|
if (!is_valid_index(parent, path, &idx))
|
||||||
|
return -1;
|
||||||
|
return json_object_array_put_idx(parent, idx, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* path replacements should have been done in json_pointer_get_single_path(),
|
||||||
|
* and we should still be good here
|
||||||
|
*/
|
||||||
|
if (json_object_is_type(parent, json_type_object))
|
||||||
|
return json_object_object_add(parent, path, value);
|
||||||
|
|
||||||
|
/* Getting here means that we tried to "dereference" a primitive JSON type
|
||||||
|
* (like string, int, bool).i.e. add a sub-object to it
|
||||||
|
*/
|
||||||
|
errno = ENOENT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int json_pointer_get_recursive(struct json_object *obj, char *path,
|
||||||
|
struct json_object **value)
|
||||||
|
{
|
||||||
|
char *endp;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* All paths (on each recursion level must have a leading '/' */
|
||||||
|
if (path[0] != '/')
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
path++;
|
||||||
|
|
||||||
|
endp = strchr(path, '/');
|
||||||
|
if (endp)
|
||||||
|
*endp = '\0';
|
||||||
|
|
||||||
|
/* If we err-ed here, return here */
|
||||||
|
if ((rc = json_pointer_get_single_path(obj, path, &obj)))
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if (endp)
|
||||||
|
{
|
||||||
|
/* Put the slash back, so that the sanity check passes on next recursion level */
|
||||||
|
*endp = '/';
|
||||||
|
return json_pointer_get_recursive(obj, endp, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We should be at the end of the recursion here */
|
||||||
|
if (value)
|
||||||
|
*value = obj;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int json_pointer_get(struct json_object *obj, const char *path, struct json_object **res)
|
||||||
|
{
|
||||||
|
char *path_copy = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!obj || !path)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[0] == '\0')
|
||||||
|
{
|
||||||
|
if (res)
|
||||||
|
*res = obj;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pass a working copy to the recursive call */
|
||||||
|
if (!(path_copy = strdup(path)))
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
rc = json_pointer_get_recursive(obj, path_copy, res);
|
||||||
|
free(path_copy);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int json_pointer_getf(struct json_object *obj, struct json_object **res, const char *path_fmt, ...)
|
||||||
|
{
|
||||||
|
char *path_copy = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
if (!obj || !path_fmt)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(args, path_fmt);
|
||||||
|
rc = vasprintf(&path_copy, path_fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if (path_copy[0] == '\0')
|
||||||
|
{
|
||||||
|
if (res)
|
||||||
|
*res = obj;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = json_pointer_get_recursive(obj, path_copy, res);
|
||||||
|
out:
|
||||||
|
free(path_copy);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int json_pointer_set(struct json_object **obj, const char *path, struct json_object *value)
|
||||||
|
{
|
||||||
|
const char *endp;
|
||||||
|
char *path_copy = NULL;
|
||||||
|
struct json_object *set = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!obj || !path)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[0] == '\0')
|
||||||
|
{
|
||||||
|
json_object_put(*obj);
|
||||||
|
*obj = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path[0] != '/')
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If there's only 1 level to set, stop here */
|
||||||
|
if ((endp = strrchr(path, '/')) == path)
|
||||||
|
{
|
||||||
|
path++;
|
||||||
|
return json_pointer_set_single_path(*obj, path, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pass a working copy to the recursive call */
|
||||||
|
if (!(path_copy = strdup(path)))
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
path_copy[endp - path] = '\0';
|
||||||
|
rc = json_pointer_get_recursive(*obj, path_copy, &set);
|
||||||
|
free(path_copy);
|
||||||
|
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
endp++;
|
||||||
|
return json_pointer_set_single_path(set, endp, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
int json_pointer_setf(struct json_object **obj, struct json_object *value, const char *path_fmt,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
char *endp;
|
||||||
|
char *path_copy = NULL;
|
||||||
|
struct json_object *set = NULL;
|
||||||
|
va_list args;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (!obj || !path_fmt)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pass a working copy to the recursive call */
|
||||||
|
va_start(args, path_fmt);
|
||||||
|
rc = vasprintf(&path_copy, path_fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if (path_copy[0] == '\0')
|
||||||
|
{
|
||||||
|
json_object_put(*obj);
|
||||||
|
*obj = value;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path_copy[0] != '/')
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
rc = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If there's only 1 level to set, stop here */
|
||||||
|
if ((endp = strrchr(path_copy, '/')) == path_copy)
|
||||||
|
{
|
||||||
|
set = *obj;
|
||||||
|
goto set_single_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
*endp = '\0';
|
||||||
|
rc = json_pointer_get_recursive(*obj, path_copy, &set);
|
||||||
|
|
||||||
|
if (rc)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
set_single_path:
|
||||||
|
endp++;
|
||||||
|
rc = json_pointer_set_single_path(set, endp, value);
|
||||||
|
out:
|
||||||
|
free(path_copy);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
123
json_pointer.h
Normal file
123
json_pointer.h
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Alexadru Ardelean.
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief JSON Pointer (RFC 6901) implementation for retrieving
|
||||||
|
* objects from a json-c object tree.
|
||||||
|
*/
|
||||||
|
#ifndef _json_pointer_h_
|
||||||
|
#define _json_pointer_h_
|
||||||
|
|
||||||
|
#include "json_object.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a JSON sub-object from inside another JSON object
|
||||||
|
* using the JSON pointer notation as defined in RFC 6901
|
||||||
|
* https://tools.ietf.org/html/rfc6901
|
||||||
|
*
|
||||||
|
* The returned JSON sub-object is equivalent to parsing manually the
|
||||||
|
* 'obj' JSON tree ; i.e. it's not a new object that is created, but rather
|
||||||
|
* a pointer inside the JSON tree.
|
||||||
|
*
|
||||||
|
* Internally, this is equivalent to doing a series of 'json_object_object_get()'
|
||||||
|
* and 'json_object_array_get_idx()' along the given 'path'.
|
||||||
|
*
|
||||||
|
* Note that the 'path' string supports 'printf()' type arguments, so, whatever
|
||||||
|
* is added after the 'res' param will be treated as an argument for 'path'
|
||||||
|
* Example: json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar)
|
||||||
|
* This means, that you need to escape '%' with '%%' (just like in printf())
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance/tree from where to retrieve sub-objects
|
||||||
|
* @param path a (RFC6901) string notation for the sub-object to retrieve
|
||||||
|
* @param res a pointer that stores a reference to the json_object
|
||||||
|
* associated with the given path
|
||||||
|
*
|
||||||
|
* @return negative if an error (or not found), or 0 if succeeded
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_pointer_get(struct json_object *obj, const char *path,
|
||||||
|
struct json_object **res);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a variant of 'json_pointer_get()' that supports printf() style arguments.
|
||||||
|
*
|
||||||
|
* Example: json_pointer_getf(obj, res, "/foo/%d/%s", 0, bak)
|
||||||
|
* This also means that you need to escape '%' with '%%' (just like in printf())
|
||||||
|
*
|
||||||
|
* Please take into consideration all recommended 'printf()' format security
|
||||||
|
* aspects when using this function.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance/tree to which to add a sub-object
|
||||||
|
* @param res a pointer that stores a reference to the json_object
|
||||||
|
* associated with the given path
|
||||||
|
* @param path_fmt a printf() style format for the path
|
||||||
|
*
|
||||||
|
* @return negative if an error (or not found), or 0 if succeeded
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_pointer_getf(struct json_object *obj, struct json_object **res,
|
||||||
|
const char *path_fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets JSON object 'value' in the 'obj' tree at the location specified
|
||||||
|
* by the 'path'. 'path' is JSON pointer notation as defined in RFC 6901
|
||||||
|
* https://tools.ietf.org/html/rfc6901
|
||||||
|
*
|
||||||
|
* Note that 'obj' is a double pointer, mostly for the "" (empty string)
|
||||||
|
* case, where the entire JSON object would be replaced by 'value'.
|
||||||
|
* In the case of the "" path, the object at '*obj' will have it's refcount
|
||||||
|
* decremented with 'json_object_put()' and the 'value' object will be assigned to it.
|
||||||
|
*
|
||||||
|
* For other cases (JSON sub-objects) ownership of 'value' will be transferred into
|
||||||
|
* '*obj' via 'json_object_object_add()' & 'json_object_array_put_idx()', so the
|
||||||
|
* only time the refcount should be decremented for 'value' is when the return value of
|
||||||
|
* 'json_pointer_set()' is negative (meaning the 'value' object did not get set into '*obj').
|
||||||
|
*
|
||||||
|
* That also implies that 'json_pointer_set()' does not do any refcount incrementing.
|
||||||
|
* (Just that single decrement that was mentioned above).
|
||||||
|
*
|
||||||
|
* Note that the 'path' string supports 'printf()' type arguments, so, whatever
|
||||||
|
* is added after the 'value' param will be treated as an argument for 'path'
|
||||||
|
* Example: json_pointer_set(obj, "/foo/%d/%s", value, 0, bak)
|
||||||
|
* This means, that you need to escape '%' with '%%' (just like in printf())
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance/tree to which to add a sub-object
|
||||||
|
* @param path a (RFC6901) string notation for the sub-object to set in the tree
|
||||||
|
* @param value object to set at path
|
||||||
|
*
|
||||||
|
* @return negative if an error (or not found), or 0 if succeeded
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_pointer_set(struct json_object **obj, const char *path,
|
||||||
|
struct json_object *value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a variant of 'json_pointer_set()' that supports printf() style arguments.
|
||||||
|
*
|
||||||
|
* Example: json_pointer_setf(obj, value, "/foo/%d/%s", 0, bak)
|
||||||
|
* This also means that you need to escape '%' with '%%' (just like in printf())
|
||||||
|
*
|
||||||
|
* Please take into consideration all recommended 'printf()' format security
|
||||||
|
* aspects when using this function.
|
||||||
|
*
|
||||||
|
* @param obj the json_object instance/tree to which to add a sub-object
|
||||||
|
* @param value object to set at path
|
||||||
|
* @param path_fmt a printf() style format for the path
|
||||||
|
*
|
||||||
|
* @return negative if an error (or not found), or 0 if succeeded
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_pointer_setf(struct json_object **obj, struct json_object *value,
|
||||||
|
const char *path_fmt, ...);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
770
json_tokener.c
770
json_tokener.c
File diff suppressed because it is too large
Load Diff
128
json_tokener.h
128
json_tokener.h
@@ -9,17 +9,22 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Methods to parse an input string into a tree of json_object objects.
|
||||||
|
*/
|
||||||
#ifndef _json_tokener_h_
|
#ifndef _json_tokener_h_
|
||||||
#define _json_tokener_h_
|
#define _json_tokener_h_
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum json_tokener_error {
|
enum json_tokener_error
|
||||||
|
{
|
||||||
json_tokener_success,
|
json_tokener_success,
|
||||||
json_tokener_continue,
|
json_tokener_continue,
|
||||||
json_tokener_error_depth,
|
json_tokener_error_depth,
|
||||||
@@ -34,10 +39,15 @@ enum json_tokener_error {
|
|||||||
json_tokener_error_parse_object_value_sep,
|
json_tokener_error_parse_object_value_sep,
|
||||||
json_tokener_error_parse_string,
|
json_tokener_error_parse_string,
|
||||||
json_tokener_error_parse_comment,
|
json_tokener_error_parse_comment,
|
||||||
|
json_tokener_error_parse_utf8_string,
|
||||||
json_tokener_error_size
|
json_tokener_error_size
|
||||||
};
|
};
|
||||||
|
|
||||||
enum json_tokener_state {
|
/**
|
||||||
|
* @deprecated Don't use this outside of json_tokener.c, it will be made private in a future release.
|
||||||
|
*/
|
||||||
|
enum json_tokener_state
|
||||||
|
{
|
||||||
json_tokener_state_eatws,
|
json_tokener_state_eatws,
|
||||||
json_tokener_state_start,
|
json_tokener_state_start,
|
||||||
json_tokener_state_finish,
|
json_tokener_state_finish,
|
||||||
@@ -65,6 +75,9 @@ enum json_tokener_state {
|
|||||||
json_tokener_state_inf
|
json_tokener_state_inf
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Don't use this outside of json_tokener.c, it will be made private in a future release.
|
||||||
|
*/
|
||||||
struct json_tokener_srec
|
struct json_tokener_srec
|
||||||
{
|
{
|
||||||
enum json_tokener_state state, saved_state;
|
enum json_tokener_state state, saved_state;
|
||||||
@@ -75,11 +88,28 @@ struct json_tokener_srec
|
|||||||
|
|
||||||
#define JSON_TOKENER_DEFAULT_DEPTH 32
|
#define JSON_TOKENER_DEFAULT_DEPTH 32
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal state of the json parser.
|
||||||
|
* Do not access any fields of this structure directly.
|
||||||
|
* Its definition is published due to historical limitations
|
||||||
|
* in the json tokener API, and will be changed to be an opaque
|
||||||
|
* type in the future.
|
||||||
|
*/
|
||||||
struct json_tokener
|
struct json_tokener
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @deprecated Do not access any of these fields outside of json_tokener.c
|
||||||
|
*/
|
||||||
char *str;
|
char *str;
|
||||||
struct printbuf *pb;
|
struct printbuf *pb;
|
||||||
int max_depth, depth, is_double, st_pos, char_offset;
|
int max_depth, depth, is_double, st_pos;
|
||||||
|
/**
|
||||||
|
* @deprecated See json_tokener_get_parse_end() instead.
|
||||||
|
*/
|
||||||
|
int char_offset;
|
||||||
|
/**
|
||||||
|
* @deprecated See json_tokener_get_error() instead.
|
||||||
|
*/
|
||||||
enum json_tokener_error err;
|
enum json_tokener_error err;
|
||||||
unsigned int ucs_char;
|
unsigned int ucs_char;
|
||||||
char quote_char;
|
char quote_char;
|
||||||
@@ -87,25 +117,71 @@ struct json_tokener
|
|||||||
int flags;
|
int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the offset of the byte after the last byte parsed
|
||||||
|
* relative to the start of the most recent string passed in
|
||||||
|
* to json_tokener_parse_ex(). i.e. this is where parsing
|
||||||
|
* would start again if the input contains another JSON object
|
||||||
|
* after the currently parsed one.
|
||||||
|
*
|
||||||
|
* Note that when multiple parse calls are issued, this is *not* the
|
||||||
|
* total number of characters parsed.
|
||||||
|
*
|
||||||
|
* In the past this would have been accessed as tok->char_offset.
|
||||||
|
*
|
||||||
|
* See json_tokener_parse_ex() for an example of how to use this.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT size_t json_tokener_get_parse_end(struct json_tokener *tok);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Unused in json-c code
|
||||||
|
*/
|
||||||
|
typedef struct json_tokener json_tokener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Be strict when parsing JSON input. Use caution with
|
* Be strict when parsing JSON input. Use caution with
|
||||||
* this flag as what is considered valid may become more
|
* this flag as what is considered valid may become more
|
||||||
* restrictive from one release to the next, causing your
|
* restrictive from one release to the next, causing your
|
||||||
* code to fail on previously working input.
|
* code to fail on previously working input.
|
||||||
*
|
*
|
||||||
|
* Note that setting this will also effectively disable parsing
|
||||||
|
* of multiple json objects in a single character stream
|
||||||
|
* (e.g. {"foo":123}{"bar":234}); if you want to allow that
|
||||||
|
* also set JSON_TOKENER_ALLOW_TRAILING_CHARS
|
||||||
|
*
|
||||||
* This flag is not set by default.
|
* This flag is not set by default.
|
||||||
*
|
*
|
||||||
* @see json_tokener_set_flags()
|
* @see json_tokener_set_flags()
|
||||||
*/
|
*/
|
||||||
#define JSON_TOKENER_STRICT 0x01
|
#define JSON_TOKENER_STRICT 0x01
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use with JSON_TOKENER_STRICT to allow trailing characters after the
|
||||||
|
* first parsed object.
|
||||||
|
*
|
||||||
|
* @see json_tokener_set_flags()
|
||||||
|
*/
|
||||||
|
#define JSON_TOKENER_ALLOW_TRAILING_CHARS 0x02
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cause json_tokener_parse_ex() to validate that input is UTF8.
|
||||||
|
* If this flag is specified and validation fails, then
|
||||||
|
* json_tokener_get_error(tok) will return
|
||||||
|
* json_tokener_error_parse_utf8_string
|
||||||
|
*
|
||||||
|
* This flag is not set by default.
|
||||||
|
*
|
||||||
|
* @see json_tokener_set_flags()
|
||||||
|
*/
|
||||||
|
#define JSON_TOKENER_VALIDATE_UTF8 0x10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an error previously returned by json_tokener_get_error(),
|
* Given an error previously returned by json_tokener_get_error(),
|
||||||
* return a human readable description of the error.
|
* return a human readable description of the error.
|
||||||
*
|
*
|
||||||
* @return a generic error message is returned if an invalid error value is provided.
|
* @return a generic error message is returned if an invalid error value is provided.
|
||||||
*/
|
*/
|
||||||
const char *json_tokener_error_desc(enum json_tokener_error jerr);
|
JSON_EXPORT const char *json_tokener_error_desc(enum json_tokener_error jerr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the error caused by the last call to json_tokener_parse_ex(),
|
* Retrieve the error caused by the last call to json_tokener_parse_ex(),
|
||||||
@@ -114,21 +190,22 @@ const char *json_tokener_error_desc(enum json_tokener_error jerr);
|
|||||||
* When parsing a JSON string in pieces, if the tokener is in the middle
|
* When parsing a JSON string in pieces, if the tokener is in the middle
|
||||||
* of parsing this will return json_tokener_continue.
|
* of parsing this will return json_tokener_continue.
|
||||||
*
|
*
|
||||||
* See also json_tokener_error_desc().
|
* @see json_tokener_error_desc().
|
||||||
*/
|
*/
|
||||||
enum json_tokener_error json_tokener_get_error(struct json_tokener *tok);
|
JSON_EXPORT enum json_tokener_error json_tokener_get_error(struct json_tokener *tok);
|
||||||
|
|
||||||
extern struct json_tokener* json_tokener_new(void);
|
JSON_EXPORT struct json_tokener *json_tokener_new(void);
|
||||||
extern struct json_tokener* json_tokener_new_ex(int depth);
|
JSON_EXPORT struct json_tokener *json_tokener_new_ex(int depth);
|
||||||
extern void json_tokener_free(struct json_tokener *tok);
|
JSON_EXPORT void json_tokener_free(struct json_tokener *tok);
|
||||||
extern void json_tokener_reset(struct json_tokener *tok);
|
JSON_EXPORT void json_tokener_reset(struct json_tokener *tok);
|
||||||
extern struct json_object* json_tokener_parse(const char *str);
|
JSON_EXPORT struct json_object *json_tokener_parse(const char *str);
|
||||||
extern struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error);
|
JSON_EXPORT struct json_object *json_tokener_parse_verbose(const char *str,
|
||||||
|
enum json_tokener_error *error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set flags that control how parsing will be done.
|
* Set flags that control how parsing will be done.
|
||||||
*/
|
*/
|
||||||
extern void json_tokener_set_flags(struct json_tokener *tok, int flags);
|
JSON_EXPORT void json_tokener_set_flags(struct json_tokener *tok, int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a string and return a non-NULL json_object if a valid JSON value
|
* Parse a string and return a non-NULL json_object if a valid JSON value
|
||||||
@@ -136,28 +213,29 @@ extern void json_tokener_set_flags(struct json_tokener *tok, int flags);
|
|||||||
* it can also be a string, number or boolean value.
|
* it can also be a string, number or boolean value.
|
||||||
*
|
*
|
||||||
* A partial JSON string can be parsed. If the parsing is incomplete,
|
* A partial JSON string can be parsed. If the parsing is incomplete,
|
||||||
* NULL will be returned and json_tokener_get_error() will be return
|
* NULL will be returned and json_tokener_get_error() will return
|
||||||
* json_tokener_continue.
|
* json_tokener_continue.
|
||||||
* json_tokener_parse_ex() can then be called with additional bytes in str
|
* json_tokener_parse_ex() can then be called with additional bytes in str
|
||||||
* to continue the parsing.
|
* to continue the parsing.
|
||||||
*
|
*
|
||||||
* If json_tokener_parse_ex() returns NULL and the error anything other than
|
* If json_tokener_parse_ex() returns NULL and the error is anything other than
|
||||||
* json_tokener_continue, a fatal error has occurred and parsing must be
|
* json_tokener_continue, a fatal error has occurred and parsing must be
|
||||||
* halted. Then tok object must not be re-used until json_tokener_reset() is
|
* halted. Then, the tok object must not be reused until json_tokener_reset() is
|
||||||
* called.
|
* called.
|
||||||
*
|
*
|
||||||
* When a valid JSON value is parsed, a non-NULL json_object will be
|
* When a valid JSON value is parsed, a non-NULL json_object will be
|
||||||
* returned. Also, json_tokener_get_error() will return json_tokener_success.
|
* returned, with a reference count of one which belongs to the caller. Also,
|
||||||
* Be sure to check the type with json_object_is_type() or
|
* json_tokener_get_error() will return json_tokener_success. Be sure to check
|
||||||
* json_object_get_type() before using the object.
|
* the type with json_object_is_type() or json_object_get_type() before using
|
||||||
|
* the object.
|
||||||
*
|
*
|
||||||
* @b XXX this shouldn't use internal fields:
|
|
||||||
* Trailing characters after the parsed value do not automatically cause an
|
* Trailing characters after the parsed value do not automatically cause an
|
||||||
* error. It is up to the caller to decide whether to treat this as an
|
* error. It is up to the caller to decide whether to treat this as an
|
||||||
* error or to handle the additional characters, perhaps by parsing another
|
* error or to handle the additional characters, perhaps by parsing another
|
||||||
* json value starting from that point.
|
* json value starting from that point.
|
||||||
*
|
*
|
||||||
* Extra characters can be detected by comparing the tok->char_offset against
|
* Extra characters can be detected by comparing the value returned by
|
||||||
|
* json_tokener_get_parse_end() against
|
||||||
* the length of the last len parameter passed in.
|
* the length of the last len parameter passed in.
|
||||||
*
|
*
|
||||||
* The tokener does \b not maintain an internal buffer so the caller is
|
* The tokener does \b not maintain an internal buffer so the caller is
|
||||||
@@ -185,7 +263,7 @@ if (jerr != json_tokener_success)
|
|||||||
fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
|
fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr));
|
||||||
// Handle errors, as appropriate for your application.
|
// Handle errors, as appropriate for your application.
|
||||||
}
|
}
|
||||||
if (tok->char_offset < stringlen) // XXX shouldn't access internal fields
|
if (json_tokener_get_parse_end(tok) < stringlen)
|
||||||
{
|
{
|
||||||
// Handle extra characters after parsed object as desired.
|
// Handle extra characters after parsed object as desired.
|
||||||
// e.g. issue an error, parse another object from that point, etc...
|
// e.g. issue an error, parse another object from that point, etc...
|
||||||
@@ -198,8 +276,8 @@ if (tok->char_offset < stringlen) // XXX shouldn't access internal fields
|
|||||||
* @param str an string with any valid JSON expression, or portion of. This does not need to be null terminated.
|
* @param str an string with any valid JSON expression, or portion of. This does not need to be null terminated.
|
||||||
* @param len the length of str
|
* @param len the length of str
|
||||||
*/
|
*/
|
||||||
extern struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
JSON_EXPORT struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *str,
|
||||||
const char *str, int len);
|
int len);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
78
json_types.h
Normal file
78
json_types.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Eric Hawicz
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _json_types_h_
|
||||||
|
#define _json_types_h_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Basic types used in a few places in json-c, but you should include "json_object.h" instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef JSON_EXPORT
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define JSON_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JSON_EXPORT extern
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct printbuf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A structure to use with json_object_object_foreachC() loops.
|
||||||
|
* Contains key, val and entry members.
|
||||||
|
*/
|
||||||
|
struct json_object_iter
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
struct json_object *val;
|
||||||
|
struct lh_entry *entry;
|
||||||
|
};
|
||||||
|
typedef struct json_object_iter json_object_iter;
|
||||||
|
|
||||||
|
typedef int json_bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The core type for all type of JSON objects handled by json-c
|
||||||
|
*/
|
||||||
|
typedef struct json_object json_object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of custom user delete functions. See json_object_set_serializer.
|
||||||
|
*/
|
||||||
|
typedef void(json_object_delete_fn)(struct json_object *jso, void *userdata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of a custom serialization function. See json_object_set_serializer.
|
||||||
|
*/
|
||||||
|
typedef int(json_object_to_json_string_fn)(struct json_object *jso, struct printbuf *pb, int level,
|
||||||
|
int flags);
|
||||||
|
|
||||||
|
/* supported object types */
|
||||||
|
|
||||||
|
typedef enum json_type
|
||||||
|
{
|
||||||
|
/* If you change this, be sure to update json_type_to_name() too */
|
||||||
|
json_type_null,
|
||||||
|
json_type_boolean,
|
||||||
|
json_type_double,
|
||||||
|
json_type_int,
|
||||||
|
json_type_object,
|
||||||
|
json_type_array,
|
||||||
|
json_type_string
|
||||||
|
} json_type;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
310
json_util.c
310
json_util.c
@@ -12,13 +12,15 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#undef realloc
|
#undef realloc
|
||||||
|
|
||||||
|
#include "strerror_override.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -38,95 +40,170 @@
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
# include <windows.h>
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <windows.h>
|
||||||
#endif /* defined(WIN32) */
|
#endif /* defined(WIN32) */
|
||||||
|
|
||||||
#if !defined(HAVE_OPEN) && defined(WIN32)
|
#if !defined(HAVE_OPEN) && defined(WIN32)
|
||||||
#define open _open
|
#define open _open
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
|
#include "snprintf_compat.h"
|
||||||
/* MSC has the version as _snprintf */
|
|
||||||
# define snprintf _snprintf
|
|
||||||
#elif !defined(HAVE_SNPRINTF)
|
|
||||||
# error You do not have snprintf on your system.
|
|
||||||
#endif /* HAVE_SNPRINTF */
|
|
||||||
|
|
||||||
#include "bits.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "printbuf.h"
|
|
||||||
#include "json_inttypes.h"
|
#include "json_inttypes.h"
|
||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
#include "json_tokener.h"
|
#include "json_tokener.h"
|
||||||
#include "json_util.h"
|
#include "json_util.h"
|
||||||
|
#include "printbuf.h"
|
||||||
|
|
||||||
static int sscanf_is_broken = 0;
|
static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const char *filename);
|
||||||
static int sscanf_is_broken_testdone = 0;
|
|
||||||
static void sscanf_is_broken_test(void);
|
|
||||||
|
|
||||||
struct json_object* json_object_from_file(const char *filename)
|
static char _last_err[256] = "";
|
||||||
|
|
||||||
|
const char *json_util_get_last_err()
|
||||||
|
{
|
||||||
|
if (_last_err[0] == '\0')
|
||||||
|
return NULL;
|
||||||
|
return _last_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _json_c_set_last_err(const char *err_fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, err_fmt);
|
||||||
|
// Ignore (attempted) overruns from snprintf
|
||||||
|
(void)vsnprintf(_last_err, sizeof(_last_err), err_fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct json_object *json_object_from_fd(int fd)
|
||||||
|
{
|
||||||
|
return json_object_from_fd_ex(fd, -1);
|
||||||
|
}
|
||||||
|
struct json_object *json_object_from_fd_ex(int fd, int in_depth)
|
||||||
{
|
{
|
||||||
struct printbuf *pb;
|
struct printbuf *pb;
|
||||||
struct json_object *obj;
|
struct json_object *obj;
|
||||||
char buf[JSON_FILE_BUF_SIZE];
|
char buf[JSON_FILE_BUF_SIZE];
|
||||||
int fd, ret;
|
int ret;
|
||||||
|
int depth = JSON_TOKENER_DEFAULT_DEPTH;
|
||||||
|
json_tokener *tok;
|
||||||
|
|
||||||
if((fd = open(filename, O_RDONLY)) < 0) {
|
if (!(pb = printbuf_new()))
|
||||||
MC_ERROR("json_object_from_file: error opening file %s: %s\n",
|
{
|
||||||
filename, strerror(errno));
|
_json_c_set_last_err("json_object_from_file: printbuf_new failed\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(!(pb = printbuf_new())) {
|
|
||||||
close(fd);
|
if (in_depth != -1)
|
||||||
MC_ERROR("json_object_from_file: printbuf_new failed\n");
|
depth = in_depth;
|
||||||
|
tok = json_tokener_new_ex(depth);
|
||||||
|
if (!tok)
|
||||||
|
{
|
||||||
|
_json_c_set_last_err(
|
||||||
|
"json_object_from_fd: unable to allocate json_tokener(depth=%d): %s\n", depth,
|
||||||
|
strerror(errno));
|
||||||
|
printbuf_free(pb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
|
|
||||||
|
while ((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0)
|
||||||
|
{
|
||||||
printbuf_memappend(pb, buf, ret);
|
printbuf_memappend(pb, buf, ret);
|
||||||
}
|
}
|
||||||
close(fd);
|
if (ret < 0)
|
||||||
if(ret < 0) {
|
{
|
||||||
MC_ERROR("json_object_from_file: error reading file %s: %s\n",
|
_json_c_set_last_err("json_object_from_fd: error reading fd %d: %s\n", fd,
|
||||||
filename, strerror(errno));
|
strerror(errno));
|
||||||
|
json_tokener_free(tok);
|
||||||
printbuf_free(pb);
|
printbuf_free(pb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
obj = json_tokener_parse(pb->buf);
|
|
||||||
|
obj = json_tokener_parse_ex(tok, pb->buf, printbuf_length(pb));
|
||||||
|
if (obj == NULL)
|
||||||
|
_json_c_set_last_err("json_tokener_parse_ex failed: %s\n",
|
||||||
|
json_tokener_error_desc(json_tokener_get_error(tok)));
|
||||||
|
|
||||||
|
json_tokener_free(tok);
|
||||||
printbuf_free(pb);
|
printbuf_free(pb);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct json_object *json_object_from_file(const char *filename)
|
||||||
|
{
|
||||||
|
struct json_object *obj;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||||
|
{
|
||||||
|
_json_c_set_last_err("json_object_from_file: error opening file %s: %s\n", filename,
|
||||||
|
strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
obj = json_object_from_fd(fd);
|
||||||
|
close(fd);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/* extended "format and write to file" function */
|
/* extended "format and write to file" function */
|
||||||
|
|
||||||
int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags)
|
int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags)
|
||||||
{
|
{
|
||||||
const char *json_str;
|
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
|
int saved_errno;
|
||||||
|
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
_json_c_set_last_err("json_object_to_file: object is null\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0)
|
||||||
|
{
|
||||||
|
_json_c_set_last_err("json_object_to_file: error opening file %s: %s\n", filename,
|
||||||
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ret = _json_object_to_fd(fd, obj, flags, filename);
|
||||||
|
saved_errno = errno;
|
||||||
|
close(fd);
|
||||||
|
errno = saved_errno;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int json_object_to_fd(int fd, struct json_object *obj, int flags)
|
||||||
|
{
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
_json_c_set_last_err("json_object_to_fd: object is null\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _json_object_to_fd(fd, obj, flags, NULL);
|
||||||
|
}
|
||||||
|
static int _json_object_to_fd(int fd, struct json_object *obj, int flags, const char *filename)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
const char *json_str;
|
||||||
unsigned int wpos, wsize;
|
unsigned int wpos, wsize;
|
||||||
|
|
||||||
if(!obj) {
|
filename = filename ? filename : "(fd)";
|
||||||
MC_ERROR("json_object_to_file: object is null\n");
|
|
||||||
|
if (!(json_str = json_object_to_json_string_ext(obj, flags)))
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) {
|
/* CAW: probably unnecessary, but the most 64bit safe */
|
||||||
MC_ERROR("json_object_to_file: error opening file %s: %s\n",
|
wsize = (unsigned int)(strlen(json_str) & UINT_MAX);
|
||||||
filename, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(json_str = json_object_to_json_string_ext(obj,flags))) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */
|
|
||||||
wpos = 0;
|
wpos = 0;
|
||||||
while(wpos < wsize) {
|
while (wpos < wsize)
|
||||||
if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) {
|
{
|
||||||
close(fd);
|
if ((ret = write(fd, json_str + wpos, wsize - wpos)) < 0)
|
||||||
MC_ERROR("json_object_to_file: error writing file %s: %s\n",
|
{
|
||||||
|
_json_c_set_last_err("json_object_to_file: error writing file %s: %s\n",
|
||||||
filename, strerror(errno));
|
filename, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -135,7 +212,6 @@ int json_object_to_file_ext(const char *filename, struct json_object *obj, int f
|
|||||||
wpos += (unsigned int)ret;
|
wpos += (unsigned int)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,120 +224,38 @@ int json_object_to_file(const char *filename, struct json_object *obj)
|
|||||||
|
|
||||||
int json_parse_double(const char *buf, double *retval)
|
int json_parse_double(const char *buf, double *retval)
|
||||||
{
|
{
|
||||||
return (sscanf(buf, "%lf", retval)==1 ? 0 : 1);
|
char *end;
|
||||||
}
|
*retval = strtod(buf, &end);
|
||||||
|
return end == buf ? 1 : 0;
|
||||||
/*
|
|
||||||
* Not all implementations of sscanf actually work properly.
|
|
||||||
* Check whether the one we're currently using does, and if
|
|
||||||
* it's broken, enable the workaround code.
|
|
||||||
*/
|
|
||||||
static void sscanf_is_broken_test()
|
|
||||||
{
|
|
||||||
int64_t num64;
|
|
||||||
int ret_errno, is_int64_min, ret_errno2, is_int64_max;
|
|
||||||
|
|
||||||
(void)sscanf(" -01234567890123456789012345", "%" SCNd64, &num64);
|
|
||||||
ret_errno = errno;
|
|
||||||
is_int64_min = (num64 == INT64_MIN);
|
|
||||||
|
|
||||||
(void)sscanf(" 01234567890123456789012345", "%" SCNd64, &num64);
|
|
||||||
ret_errno2 = errno;
|
|
||||||
is_int64_max = (num64 == INT64_MAX);
|
|
||||||
|
|
||||||
if (ret_errno != ERANGE || !is_int64_min ||
|
|
||||||
ret_errno2 != ERANGE || !is_int64_max)
|
|
||||||
{
|
|
||||||
MC_DEBUG("sscanf_is_broken_test failed, enabling workaround code\n");
|
|
||||||
sscanf_is_broken = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int json_parse_int64(const char *buf, int64_t *retval)
|
int json_parse_int64(const char *buf, int64_t *retval)
|
||||||
{
|
{
|
||||||
int64_t num64;
|
char *end = NULL;
|
||||||
const char *buf_sig_digits;
|
int64_t val;
|
||||||
int orig_has_neg;
|
|
||||||
int saved_errno;
|
|
||||||
|
|
||||||
if (!sscanf_is_broken_testdone)
|
errno = 0;
|
||||||
{
|
val = strtoll(buf, &end, 10);
|
||||||
sscanf_is_broken_test();
|
if (end != buf)
|
||||||
sscanf_is_broken_testdone = 1;
|
*retval = val;
|
||||||
|
return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip leading spaces
|
int json_parse_uint64(const char *buf, uint64_t *retval)
|
||||||
while (isspace((int)*buf) && *buf)
|
{
|
||||||
|
char *end = NULL;
|
||||||
|
uint64_t val;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
while (*buf == ' ')
|
||||||
buf++;
|
buf++;
|
||||||
|
if (*buf == '-')
|
||||||
|
return 1; /* error: uint cannot be negative */
|
||||||
|
|
||||||
errno = 0; // sscanf won't always set errno, so initialize
|
val = strtoull(buf, &end, 10);
|
||||||
if (sscanf(buf, "%" SCNd64, &num64) != 1)
|
if (end != buf)
|
||||||
{
|
*retval = val;
|
||||||
MC_DEBUG("Failed to parse, sscanf != 1\n");
|
return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
saved_errno = errno;
|
|
||||||
buf_sig_digits = buf;
|
|
||||||
orig_has_neg = 0;
|
|
||||||
if (*buf_sig_digits == '-')
|
|
||||||
{
|
|
||||||
buf_sig_digits++;
|
|
||||||
orig_has_neg = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not all sscanf implementations actually work
|
|
||||||
if (sscanf_is_broken && saved_errno != ERANGE)
|
|
||||||
{
|
|
||||||
char buf_cmp[100];
|
|
||||||
char *buf_cmp_start = buf_cmp;
|
|
||||||
int recheck_has_neg = 0;
|
|
||||||
int buf_cmp_len;
|
|
||||||
|
|
||||||
// Skip leading zeros, but keep at least one digit
|
|
||||||
while (buf_sig_digits[0] == '0' && buf_sig_digits[1] != '\0')
|
|
||||||
buf_sig_digits++;
|
|
||||||
if (num64 == 0) // assume all sscanf impl's will parse -0 to 0
|
|
||||||
orig_has_neg = 0; // "-0" is the same as just plain "0"
|
|
||||||
|
|
||||||
snprintf(buf_cmp_start, sizeof(buf_cmp), "%" PRId64, num64);
|
|
||||||
if (*buf_cmp_start == '-')
|
|
||||||
{
|
|
||||||
recheck_has_neg = 1;
|
|
||||||
buf_cmp_start++;
|
|
||||||
}
|
|
||||||
// No need to skip leading spaces or zeros here.
|
|
||||||
|
|
||||||
buf_cmp_len = strlen(buf_cmp_start);
|
|
||||||
/**
|
|
||||||
* If the sign is different, or
|
|
||||||
* some of the digits are different, or
|
|
||||||
* there is another digit present in the original string
|
|
||||||
* then we have NOT successfully parsed the value.
|
|
||||||
*/
|
|
||||||
if (orig_has_neg != recheck_has_neg ||
|
|
||||||
strncmp(buf_sig_digits, buf_cmp_start, strlen(buf_cmp_start)) != 0 ||
|
|
||||||
((int)strlen(buf_sig_digits) != buf_cmp_len &&
|
|
||||||
isdigit((int)buf_sig_digits[buf_cmp_len])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
saved_errno = ERANGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not all sscanf impl's set the value properly when out of range.
|
|
||||||
// Always do this, even for properly functioning implementations,
|
|
||||||
// since it shouldn't slow things down much.
|
|
||||||
if (saved_errno == ERANGE)
|
|
||||||
{
|
|
||||||
if (orig_has_neg)
|
|
||||||
num64 = INT64_MIN;
|
|
||||||
else
|
|
||||||
num64 = INT64_MAX;
|
|
||||||
}
|
|
||||||
*retval = num64;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_REALLOC
|
#ifndef HAVE_REALLOC
|
||||||
@@ -276,6 +270,7 @@ void* rpl_realloc(void* p, size_t n)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NELEM(a) (sizeof(a) / sizeof(a[0]))
|
#define NELEM(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
/* clang-format off */
|
||||||
static const char *json_type_name[] = {
|
static const char *json_type_name[] = {
|
||||||
/* If you change this, be sure to update the enum json_type definition too */
|
/* If you change this, be sure to update the enum json_type definition too */
|
||||||
"null",
|
"null",
|
||||||
@@ -286,15 +281,16 @@ static const char* json_type_name[] = {
|
|||||||
"array",
|
"array",
|
||||||
"string",
|
"string",
|
||||||
};
|
};
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
const char *json_type_to_name(enum json_type o_type)
|
const char *json_type_to_name(enum json_type o_type)
|
||||||
{
|
{
|
||||||
int o_type_int = (int)o_type;
|
int o_type_int = (int)o_type;
|
||||||
if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name))
|
if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name))
|
||||||
{
|
{
|
||||||
MC_ERROR("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name));
|
_json_c_set_last_err("json_type_to_name: type %d is out of range [0,%d]\n", o_type,
|
||||||
|
NELEM(json_type_name));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return json_type_name[o_type];
|
return json_type_name[o_type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
89
json_util.h
89
json_util.h
@@ -9,11 +9,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Miscllaneous utility functions and macros.
|
||||||
|
*/
|
||||||
#ifndef _json_util_h_
|
#ifndef _json_util_h_
|
||||||
#define _json_util_h_
|
#define _json_util_h_
|
||||||
|
|
||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
|
|
||||||
|
#ifndef json_min
|
||||||
|
#define json_min(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef json_max
|
||||||
|
#define json_max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -21,18 +33,83 @@ extern "C" {
|
|||||||
#define JSON_FILE_BUF_SIZE 4096
|
#define JSON_FILE_BUF_SIZE 4096
|
||||||
|
|
||||||
/* utility functions */
|
/* utility functions */
|
||||||
extern struct json_object* json_object_from_file(const char *filename);
|
/**
|
||||||
extern int json_object_to_file(const char *filename, struct json_object *obj);
|
* Read the full contents of the given file, then convert it to a
|
||||||
extern int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags);
|
* json_object using json_tokener_parse().
|
||||||
extern int json_parse_int64(const char *buf, int64_t *retval);
|
*
|
||||||
extern int json_parse_double(const char *buf, double *retval);
|
* Returns NULL on failure. See json_util_get_last_err() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_from_file(const char *filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a JSON object from already opened file descriptor.
|
||||||
|
*
|
||||||
|
* This function can be helpful, when you opened the file already,
|
||||||
|
* e.g. when you have a temp file.
|
||||||
|
* Note, that the fd must be readable at the actual position, i.e.
|
||||||
|
* use lseek(fd, 0, SEEK_SET) before.
|
||||||
|
*
|
||||||
|
* The depth argument specifies the maximum object depth to pass to
|
||||||
|
* json_tokener_new_ex(). When depth == -1, JSON_TOKENER_DEFAULT_DEPTH
|
||||||
|
* is used instead.
|
||||||
|
*
|
||||||
|
* Returns NULL on failure. See json_util_get_last_err() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_from_fd_ex(int fd, int depth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a JSON object from an already opened file descriptor, using
|
||||||
|
* the default maximum object depth. (JSON_TOKENER_DEFAULT_DEPTH)
|
||||||
|
*
|
||||||
|
* See json_object_from_fd_ex() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT struct json_object *json_object_from_fd(int fd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to:
|
||||||
|
* json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN);
|
||||||
|
*
|
||||||
|
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_to_file(const char *filename, struct json_object *obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open and truncate the given file, creating it if necessary, then
|
||||||
|
* convert the json_object to a string and write it to the file.
|
||||||
|
*
|
||||||
|
* Returns -1 if something fails. See json_util_get_last_err() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_to_file_ext(const char *filename, struct json_object *obj, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the json_object to a string and write it to the file descriptor.
|
||||||
|
* Handles partial writes and will keep writing until done, or an error
|
||||||
|
* occurs.
|
||||||
|
*
|
||||||
|
* @param fd an open, writable file descriptor to write to
|
||||||
|
* @param obj the object to serializer and write
|
||||||
|
* @param flags flags to pass to json_object_to_json_string_ext()
|
||||||
|
* @return -1 if something fails. See json_util_get_last_err() for details.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_object_to_fd(int fd, struct json_object *obj, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the last error from various json-c functions, including:
|
||||||
|
* json_object_to_file{,_ext}, json_object_to_fd() or
|
||||||
|
* json_object_from_{file,fd}, or NULL if there is none.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT const char *json_util_get_last_err(void);
|
||||||
|
|
||||||
|
/* these parsing helpers return zero on success */
|
||||||
|
JSON_EXPORT int json_parse_int64(const char *buf, int64_t *retval);
|
||||||
|
JSON_EXPORT int json_parse_uint64(const char *buf, uint64_t *retval);
|
||||||
|
JSON_EXPORT int json_parse_double(const char *buf, double *retval);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string describing the type of the object.
|
* Return a string describing the type of the object.
|
||||||
* e.g. "int", or "object", etc...
|
* e.g. "int", or "object", etc...
|
||||||
*/
|
*/
|
||||||
extern const char *json_type_to_name(enum json_type o_type);
|
JSON_EXPORT const char *json_type_to_name(enum json_type o_type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
128
json_visit.c
Normal file
128
json_visit.c
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Eric Haszlakiewicz
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the MIT license. See COPYING for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "json_inttypes.h"
|
||||||
|
#include "json_object.h"
|
||||||
|
#include "json_visit.h"
|
||||||
|
#include "linkhash.h"
|
||||||
|
|
||||||
|
static int _json_c_visit(json_object *jso, json_object *parent_jso, const char *jso_key,
|
||||||
|
size_t *jso_index, json_c_visit_userfunc *userfunc, void *userarg);
|
||||||
|
|
||||||
|
int json_c_visit(json_object *jso, int future_flags, json_c_visit_userfunc *userfunc, void *userarg)
|
||||||
|
{
|
||||||
|
int ret = _json_c_visit(jso, NULL, NULL, NULL, userfunc, userarg);
|
||||||
|
switch (ret)
|
||||||
|
{
|
||||||
|
case JSON_C_VISIT_RETURN_CONTINUE:
|
||||||
|
case JSON_C_VISIT_RETURN_SKIP:
|
||||||
|
case JSON_C_VISIT_RETURN_POP:
|
||||||
|
case JSON_C_VISIT_RETURN_STOP: return 0;
|
||||||
|
default: return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static int _json_c_visit(json_object *jso, json_object *parent_jso, const char *jso_key,
|
||||||
|
size_t *jso_index, json_c_visit_userfunc *userfunc, void *userarg)
|
||||||
|
{
|
||||||
|
int userret = userfunc(jso, 0, parent_jso, jso_key, jso_index, userarg);
|
||||||
|
switch (userret)
|
||||||
|
{
|
||||||
|
case JSON_C_VISIT_RETURN_CONTINUE: break;
|
||||||
|
case JSON_C_VISIT_RETURN_SKIP:
|
||||||
|
case JSON_C_VISIT_RETURN_POP:
|
||||||
|
case JSON_C_VISIT_RETURN_STOP:
|
||||||
|
case JSON_C_VISIT_RETURN_ERROR: return userret;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n",
|
||||||
|
userret);
|
||||||
|
return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (json_object_get_type(jso))
|
||||||
|
{
|
||||||
|
case json_type_null:
|
||||||
|
case json_type_boolean:
|
||||||
|
case json_type_double:
|
||||||
|
case json_type_int:
|
||||||
|
case json_type_string:
|
||||||
|
// we already called userfunc above, move on to the next object
|
||||||
|
return JSON_C_VISIT_RETURN_CONTINUE;
|
||||||
|
|
||||||
|
case json_type_object:
|
||||||
|
{
|
||||||
|
json_object_object_foreach(jso, key, child)
|
||||||
|
{
|
||||||
|
userret = _json_c_visit(child, jso, key, NULL, userfunc, userarg);
|
||||||
|
if (userret == JSON_C_VISIT_RETURN_POP)
|
||||||
|
break;
|
||||||
|
if (userret == JSON_C_VISIT_RETURN_STOP ||
|
||||||
|
userret == JSON_C_VISIT_RETURN_ERROR)
|
||||||
|
return userret;
|
||||||
|
if (userret != JSON_C_VISIT_RETURN_CONTINUE &&
|
||||||
|
userret != JSON_C_VISIT_RETURN_SKIP)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n",
|
||||||
|
userret);
|
||||||
|
return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case json_type_array:
|
||||||
|
{
|
||||||
|
size_t array_len = json_object_array_length(jso);
|
||||||
|
size_t ii;
|
||||||
|
for (ii = 0; ii < array_len; ii++)
|
||||||
|
{
|
||||||
|
json_object *child = json_object_array_get_idx(jso, ii);
|
||||||
|
userret = _json_c_visit(child, jso, NULL, &ii, userfunc, userarg);
|
||||||
|
if (userret == JSON_C_VISIT_RETURN_POP)
|
||||||
|
break;
|
||||||
|
if (userret == JSON_C_VISIT_RETURN_STOP ||
|
||||||
|
userret == JSON_C_VISIT_RETURN_ERROR)
|
||||||
|
return userret;
|
||||||
|
if (userret != JSON_C_VISIT_RETURN_CONTINUE &&
|
||||||
|
userret != JSON_C_VISIT_RETURN_SKIP)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "INTERNAL ERROR: _json_c_visit returned %d\n",
|
||||||
|
userret);
|
||||||
|
return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "INTERNAL ERROR: _json_c_visit found object of unknown type: %d\n",
|
||||||
|
json_object_get_type(jso));
|
||||||
|
return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call userfunc for the second type on container types, after all
|
||||||
|
// members of the container have been visited.
|
||||||
|
// Non-container types will have already returned before this point.
|
||||||
|
|
||||||
|
userret = userfunc(jso, JSON_C_VISIT_SECOND, parent_jso, jso_key, jso_index, userarg);
|
||||||
|
switch (userret)
|
||||||
|
{
|
||||||
|
case JSON_C_VISIT_RETURN_SKIP:
|
||||||
|
case JSON_C_VISIT_RETURN_POP:
|
||||||
|
// These are not really sensible during JSON_C_VISIT_SECOND,
|
||||||
|
// but map them to JSON_C_VISIT_CONTINUE anyway.
|
||||||
|
// FALLTHROUGH
|
||||||
|
case JSON_C_VISIT_RETURN_CONTINUE: return JSON_C_VISIT_RETURN_CONTINUE;
|
||||||
|
case JSON_C_VISIT_RETURN_STOP:
|
||||||
|
case JSON_C_VISIT_RETURN_ERROR: return userret;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "ERROR: invalid return value from json_c_visit userfunc: %d\n",
|
||||||
|
userret);
|
||||||
|
return JSON_C_VISIT_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
// NOTREACHED
|
||||||
|
}
|
||||||
101
json_visit.h
Normal file
101
json_visit.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
|
||||||
|
#ifndef _json_c_json_visit_h_
|
||||||
|
#define _json_c_json_visit_h_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Methods for walking a tree of objects.
|
||||||
|
*/
|
||||||
|
#include "json_object.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int(json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso,
|
||||||
|
const char *jso_key, size_t *jso_index, void *userarg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visit each object in the JSON hierarchy starting at jso.
|
||||||
|
* For each object, userfunc is called, passing the object and userarg.
|
||||||
|
* If the object has a parent (i.e. anything other than jso itself)
|
||||||
|
* its parent will be passed as parent_jso, and either jso_key or jso_index
|
||||||
|
* will be set, depending on whether the parent is an object or an array.
|
||||||
|
*
|
||||||
|
* Nodes will be visited depth first, but containers (arrays and objects)
|
||||||
|
* will be visited twice, the second time with JSON_C_VISIT_SECOND set in
|
||||||
|
* flags.
|
||||||
|
*
|
||||||
|
* userfunc must return one of the defined return values, to indicate
|
||||||
|
* whether and how to continue visiting nodes, or one of various ways to stop.
|
||||||
|
*
|
||||||
|
* Returns 0 if nodes were visited successfully, even if some were
|
||||||
|
* intentionally skipped due to what userfunc returned.
|
||||||
|
* Returns <0 if an error occurred during iteration, including if
|
||||||
|
* userfunc returned JSON_C_VISIT_RETURN_ERROR.
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int json_c_visit(json_object *jso, int future_flags, json_c_visit_userfunc *userfunc,
|
||||||
|
void *userarg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passed to json_c_visit_userfunc as one of the flags values to indicate
|
||||||
|
* that this is the second time a container (array or object) is being
|
||||||
|
* called, after all of it's members have been iterated over.
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_SECOND 0x02
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This json_c_visit_userfunc return value indicates that iteration
|
||||||
|
* should proceed normally.
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_RETURN_CONTINUE 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This json_c_visit_userfunc return value indicates that iteration
|
||||||
|
* over the members of the current object should be skipped.
|
||||||
|
* If the current object isn't a container (array or object), this
|
||||||
|
* is no different than JSON_C_VISIT_RETURN_CONTINUE.
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_RETURN_SKIP 7547
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This json_c_visit_userfunc return value indicates that iteration
|
||||||
|
* of the fields/elements of the <b>containing</b> object should stop
|
||||||
|
* and continue "popped up" a level of the object hierarchy.
|
||||||
|
* For example, returning this when handling arg will result in
|
||||||
|
* arg3 and any other fields being skipped. The next call to userfunc
|
||||||
|
* will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc
|
||||||
|
* call on "bar".
|
||||||
|
* <pre>
|
||||||
|
* {
|
||||||
|
* "foo": {
|
||||||
|
* "arg1": 1,
|
||||||
|
* "arg2": 2,
|
||||||
|
* "arg3": 3,
|
||||||
|
* ...
|
||||||
|
* },
|
||||||
|
* "bar": {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_RETURN_POP 767
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This json_c_visit_userfunc return value indicates that iteration
|
||||||
|
* should stop immediately, and cause json_c_visit to return success.
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_RETURN_STOP 7867
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This json_c_visit_userfunc return value indicates that iteration
|
||||||
|
* should stop immediately, and cause json_c_visit to return an error.
|
||||||
|
*/
|
||||||
|
#define JSON_C_VISIT_RETURN_ERROR -1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _json_c_json_visit_h_ */
|
||||||
332
linkhash.c
332
linkhash.c
@@ -10,30 +10,49 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "config.h"
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <limits.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef HAVE_ENDIAN_H
|
#ifdef HAVE_ENDIAN_H
|
||||||
#include <endian.h> /* attempt to define endianness */
|
#include <endian.h> /* attempt to define endianness */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "random_seed.h"
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
#include "linkhash.h"
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h> /* Get InterlockedCompareExchange */
|
||||||
|
#endif
|
||||||
|
|
||||||
void lh_abort(const char *msg, ...)
|
#include "linkhash.h"
|
||||||
|
#include "random_seed.h"
|
||||||
|
|
||||||
|
/* hash functions */
|
||||||
|
static unsigned long lh_char_hash(const void *k);
|
||||||
|
static unsigned long lh_perllike_str_hash(const void *k);
|
||||||
|
static lh_hash_fn *char_hash_fn = lh_char_hash;
|
||||||
|
|
||||||
|
/* comparison functions */
|
||||||
|
int lh_char_equal(const void *k1, const void *k2);
|
||||||
|
int lh_ptr_equal(const void *k1, const void *k2);
|
||||||
|
|
||||||
|
int json_global_set_string_hash(const int h)
|
||||||
{
|
{
|
||||||
va_list ap;
|
switch (h)
|
||||||
va_start(ap, msg);
|
{
|
||||||
vprintf(msg, ap);
|
case JSON_C_STR_HASH_DFLT: char_hash_fn = lh_char_hash; break;
|
||||||
va_end(ap);
|
case JSON_C_STR_HASH_PERLLIKE: char_hash_fn = lh_perllike_str_hash; break;
|
||||||
exit(1);
|
default: return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long lh_ptr_hash(const void *k)
|
static unsigned long lh_ptr_hash(const void *k)
|
||||||
{
|
{
|
||||||
/* CAW: refactored to be 64bit nice */
|
/* CAW: refactored to be 64bit nice */
|
||||||
return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX);
|
return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX);
|
||||||
@@ -91,14 +110,12 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
|
|||||||
* My best guess at if you are big-endian or little-endian. This may
|
* My best guess at if you are big-endian or little-endian. This may
|
||||||
* need adjustment.
|
* need adjustment.
|
||||||
*/
|
*/
|
||||||
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
|
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
|
||||||
__BYTE_ORDER == __LITTLE_ENDIAN) || \
|
(defined(i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || \
|
||||||
(defined(i386) || defined(__i386__) || defined(__i486__) || \
|
defined(__i686__) || defined(vax) || defined(MIPSEL))
|
||||||
defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL))
|
|
||||||
#define HASH_LITTLE_ENDIAN 1
|
#define HASH_LITTLE_ENDIAN 1
|
||||||
#define HASH_BIG_ENDIAN 0
|
#define HASH_BIG_ENDIAN 0
|
||||||
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
|
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || \
|
||||||
__BYTE_ORDER == __BIG_ENDIAN) || \
|
|
||||||
(defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel))
|
(defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel))
|
||||||
#define HASH_LITTLE_ENDIAN 0
|
#define HASH_LITTLE_ENDIAN 0
|
||||||
#define HASH_BIG_ENDIAN 1
|
#define HASH_BIG_ENDIAN 1
|
||||||
@@ -155,6 +172,7 @@ on, and rotates are much kinder to the top and bottom bits, so I used
|
|||||||
rotates.
|
rotates.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
/* clang-format off */
|
||||||
#define mix(a,b,c) \
|
#define mix(a,b,c) \
|
||||||
{ \
|
{ \
|
||||||
a -= c; a ^= rot(c, 4); c += b; \
|
a -= c; a ^= rot(c, 4); c += b; \
|
||||||
@@ -164,6 +182,7 @@ rotates.
|
|||||||
b -= a; b ^= rot(a,19); a += c; \
|
b -= a; b ^= rot(a,19); a += c; \
|
||||||
c -= b; c ^= rot(b, 4); b += a; \
|
c -= b; c ^= rot(b, 4); b += a; \
|
||||||
}
|
}
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@@ -190,6 +209,7 @@ and these came close:
|
|||||||
11 8 15 26 3 22 24
|
11 8 15 26 3 22 24
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
/* clang-format off */
|
||||||
#define final(a,b,c) \
|
#define final(a,b,c) \
|
||||||
{ \
|
{ \
|
||||||
c ^= b; c -= rot(b,14); \
|
c ^= b; c -= rot(b,14); \
|
||||||
@@ -200,7 +220,7 @@ and these came close:
|
|||||||
b ^= a; b -= rot(a,14); \
|
b ^= a; b -= rot(a,14); \
|
||||||
c ^= b; c -= rot(b,24); \
|
c ^= b; c -= rot(b,24); \
|
||||||
}
|
}
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@@ -229,10 +249,15 @@ acceptable. Do NOT use for cryptographic purposes.
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
static uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
|
static uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
|
||||||
{
|
{
|
||||||
uint32_t a,b,c; /* internal state */
|
uint32_t a,b,c; /* internal state */
|
||||||
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
|
union
|
||||||
|
{
|
||||||
|
const void *ptr;
|
||||||
|
size_t i;
|
||||||
|
} u; /* needed for Mac Powerbook G4 */
|
||||||
|
|
||||||
/* Set up the internal state */
|
/* Set up the internal state */
|
||||||
a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
|
a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
|
||||||
@@ -261,8 +286,19 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
* does it on word boundaries, so is OK with this. But VALGRIND will
|
* does it on word boundaries, so is OK with this. But VALGRIND will
|
||||||
* still catch it and complain. The masking trick does make the hash
|
* still catch it and complain. The masking trick does make the hash
|
||||||
* noticably faster for short strings (like English words).
|
* noticably faster for short strings (like English words).
|
||||||
|
* AddressSanitizer is similarly picky about overrunning
|
||||||
|
* the buffer. (http://clang.llvm.org/docs/AddressSanitizer.html
|
||||||
*/
|
*/
|
||||||
#ifndef VALGRIND
|
#ifdef VALGRIND
|
||||||
|
#define PRECISE_MEMORY_ACCESS 1
|
||||||
|
#elif defined(__SANITIZE_ADDRESS__) /* GCC's ASAN */
|
||||||
|
#define PRECISE_MEMORY_ACCESS 1
|
||||||
|
#elif defined(__has_feature)
|
||||||
|
#if __has_feature(address_sanitizer) /* Clang's ASAN */
|
||||||
|
#define PRECISE_MEMORY_ACCESS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef PRECISE_MEMORY_ACCESS
|
||||||
|
|
||||||
switch(length)
|
switch(length)
|
||||||
{
|
{
|
||||||
@@ -303,7 +339,9 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
|
|
||||||
#endif /* !valgrind */
|
#endif /* !valgrind */
|
||||||
|
|
||||||
} else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
|
}
|
||||||
|
else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0))
|
||||||
|
{
|
||||||
const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
|
const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
|
||||||
const uint8_t *k8;
|
const uint8_t *k8;
|
||||||
|
|
||||||
@@ -350,7 +388,10 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
case 0 : return c; /* zero length requires no mixing */
|
case 0 : return c; /* zero length requires no mixing */
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { /* need to read the key one byte at a time */
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* need to read the key one byte at a time */
|
||||||
const uint8_t *k = (const uint8_t *)key;
|
const uint8_t *k = (const uint8_t *)key;
|
||||||
|
|
||||||
/*--------------- all but the last block: affect some 32 bits of (a,b,c) */
|
/*--------------- all but the last block: affect some 32 bits of (a,b,c) */
|
||||||
@@ -376,17 +417,17 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
/*-------------------------------- last block: affect all 32 bits of (c) */
|
/*-------------------------------- last block: affect all 32 bits of (c) */
|
||||||
switch(length) /* all the case statements fall through */
|
switch(length) /* all the case statements fall through */
|
||||||
{
|
{
|
||||||
case 12: c+=((uint32_t)k[11])<<24;
|
case 12: c+=((uint32_t)k[11])<<24; /* FALLTHRU */
|
||||||
case 11: c+=((uint32_t)k[10])<<16;
|
case 11: c+=((uint32_t)k[10])<<16; /* FALLTHRU */
|
||||||
case 10: c+=((uint32_t)k[9])<<8;
|
case 10: c+=((uint32_t)k[9])<<8; /* FALLTHRU */
|
||||||
case 9 : c+=k[8];
|
case 9 : c+=k[8]; /* FALLTHRU */
|
||||||
case 8 : b+=((uint32_t)k[7])<<24;
|
case 8 : b+=((uint32_t)k[7])<<24; /* FALLTHRU */
|
||||||
case 7 : b+=((uint32_t)k[6])<<16;
|
case 7 : b+=((uint32_t)k[6])<<16; /* FALLTHRU */
|
||||||
case 6 : b+=((uint32_t)k[5])<<8;
|
case 6 : b+=((uint32_t)k[5])<<8; /* FALLTHRU */
|
||||||
case 5 : b+=k[4];
|
case 5 : b+=k[4]; /* FALLTHRU */
|
||||||
case 4 : a+=((uint32_t)k[3])<<24;
|
case 4 : a+=((uint32_t)k[3])<<24; /* FALLTHRU */
|
||||||
case 3 : a+=((uint32_t)k[2])<<16;
|
case 3 : a+=((uint32_t)k[2])<<16; /* FALLTHRU */
|
||||||
case 2 : a+=((uint32_t)k[1])<<8;
|
case 2 : a+=((uint32_t)k[1])<<8; /* FALLTHRU */
|
||||||
case 1 : a+=k[0];
|
case 1 : a+=k[0];
|
||||||
break;
|
break;
|
||||||
case 0 : return c;
|
case 0 : return c;
|
||||||
@@ -396,21 +437,51 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
final(a,b,c);
|
final(a,b,c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
unsigned long lh_char_hash(const void *k)
|
/* a simple hash function similiar to what perl does for strings.
|
||||||
|
* for good results, the string should not be excessivly large.
|
||||||
|
*/
|
||||||
|
static unsigned long lh_perllike_str_hash(const void *k)
|
||||||
{
|
{
|
||||||
static volatile int random_seed = -1;
|
const char *rkey = (const char *)k;
|
||||||
|
unsigned hashval = 1;
|
||||||
|
|
||||||
if (random_seed == -1) {
|
while (*rkey)
|
||||||
int seed;
|
hashval = hashval * 33 + *rkey++;
|
||||||
|
|
||||||
|
return hashval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned long lh_char_hash(const void *k)
|
||||||
|
{
|
||||||
|
#if defined _MSC_VER || defined __MINGW32__
|
||||||
|
#define RANDOM_SEED_TYPE LONG
|
||||||
|
#else
|
||||||
|
#define RANDOM_SEED_TYPE int
|
||||||
|
#endif
|
||||||
|
static volatile RANDOM_SEED_TYPE random_seed = -1;
|
||||||
|
|
||||||
|
if (random_seed == -1)
|
||||||
|
{
|
||||||
|
RANDOM_SEED_TYPE seed;
|
||||||
/* we can't use -1 as it is the unitialized sentinel */
|
/* we can't use -1 as it is the unitialized sentinel */
|
||||||
while ((seed = json_c_get_random_seed()) == -1);
|
while ((seed = json_c_get_random_seed()) == -1) {}
|
||||||
#if defined __GNUC__
|
#if SIZEOF_INT == 8 && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
|
||||||
__sync_val_compare_and_swap(&random_seed, -1, seed);
|
#define USE_SYNC_COMPARE_AND_SWAP 1
|
||||||
#elif defined _MSC_VER
|
#endif
|
||||||
|
#if SIZEOF_INT == 4 && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
|
||||||
|
#define USE_SYNC_COMPARE_AND_SWAP 1
|
||||||
|
#endif
|
||||||
|
#if SIZEOF_INT == 2 && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
|
||||||
|
#define USE_SYNC_COMPARE_AND_SWAP 1
|
||||||
|
#endif
|
||||||
|
#if defined USE_SYNC_COMPARE_AND_SWAP
|
||||||
|
(void)__sync_val_compare_and_swap(&random_seed, -1, seed);
|
||||||
|
#elif defined _MSC_VER || defined __MINGW32__
|
||||||
InterlockedCompareExchange(&random_seed, seed, -1);
|
InterlockedCompareExchange(&random_seed, seed, -1);
|
||||||
#else
|
#else
|
||||||
#warning "racy random seed initializtion if used by multiple threads"
|
//#warning "racy random seed initializtion if used by multiple threads"
|
||||||
random_seed = seed; /* potentially racy */
|
random_seed = seed; /* potentially racy */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -423,97 +494,122 @@ int lh_char_equal(const void *k1, const void *k2)
|
|||||||
return (strcmp((const char *)k1, (const char *)k2) == 0);
|
return (strcmp((const char *)k1, (const char *)k2) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lh_table* lh_table_new(int size, const char *name,
|
struct lh_table *lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn,
|
||||||
lh_entry_free_fn *free_fn,
|
|
||||||
lh_hash_fn *hash_fn,
|
|
||||||
lh_equal_fn *equal_fn)
|
lh_equal_fn *equal_fn)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct lh_table *t;
|
struct lh_table *t;
|
||||||
|
|
||||||
|
/* Allocate space for elements to avoid divisions by zero. */
|
||||||
|
assert(size > 0);
|
||||||
t = (struct lh_table *)calloc(1, sizeof(struct lh_table));
|
t = (struct lh_table *)calloc(1, sizeof(struct lh_table));
|
||||||
if(!t) lh_abort("lh_table_new: calloc failed\n");
|
if (!t)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
t->count = 0;
|
t->count = 0;
|
||||||
t->size = size;
|
t->size = size;
|
||||||
t->name = name;
|
|
||||||
t->table = (struct lh_entry *)calloc(size, sizeof(struct lh_entry));
|
t->table = (struct lh_entry *)calloc(size, sizeof(struct lh_entry));
|
||||||
if(!t->table) lh_abort("lh_table_new: calloc failed\n");
|
if (!t->table)
|
||||||
|
{
|
||||||
|
free(t);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
t->free_fn = free_fn;
|
t->free_fn = free_fn;
|
||||||
t->hash_fn = hash_fn;
|
t->hash_fn = hash_fn;
|
||||||
t->equal_fn = equal_fn;
|
t->equal_fn = equal_fn;
|
||||||
for(i = 0; i < size; i++) t->table[i].k = LH_EMPTY;
|
for (i = 0; i < size; i++)
|
||||||
|
t->table[i].k = LH_EMPTY;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lh_table* lh_kchar_table_new(int size, const char *name,
|
struct lh_table *lh_kchar_table_new(int size, lh_entry_free_fn *free_fn)
|
||||||
lh_entry_free_fn *free_fn)
|
|
||||||
{
|
{
|
||||||
return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal);
|
return lh_table_new(size, free_fn, char_hash_fn, lh_char_equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lh_table* lh_kptr_table_new(int size, const char *name,
|
struct lh_table *lh_kptr_table_new(int size, lh_entry_free_fn *free_fn)
|
||||||
lh_entry_free_fn *free_fn)
|
|
||||||
{
|
{
|
||||||
return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
|
return lh_table_new(size, free_fn, lh_ptr_hash, lh_ptr_equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lh_table_resize(struct lh_table *t, int new_size)
|
int lh_table_resize(struct lh_table *t, int new_size)
|
||||||
{
|
{
|
||||||
struct lh_table *new_t;
|
struct lh_table *new_t;
|
||||||
struct lh_entry *ent;
|
struct lh_entry *ent;
|
||||||
|
|
||||||
new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn);
|
new_t = lh_table_new(new_size, NULL, t->hash_fn, t->equal_fn);
|
||||||
ent = t->head;
|
if (new_t == NULL)
|
||||||
while(ent) {
|
return -1;
|
||||||
lh_table_insert(new_t, ent->k, ent->v);
|
|
||||||
ent = ent->next;
|
for (ent = t->head; ent != NULL; ent = ent->next)
|
||||||
|
{
|
||||||
|
unsigned long h = lh_get_hash(new_t, ent->k);
|
||||||
|
unsigned int opts = 0;
|
||||||
|
if (ent->k_is_constant)
|
||||||
|
opts = JSON_C_OBJECT_KEY_IS_CONSTANT;
|
||||||
|
if (lh_table_insert_w_hash(new_t, ent->k, ent->v, h, opts) != 0)
|
||||||
|
{
|
||||||
|
lh_table_free(new_t);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(t->table);
|
free(t->table);
|
||||||
t->table = new_t->table;
|
t->table = new_t->table;
|
||||||
t->size = new_size;
|
t->size = new_size;
|
||||||
t->head = new_t->head;
|
t->head = new_t->head;
|
||||||
t->tail = new_t->tail;
|
t->tail = new_t->tail;
|
||||||
t->resizes++;
|
|
||||||
free(new_t);
|
free(new_t);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lh_table_free(struct lh_table *t)
|
void lh_table_free(struct lh_table *t)
|
||||||
{
|
{
|
||||||
struct lh_entry *c;
|
struct lh_entry *c;
|
||||||
for(c = t->head; c != NULL; c = c->next) {
|
if (t->free_fn)
|
||||||
if(t->free_fn) {
|
{
|
||||||
|
for (c = t->head; c != NULL; c = c->next)
|
||||||
t->free_fn(c);
|
t->free_fn(c);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(t->table);
|
free(t->table);
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v, const unsigned long h,
|
||||||
int lh_table_insert(struct lh_table *t, void *k, const void *v)
|
const unsigned opts)
|
||||||
{
|
{
|
||||||
unsigned long h, n;
|
unsigned long n;
|
||||||
|
|
||||||
t->inserts++;
|
if (t->count >= t->size * LH_LOAD_FACTOR)
|
||||||
if(t->count >= t->size * LH_LOAD_FACTOR) lh_table_resize(t, t->size * 2);
|
{
|
||||||
|
/* Avoid signed integer overflow with large tables. */
|
||||||
|
int new_size = (t->size > INT_MAX / 2) ? INT_MAX : (t->size * 2);
|
||||||
|
if (t->size == INT_MAX || lh_table_resize(t, new_size) != 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
h = t->hash_fn(k);
|
|
||||||
n = h % t->size;
|
n = h % t->size;
|
||||||
|
|
||||||
while( 1 ) {
|
while (1)
|
||||||
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break;
|
{
|
||||||
t->collisions++;
|
if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
|
||||||
if ((int)++n == t->size) n = 0;
|
break;
|
||||||
|
if ((int)++n == t->size)
|
||||||
|
n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->table[n].k = k;
|
t->table[n].k = k;
|
||||||
|
t->table[n].k_is_constant = (opts & JSON_C_OBJECT_KEY_IS_CONSTANT);
|
||||||
t->table[n].v = v;
|
t->table[n].v = v;
|
||||||
t->count++;
|
t->count++;
|
||||||
|
|
||||||
if(t->head == NULL) {
|
if (t->head == NULL)
|
||||||
|
{
|
||||||
t->head = t->tail = &t->table[n];
|
t->head = t->tail = &t->table[n];
|
||||||
t->table[n].next = t->table[n].prev = NULL;
|
t->table[n].next = t->table[n].prev = NULL;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
t->tail->next = &t->table[n];
|
t->tail->next = &t->table[n];
|
||||||
t->table[n].prev = t->tail;
|
t->table[n].prev = t->tail;
|
||||||
t->table[n].next = NULL;
|
t->table[n].next = NULL;
|
||||||
@@ -522,65 +618,83 @@ int lh_table_insert(struct lh_table *t, void *k, const void *v)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lh_table_insert(struct lh_table *t, const void *k, const void *v)
|
||||||
|
{
|
||||||
struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k)
|
return lh_table_insert_w_hash(t, k, v, lh_get_hash(t, k), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct lh_entry *lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k,
|
||||||
|
const unsigned long h)
|
||||||
{
|
{
|
||||||
unsigned long h = t->hash_fn(k);
|
|
||||||
unsigned long n = h % t->size;
|
unsigned long n = h % t->size;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
t->lookups++;
|
while (count < t->size)
|
||||||
while( count < t->size ) {
|
{
|
||||||
if(t->table[n].k == LH_EMPTY) return NULL;
|
if (t->table[n].k == LH_EMPTY)
|
||||||
if(t->table[n].k != LH_FREED &&
|
return NULL;
|
||||||
t->equal_fn(t->table[n].k, k)) return &t->table[n];
|
if (t->table[n].k != LH_FREED && t->equal_fn(t->table[n].k, k))
|
||||||
if ((int)++n == t->size) n = 0;
|
return &t->table[n];
|
||||||
|
if ((int)++n == t->size)
|
||||||
|
n = 0;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lh_entry *lh_table_lookup_entry(struct lh_table *t, const void *k)
|
||||||
const void* lh_table_lookup(struct lh_table *t, const void *k)
|
|
||||||
{
|
{
|
||||||
void *result;
|
return lh_table_lookup_entry_w_hash(t, k, lh_get_hash(t, k));
|
||||||
lh_table_lookup_ex(t, k, &result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
|
json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
|
||||||
{
|
{
|
||||||
struct lh_entry *e = lh_table_lookup_entry(t, k);
|
struct lh_entry *e = lh_table_lookup_entry(t, k);
|
||||||
if (e != NULL) {
|
if (e != NULL)
|
||||||
if (v != NULL) *v = (void *)e->v;
|
{
|
||||||
return TRUE; /* key found */
|
if (v != NULL)
|
||||||
|
*v = lh_entry_v(e);
|
||||||
|
return 1; /* key found */
|
||||||
}
|
}
|
||||||
if (v != NULL) *v = NULL;
|
if (v != NULL)
|
||||||
return FALSE; /* key not found */
|
*v = NULL;
|
||||||
|
return 0; /* key not found */
|
||||||
}
|
}
|
||||||
|
|
||||||
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
|
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
|
||||||
{
|
{
|
||||||
ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */
|
/* CAW: fixed to be 64bit nice, still need the crazy negative case... */
|
||||||
|
ptrdiff_t n = (ptrdiff_t)(e - t->table);
|
||||||
|
|
||||||
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
|
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
|
||||||
if(n < 0) { return -2; }
|
if (n < 0)
|
||||||
|
{
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1;
|
if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
|
||||||
|
return -1;
|
||||||
t->count--;
|
t->count--;
|
||||||
if(t->free_fn) t->free_fn(e);
|
if (t->free_fn)
|
||||||
|
t->free_fn(e);
|
||||||
t->table[n].v = NULL;
|
t->table[n].v = NULL;
|
||||||
t->table[n].k = LH_FREED;
|
t->table[n].k = LH_FREED;
|
||||||
if(t->tail == &t->table[n] && t->head == &t->table[n]) {
|
if (t->tail == &t->table[n] && t->head == &t->table[n])
|
||||||
|
{
|
||||||
t->head = t->tail = NULL;
|
t->head = t->tail = NULL;
|
||||||
} else if (t->head == &t->table[n]) {
|
}
|
||||||
|
else if (t->head == &t->table[n])
|
||||||
|
{
|
||||||
t->head->next->prev = NULL;
|
t->head->next->prev = NULL;
|
||||||
t->head = t->head->next;
|
t->head = t->head->next;
|
||||||
} else if (t->tail == &t->table[n]) {
|
}
|
||||||
|
else if (t->tail == &t->table[n])
|
||||||
|
{
|
||||||
t->tail->prev->next = NULL;
|
t->tail->prev->next = NULL;
|
||||||
t->tail = t->tail->prev;
|
t->tail = t->tail->prev;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
t->table[n].prev->next = t->table[n].next;
|
t->table[n].prev->next = t->table[n].next;
|
||||||
t->table[n].next->prev = t->table[n].prev;
|
t->table[n].next->prev = t->table[n].prev;
|
||||||
}
|
}
|
||||||
@@ -588,11 +702,11 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lh_table_delete(struct lh_table *t, const void *k)
|
int lh_table_delete(struct lh_table *t, const void *k)
|
||||||
{
|
{
|
||||||
struct lh_entry *e = lh_table_lookup_entry(t, k);
|
struct lh_entry *e = lh_table_lookup_entry(t, k);
|
||||||
if(!e) return -1;
|
if (!e)
|
||||||
|
return -1;
|
||||||
return lh_table_delete_entry(t, e);
|
return lh_table_delete_entry(t, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
245
linkhash.h
245
linkhash.h
@@ -10,6 +10,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Internal methods for working with json_type_object objects. Although
|
||||||
|
* this is exposed by the json_object_get_object() function and within the
|
||||||
|
* json_object_iter type, it is not recommended for direct use.
|
||||||
|
*/
|
||||||
#ifndef _linkhash_h_
|
#ifndef _linkhash_h_
|
||||||
#define _linkhash_h_
|
#define _linkhash_h_
|
||||||
|
|
||||||
@@ -41,6 +47,23 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define LH_FREED (void *)-2
|
#define LH_FREED (void *)-2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default string hash function
|
||||||
|
*/
|
||||||
|
#define JSON_C_STR_HASH_DFLT 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* perl-like string hash function
|
||||||
|
*/
|
||||||
|
#define JSON_C_STR_HASH_PERLLIKE 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function sets the hash function to be used for strings.
|
||||||
|
* Must be one of the JSON_C_STR_HASH_* values.
|
||||||
|
* @returns 0 - ok, -1 if parameter was invalid
|
||||||
|
*/
|
||||||
|
int json_global_set_string_hash(const int h);
|
||||||
|
|
||||||
struct lh_entry;
|
struct lh_entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,13 +82,19 @@ typedef int (lh_equal_fn) (const void *k1, const void *k2);
|
|||||||
/**
|
/**
|
||||||
* An entry in the hash table
|
* An entry in the hash table
|
||||||
*/
|
*/
|
||||||
struct lh_entry {
|
struct lh_entry
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* The key.
|
* The key. Use lh_entry_k() instead of accessing this directly.
|
||||||
*/
|
*/
|
||||||
void *k;
|
const void *k;
|
||||||
/**
|
/**
|
||||||
* The value.
|
* A flag for users of linkhash to know whether or not they
|
||||||
|
* need to free k.
|
||||||
|
*/
|
||||||
|
int k_is_constant;
|
||||||
|
/**
|
||||||
|
* The value. Use lh_entry_v() instead of accessing this directly.
|
||||||
*/
|
*/
|
||||||
const void *v;
|
const void *v;
|
||||||
/**
|
/**
|
||||||
@@ -78,11 +107,11 @@ struct lh_entry {
|
|||||||
struct lh_entry *prev;
|
struct lh_entry *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hash table structure.
|
* The hash table structure.
|
||||||
*/
|
*/
|
||||||
struct lh_table {
|
struct lh_table
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Size of our hash.
|
* Size of our hash.
|
||||||
*/
|
*/
|
||||||
@@ -92,36 +121,6 @@ struct lh_table {
|
|||||||
*/
|
*/
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of collisions.
|
|
||||||
*/
|
|
||||||
int collisions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of resizes.
|
|
||||||
*/
|
|
||||||
int resizes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of lookups.
|
|
||||||
*/
|
|
||||||
int lookups;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of inserts.
|
|
||||||
*/
|
|
||||||
int inserts;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of deletes.
|
|
||||||
*/
|
|
||||||
int deletes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the hash table.
|
|
||||||
*/
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first entry.
|
* The first entry.
|
||||||
*/
|
*/
|
||||||
@@ -141,37 +140,28 @@ struct lh_table {
|
|||||||
lh_hash_fn *hash_fn;
|
lh_hash_fn *hash_fn;
|
||||||
lh_equal_fn *equal_fn;
|
lh_equal_fn *equal_fn;
|
||||||
};
|
};
|
||||||
|
typedef struct lh_table lh_table;
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-defined hash and equality functions
|
|
||||||
*/
|
|
||||||
extern unsigned long lh_ptr_hash(const void *k);
|
|
||||||
extern int lh_ptr_equal(const void *k1, const void *k2);
|
|
||||||
|
|
||||||
extern unsigned long lh_char_hash(const void *k);
|
|
||||||
extern int lh_char_equal(const void *k1, const void *k2);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience list iterator.
|
* Convenience list iterator.
|
||||||
*/
|
*/
|
||||||
#define lh_foreach(table, entry) \
|
#define lh_foreach(table, entry) for (entry = table->head; entry; entry = entry->next)
|
||||||
for(entry = table->head; entry; entry = entry->next)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lh_foreach_safe allows calling of deletion routine while iterating.
|
* lh_foreach_safe allows calling of deletion routine while iterating.
|
||||||
|
*
|
||||||
|
* @param table a struct lh_table * to iterate over
|
||||||
|
* @param entry a struct lh_entry * variable to hold each element
|
||||||
|
* @param tmp a struct lh_entry * variable to hold a temporary pointer to the next element
|
||||||
*/
|
*/
|
||||||
#define lh_foreach_safe(table, entry, tmp) \
|
#define lh_foreach_safe(table, entry, tmp) \
|
||||||
for (entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
|
for (entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new linkhash table.
|
* Create a new linkhash table.
|
||||||
|
*
|
||||||
* @param size initial table size. The table is automatically resized
|
* @param size initial table size. The table is automatically resized
|
||||||
* although this incurs a performance penalty.
|
* although this incurs a performance penalty.
|
||||||
* @param name the table name.
|
|
||||||
* @param free_fn callback function used to free memory for entries
|
* @param free_fn callback function used to free memory for entries
|
||||||
* when lh_table_free or lh_table_delete is called.
|
* when lh_table_free or lh_table_delete is called.
|
||||||
* If NULL is provided, then memory for keys and values
|
* If NULL is provided, then memory for keys and values
|
||||||
@@ -182,57 +172,74 @@ for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
|
|||||||
* @param equal_fn comparison function to compare keys. 2 standard ones defined:
|
* @param equal_fn comparison function to compare keys. 2 standard ones defined:
|
||||||
* lh_ptr_hash and lh_char_hash for comparing pointer values
|
* lh_ptr_hash and lh_char_hash for comparing pointer values
|
||||||
* and C strings respectively.
|
* and C strings respectively.
|
||||||
* @return a pointer onto the linkhash table.
|
* @return On success, a pointer to the new linkhash table is returned.
|
||||||
|
* On error, a null pointer is returned.
|
||||||
*/
|
*/
|
||||||
extern struct lh_table* lh_table_new(int size, const char *name,
|
extern struct lh_table *lh_table_new(int size, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn,
|
||||||
lh_entry_free_fn *free_fn,
|
|
||||||
lh_hash_fn *hash_fn,
|
|
||||||
lh_equal_fn *equal_fn);
|
lh_equal_fn *equal_fn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to create a new linkhash
|
* Convenience function to create a new linkhash table with char keys.
|
||||||
* table with char keys.
|
*
|
||||||
* @param size initial table size.
|
* @param size initial table size.
|
||||||
* @param name table name.
|
|
||||||
* @param free_fn callback function used to free memory for entries.
|
* @param free_fn callback function used to free memory for entries.
|
||||||
* @return a pointer onto the linkhash table.
|
* @return On success, a pointer to the new linkhash table is returned.
|
||||||
|
* On error, a null pointer is returned.
|
||||||
*/
|
*/
|
||||||
extern struct lh_table* lh_kchar_table_new(int size, const char *name,
|
extern struct lh_table *lh_kchar_table_new(int size, lh_entry_free_fn *free_fn);
|
||||||
lh_entry_free_fn *free_fn);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to create a new linkhash
|
* Convenience function to create a new linkhash table with ptr keys.
|
||||||
* table with ptr keys.
|
*
|
||||||
* @param size initial table size.
|
* @param size initial table size.
|
||||||
* @param name table name.
|
|
||||||
* @param free_fn callback function used to free memory for entries.
|
* @param free_fn callback function used to free memory for entries.
|
||||||
* @return a pointer onto the linkhash table.
|
* @return On success, a pointer to the new linkhash table is returned.
|
||||||
|
* On error, a null pointer is returned.
|
||||||
*/
|
*/
|
||||||
extern struct lh_table* lh_kptr_table_new(int size, const char *name,
|
extern struct lh_table *lh_kptr_table_new(int size, lh_entry_free_fn *free_fn);
|
||||||
lh_entry_free_fn *free_fn);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a linkhash table.
|
* Free a linkhash table.
|
||||||
* If a callback free function is provided then it is called for all
|
*
|
||||||
* entries in the table.
|
* If a lh_entry_free_fn callback free function was provided then it is
|
||||||
|
* called for all entries in the table.
|
||||||
|
*
|
||||||
* @param t table to free.
|
* @param t table to free.
|
||||||
*/
|
*/
|
||||||
extern void lh_table_free(struct lh_table *t);
|
extern void lh_table_free(struct lh_table *t);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a record into the table.
|
* Insert a record into the table.
|
||||||
|
*
|
||||||
* @param t the table to insert into.
|
* @param t the table to insert into.
|
||||||
* @param k a pointer to the key to insert.
|
* @param k a pointer to the key to insert.
|
||||||
* @param v a pointer to the value to insert.
|
* @param v a pointer to the value to insert.
|
||||||
|
*
|
||||||
|
* @return On success, <code>0</code> is returned.
|
||||||
|
* On error, a negative value is returned.
|
||||||
*/
|
*/
|
||||||
extern int lh_table_insert(struct lh_table *t, void *k, const void *v);
|
extern int lh_table_insert(struct lh_table *t, const void *k, const void *v);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a record into the table.
|
* Insert a record into the table using a precalculated key hash.
|
||||||
|
*
|
||||||
|
* The hash h, which should be calculated with lh_get_hash() on k, is provided by
|
||||||
|
* the caller, to allow for optimization when multiple operations with the same
|
||||||
|
* key are known to be needed.
|
||||||
|
*
|
||||||
|
* @param t the table to insert into.
|
||||||
|
* @param k a pointer to the key to insert.
|
||||||
|
* @param v a pointer to the value to insert.
|
||||||
|
* @param h hash value of the key to insert
|
||||||
|
* @param opts if set to JSON_C_OBJECT_KEY_IS_CONSTANT, sets lh_entry.k_is_constant
|
||||||
|
* so t's free function knows to avoid freeing the key.
|
||||||
|
*/
|
||||||
|
extern int lh_table_insert_w_hash(struct lh_table *t, const void *k, const void *v,
|
||||||
|
const unsigned long h, const unsigned opts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a record in the table.
|
||||||
|
*
|
||||||
* @param t the table to lookup
|
* @param t the table to lookup
|
||||||
* @param k a pointer to the key to lookup
|
* @param k a pointer to the key to lookup
|
||||||
* @return a pointer to the record structure of the value or NULL if it does not exist.
|
* @return a pointer to the record structure of the value or NULL if it does not exist.
|
||||||
@@ -240,16 +247,23 @@ extern int lh_table_insert(struct lh_table *t, void *k, const void *v);
|
|||||||
extern struct lh_entry *lh_table_lookup_entry(struct lh_table *t, const void *k);
|
extern struct lh_entry *lh_table_lookup_entry(struct lh_table *t, const void *k);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a record into the table
|
* Lookup a record in the table using a precalculated key hash.
|
||||||
|
*
|
||||||
|
* The hash h, which should be calculated with lh_get_hash() on k, is provided by
|
||||||
|
* the caller, to allow for optimization when multiple operations with the same
|
||||||
|
* key are known to be needed.
|
||||||
|
*
|
||||||
* @param t the table to lookup
|
* @param t the table to lookup
|
||||||
* @param k a pointer to the key to lookup
|
* @param k a pointer to the key to lookup
|
||||||
* @return a pointer to the found value or NULL if it does not exist.
|
* @param h hash value of the key to lookup
|
||||||
* @deprecated Use lh_table_lookup_ex instead.
|
* @return a pointer to the record structure of the value or NULL if it does not exist.
|
||||||
*/
|
*/
|
||||||
THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table *t, const void *k));
|
extern struct lh_entry *lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k,
|
||||||
|
const unsigned long h);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a record in the table
|
* Lookup a record in the table.
|
||||||
|
*
|
||||||
* @param t the table to lookup
|
* @param t the table to lookup
|
||||||
* @param k a pointer to the key to lookup
|
* @param k a pointer to the key to lookup
|
||||||
* @param v a pointer to a where to store the found value (set to NULL if it doesn't exist).
|
* @param v a pointer to a where to store the found value (set to NULL if it doesn't exist).
|
||||||
@@ -259,6 +273,7 @@ extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a record from the table.
|
* Delete a record from the table.
|
||||||
|
*
|
||||||
* If a callback free function is provided then it is called for the
|
* If a callback free function is provided then it is called for the
|
||||||
* for the item being deleted.
|
* for the item being deleted.
|
||||||
* @param t the table to delete from.
|
* @param t the table to delete from.
|
||||||
@@ -268,9 +283,9 @@ extern json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
|
|||||||
*/
|
*/
|
||||||
extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
|
extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a record from the table.
|
* Delete a record from the table.
|
||||||
|
*
|
||||||
* If a callback free function is provided then it is called for the
|
* If a callback free function is provided then it is called for the
|
||||||
* for the item being deleted.
|
* for the item being deleted.
|
||||||
* @param t the table to delete from.
|
* @param t the table to delete from.
|
||||||
@@ -282,8 +297,70 @@ extern int lh_table_delete(struct lh_table *t, const void *k);
|
|||||||
|
|
||||||
extern int lh_table_length(struct lh_table *t);
|
extern int lh_table_length(struct lh_table *t);
|
||||||
|
|
||||||
void lh_abort(const char *msg, ...);
|
/**
|
||||||
void lh_table_resize(struct lh_table *t, int new_size);
|
* Resizes the specified table.
|
||||||
|
*
|
||||||
|
* @param t Pointer to table to resize.
|
||||||
|
* @param new_size New table size. Must be positive.
|
||||||
|
*
|
||||||
|
* @return On success, <code>0</code> is returned.
|
||||||
|
* On error, a negative value is returned.
|
||||||
|
*/
|
||||||
|
int lh_table_resize(struct lh_table *t, int new_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Don't use this outside of linkhash.h:
|
||||||
|
*/
|
||||||
|
#if !defined(_MSC_VER) || (_MSC_VER > 1800)
|
||||||
|
/* VS2010 can't handle inline funcs, so skip it there */
|
||||||
|
#define _LH_INLINE inline
|
||||||
|
#else
|
||||||
|
#define _LH_INLINE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the hash of a key for a given table.
|
||||||
|
*
|
||||||
|
* This is an exension to support functions that need to calculate
|
||||||
|
* the hash several times and allows them to do it just once and then pass
|
||||||
|
* in the hash to all utility functions. Depending on use case, this can be a
|
||||||
|
* considerable performance improvement.
|
||||||
|
* @param t the table (used to obtain hash function)
|
||||||
|
* @param k a pointer to the key to lookup
|
||||||
|
* @return the key's hash
|
||||||
|
*/
|
||||||
|
static _LH_INLINE unsigned long lh_get_hash(const struct lh_table *t, const void *k)
|
||||||
|
{
|
||||||
|
return t->hash_fn(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef _LH_INLINE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Don't use this outside of linkhash.h:
|
||||||
|
*/
|
||||||
|
#ifdef __UNCONST
|
||||||
|
#define _LH_UNCONST(a) __UNCONST(a)
|
||||||
|
#else
|
||||||
|
#define _LH_UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a non-const version of lh_entry.k.
|
||||||
|
*
|
||||||
|
* lh_entry.k is const to indicate and help ensure that linkhash itself doesn't modify
|
||||||
|
* it, but callers are allowed to do what they want with it.
|
||||||
|
* See also lh_entry.k_is_constant
|
||||||
|
*/
|
||||||
|
#define lh_entry_k(entry) _LH_UNCONST((entry)->k)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a non-const version of lh_entry.v.
|
||||||
|
*
|
||||||
|
* v is const to indicate and help ensure that linkhash itself doesn't modify
|
||||||
|
* it, but callers are allowed to do what they want with it.
|
||||||
|
*/
|
||||||
|
#define lh_entry_v(entry) _LH_UNCONST((entry)->v)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
#ifndef __math_compat_h
|
#ifndef __math_compat_h
|
||||||
#define __math_compat_h
|
#define __math_compat_h
|
||||||
|
|
||||||
/* Define isnan and isinf on Windows/MSVC */
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define isnan, isinf, infinity and nan on Windows/MSVC */
|
||||||
|
|
||||||
#ifndef HAVE_DECL_ISNAN
|
#ifndef HAVE_DECL_ISNAN
|
||||||
#ifdef HAVE_DECL__ISNAN
|
#ifdef HAVE_DECL__ISNAN
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#define isnan(x) _isnan(x)
|
#define isnan(x) _isnan(x)
|
||||||
|
#else
|
||||||
|
/* On platforms like AIX and "IBM i" we need to provide our own isnan */
|
||||||
|
#define isnan(x) ((x) != (x))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -14,15 +22,22 @@
|
|||||||
#ifdef HAVE_DECL__FINITE
|
#ifdef HAVE_DECL__FINITE
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#define isinf(x) (!_finite(x))
|
#define isinf(x) (!_finite(x))
|
||||||
|
#else
|
||||||
|
#include <float.h>
|
||||||
|
/* On platforms like AIX and "IBM i" we need to provide our own isinf */
|
||||||
|
#define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_DECL_NAN
|
|
||||||
#error This platform does not have nan()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_DECL_INFINITY
|
#ifndef HAVE_DECL_INFINITY
|
||||||
#error This platform does not have INFINITY
|
#include <float.h>
|
||||||
|
#define INFINITY (DBL_MAX + DBL_MAX)
|
||||||
|
#define HAVE_DECL_INFINITY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_DECL_NAN
|
||||||
|
#define NAN (INFINITY - INFINITY)
|
||||||
|
#define HAVE_DECL_NAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
97
printbuf.c
97
printbuf.c
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -25,9 +26,10 @@
|
|||||||
#error Not enough var arg support!
|
#error Not enough var arg support!
|
||||||
#endif /* HAVE_STDARG_H */
|
#endif /* HAVE_STDARG_H */
|
||||||
|
|
||||||
#include "bits.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "printbuf.h"
|
#include "printbuf.h"
|
||||||
|
#include "snprintf_compat.h"
|
||||||
|
#include "vasprintf_compat.h"
|
||||||
|
|
||||||
static int printbuf_extend(struct printbuf *p, int min_size);
|
static int printbuf_extend(struct printbuf *p, int min_size);
|
||||||
|
|
||||||
@@ -36,17 +38,19 @@ struct printbuf* printbuf_new(void)
|
|||||||
struct printbuf *p;
|
struct printbuf *p;
|
||||||
|
|
||||||
p = (struct printbuf *)calloc(1, sizeof(struct printbuf));
|
p = (struct printbuf *)calloc(1, sizeof(struct printbuf));
|
||||||
if(!p) return NULL;
|
if (!p)
|
||||||
|
return NULL;
|
||||||
p->size = 32;
|
p->size = 32;
|
||||||
p->bpos = 0;
|
p->bpos = 0;
|
||||||
if(!(p->buf = (char*)malloc(p->size))) {
|
if (!(p->buf = (char *)malloc(p->size)))
|
||||||
|
{
|
||||||
free(p);
|
free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
p->buf[0] = '\0';
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the buffer p so it has a size of at least min_size.
|
* Extend the buffer p so it has a size of at least min_size.
|
||||||
*
|
*
|
||||||
@@ -62,8 +66,16 @@ static int printbuf_extend(struct printbuf *p, int min_size)
|
|||||||
|
|
||||||
if (p->size >= min_size)
|
if (p->size >= min_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
/* Prevent signed integer overflows with large buffers. */
|
||||||
new_size = json_max(p->size * 2, min_size + 8);
|
if (min_size > INT_MAX - 8)
|
||||||
|
return -1;
|
||||||
|
if (p->size > INT_MAX / 2)
|
||||||
|
new_size = min_size + 8;
|
||||||
|
else {
|
||||||
|
new_size = p->size * 2;
|
||||||
|
if (new_size < min_size + 8)
|
||||||
|
new_size = min_size + 8;
|
||||||
|
}
|
||||||
#ifdef PRINTBUF_DEBUG
|
#ifdef PRINTBUF_DEBUG
|
||||||
MC_DEBUG("printbuf_memappend: realloc "
|
MC_DEBUG("printbuf_memappend: realloc "
|
||||||
"bpos=%d min_size=%d old_size=%d new_size=%d\n",
|
"bpos=%d min_size=%d old_size=%d new_size=%d\n",
|
||||||
@@ -78,7 +90,11 @@ static int printbuf_extend(struct printbuf *p, int min_size)
|
|||||||
|
|
||||||
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
|
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
|
||||||
{
|
{
|
||||||
if (p->size <= p->bpos + size + 1) {
|
/* Prevent signed integer overflows with large buffers. */
|
||||||
|
if (size > INT_MAX - p->bpos - 1)
|
||||||
|
return -1;
|
||||||
|
if (p->size <= p->bpos + size + 1)
|
||||||
|
{
|
||||||
if (printbuf_extend(p, p->bpos + size + 1) < 0)
|
if (printbuf_extend(p, p->bpos + size + 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -94,6 +110,9 @@ int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len)
|
|||||||
|
|
||||||
if (offset == -1)
|
if (offset == -1)
|
||||||
offset = pb->bpos;
|
offset = pb->bpos;
|
||||||
|
/* Prevent signed integer overflows with large buffers. */
|
||||||
|
if (len > INT_MAX - offset)
|
||||||
|
return -1;
|
||||||
size_needed = offset + len;
|
size_needed = offset + len;
|
||||||
if (pb->size < size_needed)
|
if (pb->size < size_needed)
|
||||||
{
|
{
|
||||||
@@ -108,47 +127,6 @@ int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(HAVE_VSNPRINTF) && defined(_MSC_VER)
|
|
||||||
# define vsnprintf _vsnprintf
|
|
||||||
#elif !defined(HAVE_VSNPRINTF) /* !HAVE_VSNPRINTF */
|
|
||||||
# error Need vsnprintf!
|
|
||||||
#endif /* !HAVE_VSNPRINTF && defined(WIN32) */
|
|
||||||
|
|
||||||
#if !defined(HAVE_VASPRINTF)
|
|
||||||
/* CAW: compliant version of vasprintf */
|
|
||||||
static int vasprintf(char **buf, const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
|
||||||
static char _T_emptybuffer = '\0';
|
|
||||||
#endif /* !defined(WIN32) */
|
|
||||||
int chars;
|
|
||||||
char *b;
|
|
||||||
|
|
||||||
if(!buf) { return -1; }
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
chars = _vscprintf(fmt, ap)+1;
|
|
||||||
#else /* !defined(WIN32) */
|
|
||||||
/* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
|
|
||||||
our buffer like on some 64bit sun systems.... but hey, its time to move on */
|
|
||||||
chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1;
|
|
||||||
if(chars < 0) { chars *= -1; } /* CAW: old glibc versions have this problem */
|
|
||||||
#endif /* defined(WIN32) */
|
|
||||||
|
|
||||||
b = (char*)malloc(sizeof(char)*chars);
|
|
||||||
if(!b) { return -1; }
|
|
||||||
|
|
||||||
if((chars = vsprintf(b, fmt, ap)) < 0)
|
|
||||||
{
|
|
||||||
free(b);
|
|
||||||
} else {
|
|
||||||
*buf = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
return chars;
|
|
||||||
}
|
|
||||||
#endif /* !HAVE_VASPRINTF */
|
|
||||||
|
|
||||||
int sprintbuf(struct printbuf *p, const char *msg, ...)
|
int sprintbuf(struct printbuf *p, const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@@ -161,17 +139,25 @@ int sprintbuf(struct printbuf *p, const char *msg, ...)
|
|||||||
size = vsnprintf(buf, 128, msg, ap);
|
size = vsnprintf(buf, 128, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
/* if string is greater than stack buffer, then use dynamic string
|
/* if string is greater than stack buffer, then use dynamic string
|
||||||
with vasprintf. Note: some implementation of vsnprintf return -1
|
* with vasprintf. Note: some implementation of vsnprintf return -1
|
||||||
if output is truncated whereas some return the number of bytes that
|
* if output is truncated whereas some return the number of bytes that
|
||||||
would have been written - this code handles both cases. */
|
* would have been written - this code handles both cases.
|
||||||
if(size == -1 || size > 127) {
|
*/
|
||||||
|
if (size == -1 || size > 127)
|
||||||
|
{
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
if((size = vasprintf(&t, msg, ap)) < 0) { va_end(ap); return -1; }
|
if ((size = vasprintf(&t, msg, ap)) < 0)
|
||||||
|
{
|
||||||
|
va_end(ap);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
printbuf_memappend(p, t, size);
|
printbuf_memappend(p, t, size);
|
||||||
free(t);
|
free(t);
|
||||||
return size;
|
return size;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printbuf_memappend(p, buf, size);
|
printbuf_memappend(p, buf, size);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -185,7 +171,8 @@ void printbuf_reset(struct printbuf *p)
|
|||||||
|
|
||||||
void printbuf_free(struct printbuf *p)
|
void printbuf_free(struct printbuf *p)
|
||||||
{
|
{
|
||||||
if(p) {
|
if (p)
|
||||||
|
{
|
||||||
free(p->buf);
|
free(p->buf);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|||||||
94
printbuf.h
94
printbuf.h
@@ -13,43 +13,87 @@
|
|||||||
* (http://www.opensource.org/licenses/mit-license.php)
|
* (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Internal string buffer handing. Unless you're writing a
|
||||||
|
* json_object_to_json_string_fn implementation for use with
|
||||||
|
* json_object_set_serializer() direct use of this is not
|
||||||
|
* recommended.
|
||||||
|
*/
|
||||||
#ifndef _printbuf_h_
|
#ifndef _printbuf_h_
|
||||||
#define _printbuf_h_
|
#define _printbuf_h_
|
||||||
|
|
||||||
|
#ifndef JSON_EXPORT
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define JSON_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JSON_EXPORT extern
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct printbuf {
|
struct printbuf
|
||||||
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
int bpos;
|
int bpos;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
typedef struct printbuf printbuf;
|
||||||
|
|
||||||
extern struct printbuf*
|
JSON_EXPORT struct printbuf *printbuf_new(void);
|
||||||
printbuf_new(void);
|
|
||||||
|
|
||||||
/* As an optimization, printbuf_memappend_fast is defined as a macro
|
/* As an optimization, printbuf_memappend_fast() is defined as a macro
|
||||||
* that handles copying data if the buffer is large enough; otherwise
|
* that handles copying data if the buffer is large enough; otherwise
|
||||||
* it invokes printbuf_memappend_real() which performs the heavy
|
* it invokes printbuf_memappend() which performs the heavy
|
||||||
* lifting of realloc()ing the buffer and copying data.
|
* lifting of realloc()ing the buffer and copying data.
|
||||||
* Your code should not use printbuf_memappend directly--use
|
*
|
||||||
* printbuf_memappend_fast instead.
|
* Your code should not use printbuf_memappend() directly unless it
|
||||||
|
* checks the return code. Use printbuf_memappend_fast() instead.
|
||||||
*/
|
*/
|
||||||
extern int
|
JSON_EXPORT int printbuf_memappend(struct printbuf *p, const char *buf, int size);
|
||||||
printbuf_memappend(struct printbuf *p, const char *buf, int size);
|
|
||||||
|
|
||||||
#define printbuf_memappend_fast(p, bufptr, bufsize) \
|
#define printbuf_memappend_fast(p, bufptr, bufsize) \
|
||||||
do { \
|
do \
|
||||||
if ((p->size - p->bpos) > bufsize) { \
|
{ \
|
||||||
|
if ((p->size - p->bpos) > bufsize) \
|
||||||
|
{ \
|
||||||
memcpy(p->buf + p->bpos, (bufptr), bufsize); \
|
memcpy(p->buf + p->bpos, (bufptr), bufsize); \
|
||||||
p->bpos += bufsize; \
|
p->bpos += bufsize; \
|
||||||
p->buf[p->bpos] = '\0'; \
|
p->buf[p->bpos] = '\0'; \
|
||||||
} else { printbuf_memappend(p, (bufptr), bufsize); } \
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
printbuf_memappend(p, (bufptr), bufsize); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define printbuf_length(p) ((p)->bpos)
|
#define printbuf_length(p) ((p)->bpos)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Results in a compile error if the argument is not a string literal.
|
||||||
|
*/
|
||||||
|
#define _printbuf_check_literal(mystr) ("" mystr)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an optimization wrapper around printbuf_memappend() that is useful
|
||||||
|
* for appending string literals. Since the size of string constants is known
|
||||||
|
* at compile time, using this macro can avoid a costly strlen() call. This is
|
||||||
|
* especially helpful when a constant string must be appended many times. If
|
||||||
|
* you got here because of a compilation error caused by passing something
|
||||||
|
* other than a string literal, use printbuf_memappend_fast() in conjunction
|
||||||
|
* with strlen().
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* printbuf_memappend_fast()
|
||||||
|
* printbuf_memappend()
|
||||||
|
* sprintbuf()
|
||||||
|
*/
|
||||||
|
#define printbuf_strappend(pb, str) \
|
||||||
|
printbuf_memappend((pb), _printbuf_check_literal(str), sizeof(str) - 1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set len bytes of the buffer to charvalue, starting at offset offset.
|
* Set len bytes of the buffer to charvalue, starting at offset offset.
|
||||||
* Similar to calling memset(x, charvalue, len);
|
* Similar to calling memset(x, charvalue, len);
|
||||||
@@ -58,17 +102,27 @@ do { \
|
|||||||
*
|
*
|
||||||
* If offset is -1, this starts at the end of the current data in the buffer.
|
* If offset is -1, this starts at the end of the current data in the buffer.
|
||||||
*/
|
*/
|
||||||
extern int
|
JSON_EXPORT int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len);
|
||||||
printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len);
|
|
||||||
|
|
||||||
extern int
|
/**
|
||||||
sprintbuf(struct printbuf *p, const char *msg, ...);
|
* Formatted print to printbuf.
|
||||||
|
*
|
||||||
|
* This function is the most expensive of the available functions for appending
|
||||||
|
* string data to a printbuf and should be used only where convenience is more
|
||||||
|
* important than speed. Avoid using this function in high performance code or
|
||||||
|
* tight loops; in these scenarios, consider using snprintf() with a static
|
||||||
|
* buffer in conjunction with one of the printbuf_*append() functions.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* printbuf_memappend_fast()
|
||||||
|
* printbuf_memappend()
|
||||||
|
* printbuf_strappend()
|
||||||
|
*/
|
||||||
|
JSON_EXPORT int sprintbuf(struct printbuf *p, const char *msg, ...);
|
||||||
|
|
||||||
extern void
|
JSON_EXPORT void printbuf_reset(struct printbuf *p);
|
||||||
printbuf_reset(struct printbuf *p);
|
|
||||||
|
|
||||||
extern void
|
JSON_EXPORT void printbuf_free(struct printbuf *p);
|
||||||
printbuf_free(struct printbuf *p);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
152
random_seed.c
152
random_seed.c
@@ -9,12 +9,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "random_seed.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "strerror_override.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define DEBUG_SEED(s)
|
#define DEBUG_SEED(s)
|
||||||
|
|
||||||
|
|
||||||
#if defined ENABLE_RDRAND
|
#if defined ENABLE_RDRAND
|
||||||
|
|
||||||
/* cpuid */
|
/* cpuid */
|
||||||
@@ -24,20 +25,11 @@
|
|||||||
|
|
||||||
static void do_cpuid(int regs[], int h)
|
static void do_cpuid(int regs[], int h)
|
||||||
{
|
{
|
||||||
__asm__ __volatile__(
|
/* clang-format off */
|
||||||
#if defined __x86_64__
|
__asm__ __volatile__("cpuid"
|
||||||
"pushq %%rbx;\n"
|
: "=a"(regs[0]), "=b"(regs[1]), "=c"(regs[2]), "=d"(regs[3])
|
||||||
#else
|
|
||||||
"pushl %%ebx;\n"
|
|
||||||
#endif
|
|
||||||
"cpuid;\n"
|
|
||||||
#if defined __x86_64__
|
|
||||||
"popq %%rbx;\n"
|
|
||||||
#else
|
|
||||||
"popl %%ebx;\n"
|
|
||||||
#endif
|
|
||||||
: "=a"(regs[0]), [ebx] "=r"(regs[1]), "=c"(regs[2]), "=d"(regs[3])
|
|
||||||
: "a"(h));
|
: "a"(h));
|
||||||
|
/* clang-format on */
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined _MSC_VER
|
#elif defined _MSC_VER
|
||||||
@@ -51,12 +43,51 @@ static void do_cpuid(int regs[], int h)
|
|||||||
|
|
||||||
#if HAS_X86_CPUID
|
#if HAS_X86_CPUID
|
||||||
|
|
||||||
static int has_rdrand()
|
static int get_rdrand_seed(void);
|
||||||
|
|
||||||
|
/* Valid values are -1 (haven't tested), 0 (no), and 1 (yes). */
|
||||||
|
static int _has_rdrand = -1;
|
||||||
|
|
||||||
|
static int has_rdrand(void)
|
||||||
{
|
{
|
||||||
// CPUID.01H:ECX.RDRAND[bit 30] == 1
|
if (_has_rdrand != -1)
|
||||||
|
{
|
||||||
|
return _has_rdrand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CPUID.01H:ECX.RDRAND[bit 30] == 1 */
|
||||||
int regs[4];
|
int regs[4];
|
||||||
do_cpuid(regs, 1);
|
do_cpuid(regs, 1);
|
||||||
return (regs[2] & (1 << 30)) != 0;
|
if (!(regs[2] & (1 << 30)))
|
||||||
|
{
|
||||||
|
_has_rdrand = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some CPUs advertise RDRAND in CPUID, but return 0xFFFFFFFF
|
||||||
|
* unconditionally. To avoid locking up later, test RDRAND here. If over
|
||||||
|
* 3 trials RDRAND has returned the same value, declare it broken.
|
||||||
|
* Example CPUs are AMD Ryzen 3000 series
|
||||||
|
* and much older AMD APUs, such as the E1-1500
|
||||||
|
* https://github.com/systemd/systemd/issues/11810
|
||||||
|
* https://linuxreviews.org/RDRAND_stops_returning_random_values_on_older_AMD_CPUs_after_suspend
|
||||||
|
*/
|
||||||
|
_has_rdrand = 0;
|
||||||
|
int prev = get_rdrand_seed();
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
int temp = get_rdrand_seed();
|
||||||
|
if (temp != prev)
|
||||||
|
{
|
||||||
|
_has_rdrand = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _has_rdrand;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -67,16 +98,18 @@ static int has_rdrand()
|
|||||||
|
|
||||||
#define HAVE_RDRAND 1
|
#define HAVE_RDRAND 1
|
||||||
|
|
||||||
static int get_rdrand_seed()
|
static int get_rdrand_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_rdrand_seed");
|
DEBUG_SEED("get_rdrand_seed");
|
||||||
int _eax;
|
int _eax;
|
||||||
// rdrand eax
|
/* rdrand eax */
|
||||||
|
/* clang-format off */
|
||||||
__asm__ __volatile__("1: .byte 0x0F\n"
|
__asm__ __volatile__("1: .byte 0x0F\n"
|
||||||
" .byte 0xC7\n"
|
" .byte 0xC7\n"
|
||||||
" .byte 0xF0\n"
|
" .byte 0xF0\n"
|
||||||
" jnc 1b;\n"
|
" jnc 1b;\n"
|
||||||
: "=a" (_eax));
|
: "=a" (_eax));
|
||||||
|
/* clang-format on */
|
||||||
return _eax;
|
return _eax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,11 +122,12 @@ static int get_rdrand_seed()
|
|||||||
|
|
||||||
/* get_rdrand_seed - Visual Studio 2012 and above */
|
/* get_rdrand_seed - Visual Studio 2012 and above */
|
||||||
|
|
||||||
static int get_rdrand_seed()
|
static int get_rdrand_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_rdrand_seed");
|
DEBUG_SEED("get_rdrand_seed");
|
||||||
int r;
|
int r;
|
||||||
while (_rdrand32_step(&r) == 0);
|
while (_rdrand32_step(&r) == 0)
|
||||||
|
;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,32 +136,34 @@ static int get_rdrand_seed()
|
|||||||
|
|
||||||
/* get_rdrand_seed - Visual Studio 2010 and below - x86 only */
|
/* get_rdrand_seed - Visual Studio 2010 and below - x86 only */
|
||||||
|
|
||||||
static int get_rdrand_seed()
|
/* clang-format off */
|
||||||
|
static int get_rdrand_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_rdrand_seed");
|
DEBUG_SEED("get_rdrand_seed");
|
||||||
int _eax;
|
int _eax;
|
||||||
retry:
|
retry:
|
||||||
// rdrand eax
|
/* rdrand eax */
|
||||||
__asm _emit 0x0F __asm _emit 0xC7 __asm _emit 0xF0
|
__asm _emit 0x0F __asm _emit 0xC7 __asm _emit 0xF0
|
||||||
__asm jnc retry
|
__asm jnc retry
|
||||||
__asm mov _eax, eax
|
__asm mov _eax, eax
|
||||||
return _eax;
|
return _eax;
|
||||||
}
|
}
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* defined ENABLE_RDRAND */
|
#endif /* defined ENABLE_RDRAND */
|
||||||
|
|
||||||
|
|
||||||
/* has_dev_urandom */
|
/* has_dev_urandom */
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__unix__) || defined(__linux__)
|
#if defined(__APPLE__) || defined(__unix__) || defined(__linux__)
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#if HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#endif /* HAVE_UNISTD_H */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@@ -135,67 +171,77 @@ retry:
|
|||||||
|
|
||||||
static const char *dev_random_file = "/dev/urandom";
|
static const char *dev_random_file = "/dev/urandom";
|
||||||
|
|
||||||
static int has_dev_urandom()
|
static int has_dev_urandom(void)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(dev_random_file, &buf)) {
|
if (stat(dev_random_file, &buf))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ((buf.st_mode & S_IFCHR) != 0);
|
return ((buf.st_mode & S_IFCHR) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* get_dev_random_seed */
|
/* get_dev_random_seed */
|
||||||
|
|
||||||
static int get_dev_random_seed()
|
static int get_dev_random_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_dev_random_seed");
|
DEBUG_SEED("get_dev_random_seed");
|
||||||
|
|
||||||
int fd = open(dev_random_file, O_RDONLY);
|
int fd = open(dev_random_file, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
|
{
|
||||||
fprintf(stderr, "error opening %s: %s", dev_random_file, strerror(errno));
|
fprintf(stderr, "error opening %s: %s", dev_random_file, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
ssize_t nread = read(fd, &r, sizeof(r));
|
ssize_t nread = read(fd, &r, sizeof(r));
|
||||||
if (nread != sizeof(r)) {
|
if (nread != sizeof(r))
|
||||||
fprintf(stderr, "error read %s: %s", dev_random_file, strerror(errno));
|
{
|
||||||
exit(1);
|
fprintf(stderr, "error short read %s: %s", dev_random_file, strerror(errno));
|
||||||
}
|
|
||||||
else if (nread != sizeof(r)) {
|
|
||||||
fprintf(stderr, "error short read %s", dev_random_file);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* get_cryptgenrandom_seed */
|
/* get_cryptgenrandom_seed */
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
#define HAVE_CRYPTGENRANDOM 1
|
#define HAVE_CRYPTGENRANDOM 1
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
/* Caution: these blank lines must remain so clang-format doesn't reorder
|
||||||
|
includes to put windows.h after wincrypt.h */
|
||||||
|
|
||||||
|
#include <wincrypt.h>
|
||||||
|
/* clang-format on */
|
||||||
|
#ifndef __GNUC__
|
||||||
#pragma comment(lib, "advapi32.lib")
|
#pragma comment(lib, "advapi32.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
static int get_cryptgenrandom_seed()
|
static int get_cryptgenrandom_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_cryptgenrandom_seed");
|
|
||||||
|
|
||||||
HCRYPTPROV hProvider = 0;
|
HCRYPTPROV hProvider = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
DEBUG_SEED("get_cryptgenrandom_seed");
|
||||||
|
|
||||||
|
if (!CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL,
|
||||||
|
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
||||||
|
{
|
||||||
fprintf(stderr, "error CryptAcquireContextW");
|
fprintf(stderr, "error CryptAcquireContextW");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CryptGenRandom(hProvider, sizeof(r), (BYTE*)&r)) {
|
if (!CryptGenRandom(hProvider, sizeof(r), (BYTE *)&r))
|
||||||
|
{
|
||||||
fprintf(stderr, "error CryptGenRandom");
|
fprintf(stderr, "error CryptGenRandom");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -207,30 +253,30 @@ static int get_cryptgenrandom_seed()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* get_time_seed */
|
/* get_time_seed */
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
static int get_time_seed()
|
static int get_time_seed(void)
|
||||||
{
|
{
|
||||||
DEBUG_SEED("get_time_seed");
|
DEBUG_SEED("get_time_seed");
|
||||||
|
|
||||||
return (int)time(NULL) * 433494437;
|
return (int)time(NULL) * 433494437;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* json_c_get_random_seed */
|
/* json_c_get_random_seed */
|
||||||
|
|
||||||
int json_c_get_random_seed()
|
int json_c_get_random_seed(void)
|
||||||
{
|
{
|
||||||
#if HAVE_RDRAND
|
#if defined HAVE_RDRAND && HAVE_RDRAND
|
||||||
if (has_rdrand()) return get_rdrand_seed();
|
if (has_rdrand())
|
||||||
|
return get_rdrand_seed();
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_DEV_RANDOM
|
#if defined HAVE_DEV_RANDOM && HAVE_DEV_RANDOM
|
||||||
if (has_dev_urandom()) return get_dev_random_seed();
|
if (has_dev_urandom())
|
||||||
|
return get_dev_random_seed();
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_CRYPTGENRANDOM
|
#if defined HAVE_CRYPTGENRANDOM && HAVE_CRYPTGENRANDOM
|
||||||
return get_cryptgenrandom_seed();
|
return get_cryptgenrandom_seed();
|
||||||
#endif
|
#endif
|
||||||
return get_time_seed();
|
return get_time_seed();
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
#ifndef seed_h
|
#ifndef seed_h
|
||||||
#define seed_h
|
#define seed_h
|
||||||
|
|
||||||
@@ -16,7 +20,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int json_c_get_random_seed();
|
extern int json_c_get_random_seed(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
41
snprintf_compat.h
Normal file
41
snprintf_compat.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef __snprintf_compat_h
|
||||||
|
#define __snprintf_compat_h
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Microsoft's _vsnprintf and _snprint don't always terminate
|
||||||
|
* the string, so use wrappers that ensure that.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if !defined(HAVE_SNPRINTF) && (defined(_MSC_VER) || defined(__MINGW32__))
|
||||||
|
static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = _vsnprintf(str, size, format, ap);
|
||||||
|
str[size - 1] = '\0';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#define vsnprintf json_c_vsnprintf
|
||||||
|
|
||||||
|
static int json_c_snprintf(char *str, size_t size, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int ret;
|
||||||
|
va_start(ap, format);
|
||||||
|
ret = json_c_vsnprintf(str, size, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#define snprintf json_c_snprintf
|
||||||
|
|
||||||
|
#elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */
|
||||||
|
#error Need vsnprintf!
|
||||||
|
#endif /* !HAVE_SNPRINTF && defined(WIN32) */
|
||||||
|
|
||||||
|
#endif /* __snprintf_compat_h */
|
||||||
16
strdup_compat.h
Normal file
16
strdup_compat.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef __strdup_compat_h
|
||||||
|
#define __strdup_compat_h
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRDUP) && defined(_MSC_VER)
|
||||||
|
/* MSC has the version as _strdup */
|
||||||
|
#define strdup _strdup
|
||||||
|
#elif !defined(HAVE_STRDUP)
|
||||||
|
#error You do not have strdup on your system.
|
||||||
|
#endif /* HAVE_STRDUP */
|
||||||
|
|
||||||
|
#endif
|
||||||
106
strerror_override.c
Normal file
106
strerror_override.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#define STRERROR_OVERRIDE_IMPL 1
|
||||||
|
#include "strerror_override.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Override strerror() to get consistent output across platforms.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
int errno_value;
|
||||||
|
const char *errno_str;
|
||||||
|
} errno_list[] = {
|
||||||
|
/* clang-format off */
|
||||||
|
#define STRINGIFY(x) #x
|
||||||
|
#define ENTRY(x) {x, &STRINGIFY(undef_ ## x)[6]}
|
||||||
|
ENTRY(EPERM),
|
||||||
|
ENTRY(ENOENT),
|
||||||
|
ENTRY(ESRCH),
|
||||||
|
ENTRY(EINTR),
|
||||||
|
ENTRY(EIO),
|
||||||
|
ENTRY(ENXIO),
|
||||||
|
ENTRY(E2BIG),
|
||||||
|
#ifdef ENOEXEC
|
||||||
|
ENTRY(ENOEXEC),
|
||||||
|
#endif
|
||||||
|
ENTRY(EBADF),
|
||||||
|
ENTRY(ECHILD),
|
||||||
|
ENTRY(EDEADLK),
|
||||||
|
ENTRY(ENOMEM),
|
||||||
|
ENTRY(EACCES),
|
||||||
|
ENTRY(EFAULT),
|
||||||
|
#ifdef ENOTBLK
|
||||||
|
ENTRY(ENOTBLK),
|
||||||
|
#endif
|
||||||
|
ENTRY(EBUSY),
|
||||||
|
ENTRY(EEXIST),
|
||||||
|
ENTRY(EXDEV),
|
||||||
|
ENTRY(ENODEV),
|
||||||
|
ENTRY(ENOTDIR),
|
||||||
|
ENTRY(EISDIR),
|
||||||
|
ENTRY(EINVAL),
|
||||||
|
ENTRY(ENFILE),
|
||||||
|
ENTRY(EMFILE),
|
||||||
|
ENTRY(ENOTTY),
|
||||||
|
#ifdef ETXTBSY
|
||||||
|
ENTRY(ETXTBSY),
|
||||||
|
#endif
|
||||||
|
ENTRY(EFBIG),
|
||||||
|
ENTRY(ENOSPC),
|
||||||
|
ENTRY(ESPIPE),
|
||||||
|
ENTRY(EROFS),
|
||||||
|
ENTRY(EMLINK),
|
||||||
|
ENTRY(EPIPE),
|
||||||
|
ENTRY(EDOM),
|
||||||
|
ENTRY(ERANGE),
|
||||||
|
ENTRY(EAGAIN),
|
||||||
|
{ 0, (char *)0 }
|
||||||
|
};
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
// Enabled during tests
|
||||||
|
int _json_c_strerror_enable = 0;
|
||||||
|
|
||||||
|
#define PREFIX "ERRNO="
|
||||||
|
static char errno_buf[128] = PREFIX;
|
||||||
|
char *_json_c_strerror(int errno_in)
|
||||||
|
{
|
||||||
|
int start_idx;
|
||||||
|
char digbuf[20];
|
||||||
|
int ii, jj;
|
||||||
|
|
||||||
|
if (!_json_c_strerror_enable)
|
||||||
|
return strerror(errno_in);
|
||||||
|
|
||||||
|
// Avoid standard functions, so we don't need to include any
|
||||||
|
// headers, or guess at signatures.
|
||||||
|
|
||||||
|
for (ii = 0; errno_list[ii].errno_str != (char *)0; ii++)
|
||||||
|
{
|
||||||
|
const char *errno_str = errno_list[ii].errno_str;
|
||||||
|
if (errno_list[ii].errno_value != errno_in)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (start_idx = sizeof(PREFIX) - 1, jj = 0; errno_str[jj] != '\0';
|
||||||
|
jj++, start_idx++)
|
||||||
|
{
|
||||||
|
errno_buf[start_idx] = errno_str[jj];
|
||||||
|
}
|
||||||
|
errno_buf[start_idx] = '\0';
|
||||||
|
return errno_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
// It's not one of the known errno values, return the numeric value.
|
||||||
|
for (ii = 0; errno_in > 10; errno_in /= 10, ii++)
|
||||||
|
{
|
||||||
|
digbuf[ii] = "0123456789"[(errno_in % 10)];
|
||||||
|
}
|
||||||
|
digbuf[ii] = "0123456789"[(errno_in % 10)];
|
||||||
|
|
||||||
|
// Reverse the digits
|
||||||
|
for (start_idx = sizeof(PREFIX) - 1; ii >= 0; ii--, start_idx++)
|
||||||
|
{
|
||||||
|
errno_buf[start_idx] = digbuf[ii];
|
||||||
|
}
|
||||||
|
return errno_buf;
|
||||||
|
}
|
||||||
30
strerror_override.h
Normal file
30
strerror_override.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef _json_strerror_override_h_
|
||||||
|
#define _json_strerror_override_h_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "json_object.h" /* for JSON_EXPORT */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
JSON_EXPORT char *_json_c_strerror(int errno_in);
|
||||||
|
|
||||||
|
#ifndef STRERROR_OVERRIDE_IMPL
|
||||||
|
#define strerror _json_c_strerror
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _json_strerror_override_h_ */
|
||||||
14
strerror_override_private.h
Normal file
14
strerror_override_private.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef __json_strerror_override_private_h__
|
||||||
|
#define __json_strerror_override_private_h__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "json_types.h"
|
||||||
|
|
||||||
|
/* Used by tests to get consistent output */
|
||||||
|
JSON_EXPORT int _json_c_strerror_enable;
|
||||||
|
|
||||||
|
#endif
|
||||||
54
tests/CMakeLists.txt
Normal file
54
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
add_executable(test1Formatted test1.c parse_flags.c parse_flags.h)
|
||||||
|
target_compile_definitions(test1Formatted PRIVATE TEST_FORMATTED=1)
|
||||||
|
target_link_libraries(test1Formatted PRIVATE ${PROJECT_NAME})
|
||||||
|
|
||||||
|
add_executable(test2Formatted test2.c parse_flags.c parse_flags.h)
|
||||||
|
target_compile_definitions(test2Formatted PRIVATE TEST_FORMATTED=1)
|
||||||
|
target_link_libraries(test2Formatted PRIVATE ${PROJECT_NAME})
|
||||||
|
|
||||||
|
# https://cmake.org/cmake/help/v3.0/command/add_test.html
|
||||||
|
# https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
|
||||||
|
|
||||||
|
include_directories(PUBLIC ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
foreach(TESTNAME
|
||||||
|
test1
|
||||||
|
test2
|
||||||
|
test4
|
||||||
|
testReplaceExisting
|
||||||
|
test_cast
|
||||||
|
test_charcase
|
||||||
|
test_compare
|
||||||
|
test_deep_copy
|
||||||
|
test_double_serializer
|
||||||
|
test_float
|
||||||
|
test_int_add
|
||||||
|
test_json_pointer
|
||||||
|
test_locale
|
||||||
|
test_null
|
||||||
|
test_parse
|
||||||
|
test_parse_int64
|
||||||
|
test_printbuf
|
||||||
|
test_set_serializer
|
||||||
|
test_set_value
|
||||||
|
test_util_file
|
||||||
|
test_visit
|
||||||
|
test_object_iterator)
|
||||||
|
|
||||||
|
add_executable(${TESTNAME} ${TESTNAME}.c)
|
||||||
|
add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test)
|
||||||
|
|
||||||
|
# XXX using the non-target_ versions of these doesn't work :(
|
||||||
|
target_include_directories(
|
||||||
|
${TESTNAME}
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
target_link_libraries(
|
||||||
|
${TESTNAME}
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
endforeach(TESTNAME)
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
|
|
||||||
include ../Makefile.am.inc
|
|
||||||
LDADD= $(LIBJSON_LA)
|
|
||||||
|
|
||||||
LIBJSON_LA=$(top_builddir)/libjson-c.la
|
|
||||||
|
|
||||||
TESTS=
|
|
||||||
TESTS+= test1.test
|
|
||||||
TESTS+= test2.test
|
|
||||||
TESTS+= test4.test
|
|
||||||
TESTS+= testReplaceExisting.test
|
|
||||||
TESTS+= test_parse_int64.test
|
|
||||||
TESTS+= test_null.test
|
|
||||||
TESTS+= test_cast.test
|
|
||||||
TESTS+= test_parse.test
|
|
||||||
TESTS+= test_locale.test
|
|
||||||
TESTS+= test_charcase.test
|
|
||||||
TESTS+= test_printbuf.test
|
|
||||||
TESTS+= test_set_serializer.test
|
|
||||||
|
|
||||||
check_PROGRAMS=
|
|
||||||
check_PROGRAMS += $(TESTS:.test=)
|
|
||||||
|
|
||||||
# Note: handled by test1.test
|
|
||||||
check_PROGRAMS += test1Formatted
|
|
||||||
test1Formatted_SOURCES = test1.c parse_flags.c
|
|
||||||
test1Formatted_CPPFLAGS = -DTEST_FORMATTED
|
|
||||||
|
|
||||||
# Note: handled by test2.test
|
|
||||||
check_PROGRAMS += test2Formatted
|
|
||||||
test2Formatted_SOURCES = test2.c parse_flags.c
|
|
||||||
test2Formatted_CPPFLAGS = -DTEST_FORMATTED
|
|
||||||
|
|
||||||
EXTRA_DIST=
|
|
||||||
EXTRA_DIST += $(TESTS)
|
|
||||||
|
|
||||||
testsubdir=testSubDir
|
|
||||||
TESTS_ENVIRONMENT = top_builddir=$(top_builddir)
|
|
||||||
|
|
||||||
distclean-local:
|
|
||||||
-rm -rf $(testsubdir)
|
|
||||||
@@ -12,17 +12,19 @@
|
|||||||
#error You do not have strcasecmp on your system.
|
#error You do not have strcasecmp on your system.
|
||||||
#endif /* HAVE_STRNCASECMP */
|
#endif /* HAVE_STRNCASECMP */
|
||||||
|
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
const char *arg;
|
const char *arg;
|
||||||
int flag;
|
int flag;
|
||||||
} format_args[] = {
|
} format_args[] = {
|
||||||
{"plain", JSON_C_TO_STRING_PLAIN},
|
{"plain", JSON_C_TO_STRING_PLAIN},
|
||||||
{"spaced", JSON_C_TO_STRING_SPACED},
|
{"spaced", JSON_C_TO_STRING_SPACED},
|
||||||
{"pretty", JSON_C_TO_STRING_PRETTY},
|
{"pretty", JSON_C_TO_STRING_PRETTY},
|
||||||
|
{"pretty_tab", JSON_C_TO_STRING_PRETTY_TAB},
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NELEM
|
#ifndef NELEM
|
||||||
#define NELEM(x) (sizeof(x) / sizeof(&x[0]))
|
#define NELEM(x) (sizeof(x) / sizeof(x[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int parse_flags(int argc, char **argv)
|
int parse_flags(int argc, char **argv)
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ ! -z "$JSONC_TEST_TRACE" ] ; then
|
||||||
|
VERBOSE=1
|
||||||
|
set -x
|
||||||
|
set -v
|
||||||
|
fi
|
||||||
# Make sure srcdir is an absolute path. Supply the variable
|
# Make sure srcdir is an absolute path. Supply the variable
|
||||||
# if it does not exist. We want to be able to run the tests
|
# if it does not exist. We want to be able to run the tests
|
||||||
# stand-alone!!
|
# stand-alone!!
|
||||||
@@ -50,6 +55,14 @@ echo "=== Running test $progname"
|
|||||||
CMP="${CMP-cmp}"
|
CMP="${CMP-cmp}"
|
||||||
|
|
||||||
use_valgrind=${USE_VALGRIND-1}
|
use_valgrind=${USE_VALGRIND-1}
|
||||||
|
case "${use_valgrind}" in
|
||||||
|
[0Nn]*)
|
||||||
|
use_valgrind=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
use_valgrind=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
valgrind_path=$(which valgrind 2> /dev/null)
|
valgrind_path=$(which valgrind 2> /dev/null)
|
||||||
if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
|
if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
|
||||||
use_valgrind=0
|
use_valgrind=0
|
||||||
@@ -114,15 +127,13 @@ run_output_test()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! "$CMP" -s "${top_builddir}/${TEST_OUTPUT}.expected" "${TEST_OUTPUT}.out" ; then
|
if ! "$CMP" -s "${srcdir}/${TEST_OUTPUT}.expected" "${TEST_OUTPUT}.out" ; then
|
||||||
echo "ERROR: \"${TEST_COMMAND} $@\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
|
echo "ERROR: \"${TEST_COMMAND} $@\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
|
||||||
(cd "${CURDIR}" ; set -x ; diff "${top_builddir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
|
(cd "${CURDIR}" ; set -x ; diff "${srcdir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
|
||||||
echo "cp \"$testsubdir/${TEST_OUTPUT}.out\" \"${top_builddir}/${TEST_OUTPUT}.expected\"" 1>&2
|
echo "cp \"$testsubdir/${TEST_OUTPUT}.out\" \"${srcdir}/${TEST_OUTPUT}.expected\"" 1>&2
|
||||||
|
|
||||||
err=1
|
err=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $err
|
return $err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
201
tests/test1.c
201
tests/test1.c
@@ -1,8 +1,8 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
#include "parse_flags.h"
|
#include "parse_flags.h"
|
||||||
@@ -28,15 +28,165 @@ static int sort_fn (const void *j1, const void *j2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
#define json_object_to_json_string(obj) json_object_to_json_string_ext(obj,sflags)
|
static const char *to_json_string(json_object *obj, int flags)
|
||||||
|
{
|
||||||
|
size_t length;
|
||||||
|
char *copy;
|
||||||
|
const char *result;
|
||||||
|
|
||||||
|
result = json_object_to_json_string_length(obj, flags, &length);
|
||||||
|
copy = strdup(result);
|
||||||
|
if (copy == NULL)
|
||||||
|
printf("to_json_string: Allocation failed!\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = json_object_to_json_string_ext(obj, flags);
|
||||||
|
if (length != strlen(result))
|
||||||
|
printf("to_json_string: Length mismatch!\n");
|
||||||
|
if (strcmp(copy, result) != 0)
|
||||||
|
printf("to_json_string: Comparison Failed!\n");
|
||||||
|
free(copy);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#define json_object_to_json_string(obj) to_json_string(obj, sflags)
|
||||||
#else
|
#else
|
||||||
/* no special define */
|
/* no special define */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
json_object *make_array(void);
|
||||||
|
json_object *make_array()
|
||||||
|
{
|
||||||
|
json_object *my_array;
|
||||||
|
|
||||||
|
my_array = json_object_new_array();
|
||||||
|
json_object_array_add(my_array, json_object_new_int(1));
|
||||||
|
json_object_array_add(my_array, json_object_new_int(2));
|
||||||
|
json_object_array_add(my_array, json_object_new_int(3));
|
||||||
|
json_object_array_put_idx(my_array, 4, json_object_new_int(5));
|
||||||
|
json_object_array_put_idx(my_array, 3, json_object_new_int(4));
|
||||||
|
json_object_array_put_idx(my_array, 6, json_object_new_int(7));
|
||||||
|
|
||||||
|
return my_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_array_del_idx(void);
|
||||||
|
void test_array_del_idx()
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
size_t ii;
|
||||||
|
size_t orig_array_len;
|
||||||
|
json_object *my_array;
|
||||||
|
#ifdef TEST_FORMATTED
|
||||||
|
int sflags = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
my_array = make_array();
|
||||||
|
orig_array_len = json_object_array_length(my_array);
|
||||||
|
|
||||||
|
printf("my_array=\n");
|
||||||
|
for (ii = 0; ii < json_object_array_length(my_array); ii++)
|
||||||
|
{
|
||||||
|
json_object *obj = json_object_array_get_idx(my_array, ii);
|
||||||
|
printf("\t[%d]=%s\n", (int)ii, json_object_to_json_string(obj));
|
||||||
|
}
|
||||||
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
for (ii = 0; ii < orig_array_len; ii++)
|
||||||
|
{
|
||||||
|
rc = json_object_array_del_idx(my_array, 0, 1);
|
||||||
|
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc,
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One more time, with the empty array: */
|
||||||
|
rc = json_object_array_del_idx(my_array, 0, 1);
|
||||||
|
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc,
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
json_object_put(my_array);
|
||||||
|
|
||||||
|
/* Delete all array indexes at once */
|
||||||
|
my_array = make_array();
|
||||||
|
rc = json_object_array_del_idx(my_array, 0, orig_array_len);
|
||||||
|
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)orig_array_len, rc,
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
json_object_put(my_array);
|
||||||
|
|
||||||
|
/* Delete *more* than all array indexes at once */
|
||||||
|
my_array = make_array();
|
||||||
|
rc = json_object_array_del_idx(my_array, 0, orig_array_len + 1);
|
||||||
|
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len + 1), rc,
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
json_object_put(my_array);
|
||||||
|
|
||||||
|
/* Delete some array indexes, then add more */
|
||||||
|
my_array = make_array();
|
||||||
|
rc = json_object_array_del_idx(my_array, 0, orig_array_len - 1);
|
||||||
|
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len - 1), rc,
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
json_object_array_add(my_array, json_object_new_string("s1"));
|
||||||
|
json_object_array_add(my_array, json_object_new_string("s2"));
|
||||||
|
json_object_array_add(my_array, json_object_new_string("s3"));
|
||||||
|
|
||||||
|
printf("after adding more entries, my_array.to_string()=%s\n",
|
||||||
|
json_object_to_json_string(my_array));
|
||||||
|
json_object_put(my_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_array_list_expand_internal(void);
|
||||||
|
void test_array_list_expand_internal()
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
size_t ii;
|
||||||
|
size_t idx;
|
||||||
|
json_object *my_array;
|
||||||
|
#ifdef TEST_FORMATTED
|
||||||
|
int sflags = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
my_array = make_array();
|
||||||
|
printf("my_array=\n");
|
||||||
|
for (ii = 0; ii < json_object_array_length(my_array); ii++)
|
||||||
|
{
|
||||||
|
json_object *obj = json_object_array_get_idx(my_array, ii);
|
||||||
|
printf("\t[%d]=%s\n", (int)ii, json_object_to_json_string(obj));
|
||||||
|
}
|
||||||
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
/* Put iNdex < array->size, no expand. */
|
||||||
|
rc = json_object_array_put_idx(my_array, 5, json_object_new_int(6));
|
||||||
|
printf("put_idx(5,6)=%d\n", rc);
|
||||||
|
|
||||||
|
/* array->size < Put Index < array->size * 2 <= SIZE_T_MAX, the size = array->size * 2. */
|
||||||
|
idx = ARRAY_LIST_DEFAULT_SIZE * 2 - 1;
|
||||||
|
rc = json_object_array_put_idx(my_array, idx, json_object_new_int(0));
|
||||||
|
printf("put_idx(%d,0)=%d\n", (int)(idx), rc);
|
||||||
|
|
||||||
|
/* array->size * 2 < Put Index, the size = Put Index. */
|
||||||
|
idx = ARRAY_LIST_DEFAULT_SIZE * 2 * 2 + 1;
|
||||||
|
rc = json_object_array_put_idx(my_array, idx, json_object_new_int(0));
|
||||||
|
printf("put_idx(%d,0)=%d\n", (int)(idx), rc);
|
||||||
|
|
||||||
|
/* SIZE_T_MAX <= Put Index, it will fail and the size will no change. */
|
||||||
|
idx = SIZE_MAX; // SIZE_MAX = SIZE_T_MAX
|
||||||
|
json_object *tmp = json_object_new_int(10);
|
||||||
|
rc = json_object_array_put_idx(my_array, idx, tmp);
|
||||||
|
printf("put_idx(SIZE_T_MAX,0)=%d\n", rc);
|
||||||
|
if (rc == -1)
|
||||||
|
{
|
||||||
|
json_object_put(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_put(my_array);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
json_object *my_string, *my_int, *my_object, *my_array;
|
json_object *my_string, *my_int, *my_null, *my_object, *my_array;
|
||||||
int i;
|
size_t i;
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
int sflags = 0;
|
int sflags = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -57,6 +207,20 @@ int main(int argc, char **argv)
|
|||||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
json_object_put(my_string);
|
json_object_put(my_string);
|
||||||
|
|
||||||
|
my_string = json_object_new_string("/");
|
||||||
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
|
printf("my_string.to_string(NOSLASHESCAPE)=%s\n",
|
||||||
|
json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||||
|
json_object_put(my_string);
|
||||||
|
|
||||||
|
my_string = json_object_new_string("/foo/bar/baz");
|
||||||
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
|
printf("my_string.to_string(NOSLASHESCAPE)=%s\n",
|
||||||
|
json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||||
|
json_object_put(my_string);
|
||||||
|
|
||||||
my_string = json_object_new_string("foo");
|
my_string = json_object_new_string("foo");
|
||||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
@@ -65,6 +229,9 @@ int main(int argc, char **argv)
|
|||||||
printf("my_int=%d\n", json_object_get_int(my_int));
|
printf("my_int=%d\n", json_object_get_int(my_int));
|
||||||
printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));
|
printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));
|
||||||
|
|
||||||
|
my_null = json_object_new_null();
|
||||||
|
printf("my_null.to_string()=%s\n", json_object_to_json_string(my_null));
|
||||||
|
|
||||||
my_array = json_object_new_array();
|
my_array = json_object_new_array();
|
||||||
json_object_array_add(my_array, json_object_new_int(1));
|
json_object_array_add(my_array, json_object_new_int(1));
|
||||||
json_object_array_add(my_array, json_object_new_int(2));
|
json_object_array_add(my_array, json_object_new_int(2));
|
||||||
@@ -74,12 +241,15 @@ int main(int argc, char **argv)
|
|||||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||||
{
|
{
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||||
}
|
}
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
json_object_put(my_array);
|
json_object_put(my_array);
|
||||||
|
|
||||||
|
test_array_del_idx();
|
||||||
|
test_array_list_expand_internal();
|
||||||
|
|
||||||
my_array = json_object_new_array();
|
my_array = json_object_new_array();
|
||||||
json_object_array_add(my_array, json_object_new_int(3));
|
json_object_array_add(my_array, json_object_new_int(3));
|
||||||
json_object_array_add(my_array, json_object_new_int(1));
|
json_object_array_add(my_array, json_object_new_int(1));
|
||||||
@@ -89,7 +259,7 @@ int main(int argc, char **argv)
|
|||||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||||
{
|
{
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||||
}
|
}
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
json_object_array_sort(my_array, sort_fn);
|
json_object_array_sort(my_array, sort_fn);
|
||||||
@@ -97,11 +267,23 @@ int main(int argc, char **argv)
|
|||||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||||
{
|
{
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||||
}
|
}
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
|
json_object *one = json_object_new_int(1);
|
||||||
|
json_object *result = json_object_array_bsearch(one, my_array, sort_fn);
|
||||||
|
printf("find json_object(1) in my_array successfully: %s\n",
|
||||||
|
json_object_to_json_string(result));
|
||||||
|
json_object_put(one);
|
||||||
|
|
||||||
my_object = json_object_new_object();
|
my_object = json_object_new_object();
|
||||||
|
int rc = json_object_object_add(my_object, "abc", my_object);
|
||||||
|
if (rc != -1)
|
||||||
|
{
|
||||||
|
printf("ERROR: able to successfully add object to itself!\n");
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
json_object_object_add(my_object, "abc", json_object_new_int(12));
|
json_object_object_add(my_object, "abc", json_object_new_int(12));
|
||||||
json_object_object_add(my_object, "foo", json_object_new_string("bar"));
|
json_object_object_add(my_object, "foo", json_object_new_string("bar"));
|
||||||
json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
|
json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
|
||||||
@@ -127,8 +309,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
json_object_put(my_string);
|
json_object_put(my_string);
|
||||||
json_object_put(my_int);
|
json_object_put(my_int);
|
||||||
|
json_object_put(my_null);
|
||||||
json_object_put(my_object);
|
json_object_put(my_object);
|
||||||
json_object_put(my_array);
|
json_object_put(my_array);
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ my_string=
|
|||||||
my_string.to_string()="\t"
|
my_string.to_string()="\t"
|
||||||
my_string=\
|
my_string=\
|
||||||
my_string.to_string()="\\"
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
my_string=foo
|
my_string=foo
|
||||||
my_string.to_string()="foo"
|
my_string.to_string()="foo"
|
||||||
my_int=9
|
my_int=9
|
||||||
my_int.to_string()=9
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
my_array=
|
my_array=
|
||||||
[0]=1
|
[0]=1
|
||||||
[1]=2
|
[1]=2
|
||||||
@@ -13,6 +20,40 @@ my_array=
|
|||||||
[3]=null
|
[3]=null
|
||||||
[4]=5
|
[4]=5
|
||||||
my_array.to_string()=[ 1, 2, 3, null, 5 ]
|
my_array.to_string()=[ 1, 2, 3, null, 5 ]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ 2, 3, 4, 5, null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ 3, 4, 5, null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ 4, 5, null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ 5, null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ null, 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ 7 ]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[ ]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[ ]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[ ]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[ 7 ]
|
||||||
|
after adding more entries, my_array.to_string()=[ 7, "s1", "s2", "s3" ]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[ 1, 2, 3, 4, 5, null, 7 ]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
my_array=
|
my_array=
|
||||||
[0]=3
|
[0]=3
|
||||||
[1]=1
|
[1]=1
|
||||||
@@ -27,6 +68,7 @@ my_array=
|
|||||||
[3]=2
|
[3]=2
|
||||||
[4]=3
|
[4]=3
|
||||||
my_array.to_string()=[ null, 0, 1, 2, 3 ]
|
my_array.to_string()=[ null, 0, 1, 2, 3 ]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
baz_obj.to_string()="fark"
|
baz_obj.to_string()="fark"
|
||||||
my_object=
|
my_object=
|
||||||
abc: 12
|
abc: 12
|
||||||
|
|||||||
@@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Spaced and pretty JSON string
|
||||||
|
run_output_test -o test1Formatted_spaced_pretty \
|
||||||
|
test1Formatted spaced pretty
|
||||||
|
_err2=$?
|
||||||
|
if [ $_err -eq 0 ] ; then
|
||||||
|
_err=$_err2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Spaced and pretty JSON string using tabs
|
||||||
|
run_output_test -o test1Formatted_spaced_pretty_pretty_tab \
|
||||||
|
test1Formatted spaced pretty pretty_tab
|
||||||
|
_err2=$?
|
||||||
|
if [ $_err -eq 0 ] ; then
|
||||||
|
_err=$_err2
|
||||||
|
fi
|
||||||
|
|
||||||
exit $_err
|
exit $_err
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ my_string=
|
|||||||
my_string.to_string()="\t"
|
my_string.to_string()="\t"
|
||||||
my_string=\
|
my_string=\
|
||||||
my_string.to_string()="\\"
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
my_string=foo
|
my_string=foo
|
||||||
my_string.to_string()="foo"
|
my_string.to_string()="foo"
|
||||||
my_int=9
|
my_int=9
|
||||||
my_int.to_string()=9
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
my_array=
|
my_array=
|
||||||
[0]=1
|
[0]=1
|
||||||
[1]=2
|
[1]=2
|
||||||
@@ -13,6 +20,40 @@ my_array=
|
|||||||
[3]=null
|
[3]=null
|
||||||
[4]=5
|
[4]=5
|
||||||
my_array.to_string()=[1,2,3,null,5]
|
my_array.to_string()=[1,2,3,null,5]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[7]
|
||||||
|
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
my_array=
|
my_array=
|
||||||
[0]=3
|
[0]=3
|
||||||
[1]=1
|
[1]=1
|
||||||
@@ -27,6 +68,7 @@ my_array=
|
|||||||
[3]=2
|
[3]=2
|
||||||
[4]=3
|
[4]=3
|
||||||
my_array.to_string()=[null,0,1,2,3]
|
my_array.to_string()=[null,0,1,2,3]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
baz_obj.to_string()="fark"
|
baz_obj.to_string()="fark"
|
||||||
my_object=
|
my_object=
|
||||||
abc: 12
|
abc: 12
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ my_string=
|
|||||||
my_string.to_string()="\t"
|
my_string.to_string()="\t"
|
||||||
my_string=\
|
my_string=\
|
||||||
my_string.to_string()="\\"
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
my_string=foo
|
my_string=foo
|
||||||
my_string.to_string()="foo"
|
my_string.to_string()="foo"
|
||||||
my_int=9
|
my_int=9
|
||||||
my_int.to_string()=9
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
my_array=
|
my_array=
|
||||||
[0]=1
|
[0]=1
|
||||||
[1]=2
|
[1]=2
|
||||||
@@ -19,6 +26,40 @@ my_array.to_string()=[
|
|||||||
null,
|
null,
|
||||||
5
|
5
|
||||||
]
|
]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[7]
|
||||||
|
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
my_array=
|
my_array=
|
||||||
[0]=3
|
[0]=3
|
||||||
[1]=1
|
[1]=1
|
||||||
@@ -45,6 +86,7 @@ my_array.to_string()=[
|
|||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
]
|
]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
baz_obj.to_string()="fark"
|
baz_obj.to_string()="fark"
|
||||||
my_object=
|
my_object=
|
||||||
abc: 12
|
abc: 12
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ my_string=
|
|||||||
my_string.to_string()="\t"
|
my_string.to_string()="\t"
|
||||||
my_string=\
|
my_string=\
|
||||||
my_string.to_string()="\\"
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
my_string=foo
|
my_string=foo
|
||||||
my_string.to_string()="foo"
|
my_string.to_string()="foo"
|
||||||
my_int=9
|
my_int=9
|
||||||
my_int.to_string()=9
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
my_array=
|
my_array=
|
||||||
[0]=1
|
[0]=1
|
||||||
[1]=2
|
[1]=2
|
||||||
@@ -13,6 +20,40 @@ my_array=
|
|||||||
[3]=null
|
[3]=null
|
||||||
[4]=5
|
[4]=5
|
||||||
my_array.to_string()=[ 1, 2, 3, null, 5 ]
|
my_array.to_string()=[ 1, 2, 3, null, 5 ]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[7]
|
||||||
|
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
my_array=
|
my_array=
|
||||||
[0]=3
|
[0]=3
|
||||||
[1]=1
|
[1]=1
|
||||||
@@ -27,6 +68,7 @@ my_array=
|
|||||||
[3]=2
|
[3]=2
|
||||||
[4]=3
|
[4]=3
|
||||||
my_array.to_string()=[ null, 0, 1, 2, 3 ]
|
my_array.to_string()=[ null, 0, 1, 2, 3 ]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
baz_obj.to_string()="fark"
|
baz_obj.to_string()="fark"
|
||||||
my_object=
|
my_object=
|
||||||
abc: 12
|
abc: 12
|
||||||
|
|||||||
101
tests/test1Formatted_spaced_pretty.expected
Normal file
101
tests/test1Formatted_spaced_pretty.expected
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
my_string=
|
||||||
|
my_string.to_string()="\t"
|
||||||
|
my_string=\
|
||||||
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
|
my_string=foo
|
||||||
|
my_string.to_string()="foo"
|
||||||
|
my_int=9
|
||||||
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=null
|
||||||
|
[4]=5
|
||||||
|
my_array.to_string()=[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
null,
|
||||||
|
5
|
||||||
|
]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[7]
|
||||||
|
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
|
my_array=
|
||||||
|
[0]=3
|
||||||
|
[1]=1
|
||||||
|
[2]=2
|
||||||
|
[3]=null
|
||||||
|
[4]=0
|
||||||
|
my_array.to_string()=[
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
my_array=
|
||||||
|
[0]=null
|
||||||
|
[1]=0
|
||||||
|
[2]=1
|
||||||
|
[3]=2
|
||||||
|
[4]=3
|
||||||
|
my_array.to_string()=[
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
|
baz_obj.to_string()="fark"
|
||||||
|
my_object=
|
||||||
|
abc: 12
|
||||||
|
foo: "bar"
|
||||||
|
bool0: false
|
||||||
|
bool1: true
|
||||||
|
my_object.to_string()={
|
||||||
|
"abc": 12,
|
||||||
|
"foo": "bar",
|
||||||
|
"bool0": false,
|
||||||
|
"bool1": true
|
||||||
|
}
|
||||||
101
tests/test1Formatted_spaced_pretty_pretty_tab.expected
Normal file
101
tests/test1Formatted_spaced_pretty_pretty_tab.expected
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
my_string=
|
||||||
|
my_string.to_string()="\t"
|
||||||
|
my_string=\
|
||||||
|
my_string.to_string()="\\"
|
||||||
|
my_string=/
|
||||||
|
my_string.to_string()="\/"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/"
|
||||||
|
my_string=/foo/bar/baz
|
||||||
|
my_string.to_string()="\/foo\/bar\/baz"
|
||||||
|
my_string.to_string(NOSLASHESCAPE)="/foo/bar/baz"
|
||||||
|
my_string=foo
|
||||||
|
my_string.to_string()="foo"
|
||||||
|
my_int=9
|
||||||
|
my_int.to_string()=9
|
||||||
|
my_null.to_string()=null
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=null
|
||||||
|
[4]=5
|
||||||
|
my_array.to_string()=[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
null,
|
||||||
|
5
|
||||||
|
]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[2,3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[3,4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[4,5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[5,null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[null,7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[7]
|
||||||
|
after del_idx(0,1)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,1)=-1, my_array.to_string()=[]
|
||||||
|
after del_idx(0,7)=0, my_array.to_string()=[]
|
||||||
|
after del_idx(0,8)=-1, my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
after del_idx(0,6)=0, my_array.to_string()=[7]
|
||||||
|
after adding more entries, my_array.to_string()=[7,"s1","s2","s3"]
|
||||||
|
my_array=
|
||||||
|
[0]=1
|
||||||
|
[1]=2
|
||||||
|
[2]=3
|
||||||
|
[3]=4
|
||||||
|
[4]=5
|
||||||
|
[5]=null
|
||||||
|
[6]=7
|
||||||
|
my_array.to_string()=[1,2,3,4,5,null,7]
|
||||||
|
put_idx(5,6)=0
|
||||||
|
put_idx(63,0)=0
|
||||||
|
put_idx(129,0)=0
|
||||||
|
put_idx(SIZE_T_MAX,0)=-1
|
||||||
|
my_array=
|
||||||
|
[0]=3
|
||||||
|
[1]=1
|
||||||
|
[2]=2
|
||||||
|
[3]=null
|
||||||
|
[4]=0
|
||||||
|
my_array.to_string()=[
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
my_array=
|
||||||
|
[0]=null
|
||||||
|
[1]=0
|
||||||
|
[2]=1
|
||||||
|
[3]=2
|
||||||
|
[4]=3
|
||||||
|
my_array.to_string()=[
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
find json_object(1) in my_array successfully: 1
|
||||||
|
baz_obj.to_string()="fark"
|
||||||
|
my_object=
|
||||||
|
abc: 12
|
||||||
|
foo: "bar"
|
||||||
|
bool0: false
|
||||||
|
bool1: true
|
||||||
|
my_object.to_string()={
|
||||||
|
"abc": 12,
|
||||||
|
"foo": "bar",
|
||||||
|
"bool0": false,
|
||||||
|
"bool1": true
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
/* no special define */
|
/* no special define */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
json_object *new_obj;
|
json_object *new_obj;
|
||||||
@@ -26,9 +25,15 @@ int main(int argc, char **argv)
|
|||||||
sflags = parse_flags(argc, argv);
|
sflags = parse_flags(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
new_obj = json_tokener_parse("/* more difficult test case */ { \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
|
new_obj = json_tokener_parse(
|
||||||
|
"/* more difficult test case */"
|
||||||
|
"{ \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", "
|
||||||
|
"\"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard "
|
||||||
|
"Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", "
|
||||||
|
"\"GlossDef\": \"A meta-markup language, used to create markup languages such as "
|
||||||
|
"DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,20 @@ for flag in plain spaced pretty ; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Spaced and pretty JSON string
|
||||||
|
run_output_test -o test2Formatted_spaced_pretty \
|
||||||
|
test2Formatted spaced pretty
|
||||||
|
_err2=$?
|
||||||
|
if [ $_err -eq 0 ] ; then
|
||||||
|
_err=$_err2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Spaced and pretty JSON string using tabs
|
||||||
|
run_output_test -o test2Formatted_spaced_pretty_pretty_tab \
|
||||||
|
test2Formatted spaced pretty pretty_tab
|
||||||
|
_err2=$?
|
||||||
|
if [ $_err -eq 0 ] ; then
|
||||||
|
_err=$_err2
|
||||||
|
fi
|
||||||
|
|
||||||
exit $_err
|
exit $_err
|
||||||
|
|||||||
23
tests/test2Formatted_spaced_pretty.expected
Normal file
23
tests/test2Formatted_spaced_pretty.expected
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
new_obj.to_string()={
|
||||||
|
"glossary": {
|
||||||
|
"title": "example glossary",
|
||||||
|
"GlossDiv": {
|
||||||
|
"title": "S",
|
||||||
|
"GlossList": [
|
||||||
|
{
|
||||||
|
"ID": "SGML",
|
||||||
|
"SortAs": "SGML",
|
||||||
|
"GlossTerm": "Standard Generalized Markup Language",
|
||||||
|
"Acronym": "SGML",
|
||||||
|
"Abbrev": "ISO 8879:1986",
|
||||||
|
"GlossDef": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||||
|
"GlossSeeAlso": [
|
||||||
|
"GML",
|
||||||
|
"XML",
|
||||||
|
"markup"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
tests/test2Formatted_spaced_pretty_pretty_tab.expected
Normal file
23
tests/test2Formatted_spaced_pretty_pretty_tab.expected
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
new_obj.to_string()={
|
||||||
|
"glossary": {
|
||||||
|
"title": "example glossary",
|
||||||
|
"GlossDiv": {
|
||||||
|
"title": "S",
|
||||||
|
"GlossList": [
|
||||||
|
{
|
||||||
|
"ID": "SGML",
|
||||||
|
"SortAs": "SGML",
|
||||||
|
"GlossTerm": "Standard Generalized Markup Language",
|
||||||
|
"Acronym": "SGML",
|
||||||
|
"Abbrev": "ISO 8879:1986",
|
||||||
|
"GlossDef": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||||
|
"GlossSeeAlso": [
|
||||||
|
"GML",
|
||||||
|
"XML",
|
||||||
|
"markup"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,16 @@
|
|||||||
* gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
|
* gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "json_inttypes.h"
|
#include "json_inttypes.h"
|
||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
#include "json_tokener.h"
|
#include "json_tokener.h"
|
||||||
|
#include "snprintf_compat.h"
|
||||||
|
|
||||||
void print_hex(const char *s)
|
void print_hex(const char *s)
|
||||||
{
|
{
|
||||||
@@ -21,14 +24,38 @@ void print_hex( const char* s)
|
|||||||
else
|
else
|
||||||
printf(",");
|
printf(",");
|
||||||
}
|
}
|
||||||
printf("\n");
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
static void test_lot_of_adds(void);
|
||||||
|
static void test_lot_of_adds()
|
||||||
|
{
|
||||||
|
int ii;
|
||||||
|
char key[50];
|
||||||
|
json_object *jobj = json_object_new_object();
|
||||||
|
assert(jobj != NULL);
|
||||||
|
for (ii = 0; ii < 500; ii++)
|
||||||
|
{
|
||||||
|
snprintf(key, sizeof(key), "k%d", ii);
|
||||||
|
json_object *iobj = json_object_new_int(ii);
|
||||||
|
assert(iobj != NULL);
|
||||||
|
if (json_object_object_add(jobj, key, iobj))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "FAILED to add object #%d\n", ii);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%s\n", json_object_to_json_string(jobj));
|
||||||
|
assert(json_object_object_length(jobj) == 500);
|
||||||
|
json_object_put(jobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
{
|
{
|
||||||
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
|
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
|
||||||
const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
|
const char *expected =
|
||||||
struct json_object *parse_result = json_tokener_parse((char*)input);
|
"\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
|
||||||
|
struct json_object *parse_result = json_tokener_parse(input);
|
||||||
const char *unjson = json_object_get_string(parse_result);
|
const char *unjson = json_object_get_string(parse_result);
|
||||||
|
|
||||||
printf("input: %s\n", input);
|
printf("input: %s\n", input);
|
||||||
@@ -38,16 +65,21 @@ int main()
|
|||||||
if (strings_match)
|
if (strings_match)
|
||||||
{
|
{
|
||||||
printf("JSON parse result is correct: %s\n", unjson);
|
printf("JSON parse result is correct: %s\n", unjson);
|
||||||
printf("PASS\n");
|
puts("PASS");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf("JSON parse result doesn't match expected string\n");
|
printf("JSON parse result doesn't match expected string\n");
|
||||||
printf("expected string bytes: ");
|
printf("expected string bytes: ");
|
||||||
print_hex(expected);
|
print_hex(expected);
|
||||||
printf("parsed string bytes: ");
|
printf("parsed string bytes: ");
|
||||||
print_hex(unjson);
|
print_hex(unjson);
|
||||||
printf("FAIL\n");
|
puts("FAIL");
|
||||||
retval = 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
json_object_put(parse_result);
|
json_object_put(parse_result);
|
||||||
|
|
||||||
|
test_lot_of_adds();
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user